title: ESB Fuse module waiting on dependency - Grace Period
body: <p>I have a basic ESB Fuse test project set up with the following modules:</p>
  
  <p>simple-datasource
  simple-model
  simple-service</p>
  
  <p>The datasource is configured through blueprint and the datasource attached to jndi:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  </code></pre>
  
  <p>http://www.osgi.org/xmlns/blueprint/v1.0.0 <a href="http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd" rel="nofollow">http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd</a>"></p>
  
  <pre><code>&lt;bean id="simpleDataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&gt;
      &lt;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)))" /&gt;
      &lt;property name="username" value="username" /&gt;
      &lt;property name="password" value="password" /&gt;       
  &lt;/bean&gt;
  
  &lt;!--bean id="simpleDataSource" class="oracle.jdbc.driver.OracleDriver"&gt;     
      &lt;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)))"/&gt;
      &lt;property name="username" value="username" /&gt;
      &lt;property name="password" value="password" /&gt;       
  &lt;/bean--&gt;
  
  &lt;service ref="simpleDataSource" interface="javax.sql.DataSource"&gt;
      &lt;service-properties&gt;
          &lt;entry key="osgi.jndi.service.name" value="jdbc/simpleDataSource" /&gt;
      &lt;/service-properties&gt;
  &lt;/service&gt;
  </code></pre>
  
  <p></p>
  
  <p>The model defines a persistent unit inside persistence.xml file and references the datasource through jndi (notice the long and short jndi lookup defined here, both which I have tried):</p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
  version="2.0"&gt;
  
  &lt;persistence-unit name="simple-service-persistence-unit" transaction-type="JTA"&gt;
      &lt;provider&gt;org.apache.openjpa.persistence.PersistenceProviderImpl&lt;/provider&gt;
      &lt;!--jta-data-source&gt;osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/simpleDataSource)&lt;/jta-data-source--&gt;
      &lt;jta-data-source&gt;osgi.jndi.service.name=jdbc/simpleDataSource&lt;/jta-data-source&gt;
      &lt;!-- list of the persistance classes --&gt;
      &lt;class&gt;com.model.SimpleRow&lt;/class&gt;
      &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>The SimpleRow class uses JPA annotations:</p>
  
  <pre><code>package com.model;
  </code></pre>
  
  <p>import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Table;</p>
  
  <p>@Entity
  @Table(name = "SIMPLE")
  public class SimpleRow {</p>
  
  <pre><code>@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;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I then attempt to inject the EntityManager into a service, again using blueprint and a reference to the simple-service-persistence-unit:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  </code></pre>
  
  <p>http://www.osgi.org/xmlns/blueprint/v1.0.0 <a href="http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd" rel="nofollow">http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd</a>
         <a href="http://aries.apache.org/xmlns/jpa/v1.1.0" rel="nofollow">http://aries.apache.org/xmlns/jpa/v1.1.0</a> <a href="http://aries.apache.org/schemas/jpa/jpa_110.xsd" rel="nofollow">http://aries.apache.org/schemas/jpa/jpa_110.xsd</a>"></p>
  
  <pre><code>&lt;bean id="simpleService" class="com.service.SimpleServiceImpl"&gt;
      &lt;jpa:context property="entityManager" unitname="simple-service-persistence-unit" /&gt;
      &lt;tx:transaction method="*" value="Required" /&gt;
  &lt;/bean&gt;
  
  &lt;service ref="simpleService" interface="com.service.SimpleService" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Now when I install these modules into the fuse OSGi container the simple-datasource and simple-module both appear to install correctly. Listing these modules gives:</p>
  
  <pre><code>[ 274] [Active     ] [            ] [       ] [   60] Simple Model (1.0.0)
  [ 275] [Active     ] [Created     ] [       ] [   60] Simple Datasource (1.0.0)
  </code></pre>
  
  <p>I created a test jdbc module which used an injected DataSource and this confirmed that the DataSource is working correctly e.g.</p>
  
  <pre><code>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();
      ....
   }
  </code></pre>
  
  <p>Now, when I try and start the simple-service, it enters into a grace-period state and the following message is printed to the log file:</p>
  
  <pre><code>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 [(&amp;(&amp;(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=simple-service-persistence-unit))(objectClass=javax.persistence.EntityManagerFactory))]
  </code></pre>
  
  <p>Listing the module state shows it to be in the grace-period state:</p>
  
  <pre><code>[ 277] [Active     ] [GracePeriod ] [       ] [   60] Simple Service Bundle (1.0.0)
  </code></pre>
  
  <p>It eventually times out and moves into a failure state.</p>
  
  <p>Now my initial thinking was that it could be a broken datasource, but the jdbc module proves that it's working fine. My subsequent thoughts are that the jndi lookup isn't working correctly, although I'm not sure how to check this. Is there any way of viewing the jndi registry? Any other suggestions welcomed.</p>