ESB Fuse模块等待依赖 - 宽限期

时间:2013-07-02 10:29:56

标签: osgi datasource fuseesb

我有一个基本的ESB Fuse测试项目,其中包含以下模块:

简单的数据源 简单的模型 简单服务

数据源通过蓝图配置,数据源附加到jndi:

<?xml version="1.0" encoding="UTF-8"?>

http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd“&gt;

<bean id="simpleDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVICE_NAME=xyz))(ADDRESS=(PROTOCOL=TCP)(HOST=xx.xx.xx.xx)(PORT=1521)))" />
    <property name="username" value="username" />
    <property name="password" value="password" />       
</bean>

<!--bean id="simpleDataSource" class="oracle.jdbc.driver.OracleDriver">     
    <property name="URL" value="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVICE_NAME=devd))(ADDRESS=(PROTOCOL=TCP)(HOST=10.75.192.195)(PORT=1521)))"/>
    <property name="username" value="username" />
    <property name="password" value="password" />       
</bean-->

<service ref="simpleDataSource" interface="javax.sql.DataSource">
    <service-properties>
        <entry key="osgi.jndi.service.name" value="jdbc/simpleDataSource" />
    </service-properties>
</service>

模型在persistence.xml文件中定义了一个持久单元,并通过jndi引用了数据源(注意这里定义的长短jndi查找,这两个都是我尝试过的):

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="2.0">

<persistence-unit name="simple-service-persistence-unit" transaction-type="JTA">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <!--jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/simpleDataSource)</jta-data-source-->
    <jta-data-source>osgi.jndi.service.name=jdbc/simpleDataSource</jta-data-source>
    <!-- list of the persistance classes -->
    <class>com.model.SimpleRow</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>

SimpleRow类使用JPA注释:

package com.model;

import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table;

@Entity @Table(name =“SIMPLE”) 公共类SimpleRow {

@Column(name = "simple_id")
private Long simpleId;

@Column(name = "simple_text", length =100)
private String simpleText;

public Long getSimpleId() {
    return simpleId;
}

public void setSimpleId(Long simpleId) {
    this.simpleId = simpleId;
}

public String getSimpleText() {
    return simpleText;
}

public void setSimpleText(String simpleText) {
    this.simpleText = simpleText;
}

}

然后我尝试将EntityManager注入服务,再次使用蓝图和对simple-service-persistence-unit的引用:

<?xml version="1.0" encoding="UTF-8"?>

http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd        http://aries.apache.org/xmlns/jpa/v1.1.0 http://aries.apache.org/schemas/jpa/jpa_110.xsd“&gt;

<bean id="simpleService" class="com.service.SimpleServiceImpl">
    <jpa:context property="entityManager" unitname="simple-service-persistence-unit" />
    <tx:transaction method="*" value="Required" />
</bean>

<service ref="simpleService" interface="com.service.SimpleService" />

现在,当我将这些模块安装到保险丝OSGi容器中时,简单数据源和简单模块似乎都正确安装。列出这些模块给出了:

[ 274] [Active     ] [            ] [       ] [   60] Simple Model (1.0.0)
[ 275] [Active     ] [Created     ] [       ] [   60] Simple Datasource (1.0.0)

我创建了一个测试jdbc模块,该模块使用了一个注入的DataSource,这证实了DataSource工作正常,例如。

public class DbExample {
DataSource dataSource;

public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
}

public void test() throws Exception {
    Connection con = dataSource.getConnection();
    Statement stmt = null;
    DatabaseMetaData dbMeta = con.getMetaData();
    ....
 }

现在,当我尝试启动简单服务时,它进入宽限期状态,并将以下消息打印到日志文件中:

2013-07-02 11:05:33,772 | INFO  | e-1.0.0-thread-1 | BlueprintContainerImpl           | ?                                   ? | 8 - org.apache.aries.blueprint.core - 1.0.1.fuse-71-047 | Bundle simple-service is waiting for dependencies [(&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=simple-service-persistence-unit))(objectClass=javax.persistence.EntityManagerFactory))]

列出模块状态表明它处于宽限期状态:

[ 277] [Active     ] [GracePeriod ] [       ] [   60] Simple Service Bundle (1.0.0)

它最终会超时并进入失败状态。

现在我最初的想法是它可能是一个破坏的数据源,但jdbc模块证明它工作正常。我后来的想法是jndi查找工作不正常,虽然我不知道如何检查。有没有办法查看jndi注册表?欢迎任何其他建议。

1 个答案:

答案 0 :(得分:1)

您的软件包正在等待服务显示,这可能是一个问题,因为您引用了一个不可用的服务(打开DEBUG登录,您将在日志中看到详细信息)或者有时会发生(取决于Karaf / Aries的基础版本)您需要切换蓝图以使用同步部署,因为有时等待的捆绑包不会捕获以后启动的服务。为此,您需要翻转 etc / config.properties 文件中的 org.apache.aries.blueprint.synchronous = true