<style>
/* Changing the layout to use less space for mobiles */
@media screen and (max-device-width: 480px), screen and (-webkit-min-device-pixel-ratio: 2) {
    #email-body { min-width: 30em !important; }
    #email-page { padding: 8px !important; }
    #email-banner { padding: 8px 8px 0 8px !important; }
    #email-avatar { margin: 1px 8px 8px 0 !important; padding: 0 !important; }
    #email-fields { padding: 0 8px 8px 8px !important; }
    #email-gutter { width: 0 !important; }
}
</style>
<div id="email-body">
<table id="email-wrap" align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#f0f0f0;color:#000000;width:100%;">
    <tr valign="top">
        <td id="email-page" style="padding:16px !important;">
            <table align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#ffffff;border:1px solid #bbbbbb;color:#000000;width:100%;">
                <tr valign="top">
                    <td bgcolor="#3b4d64" style="background-color:#3b4d64;color:#ffffff;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;line-height:1;"><img src="https://issues.jboss.org/s/en_USgbanv7-418945332/852/58/_/jira-logo-scaled.png" alt="" style="vertical-align:top;" /></td>
                </tr><tr valign="top">
    <td id="email-banner" style="padding:32px 32px 0 32px;">

                
        
        
            <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="width:100%;">
    <tr valign="top">
        <td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;padding:0;">
                            &nbsp;                         <div id="email-action" style="padding: 0 0 8px 0;font-size:12px;line-height:18px;">
                                    <a class="user-hover" rel="beve" id="email_beve" href="https://issues.jboss.org/secure/ViewProfile.jspa?name=beve" style="color:#326ca6;">Daniel Bevenius</a>
     edited a comment on <img src="https://issues.jboss.org/images/icons/issuetypes/bug.png" height="16" width="16" border="0" align="absmiddle" alt="Bug"> <a style='color:#326ca6;text-decoration:none;' href='https://issues.jboss.org/browse/AGPUSH-213'>AGPUSH-213</a>
            </div>
                        <div id="email-summary" style="font-size:16px;line-height:20px;padding:2px 0 16px 0;">
                <a style='color:#326ca6;text-decoration:none;' href='https://issues.jboss.org/browse/AGPUSH-213'><strong>Investigate Netty subsystem dependency on datasources</strong></a>
            </div>
                    </td>
    </tr>
</table>
        
    </td>
</tr>
<tr valign="top">
    <td id="email-fields" style="padding:0 32px 32px 32px;">
        <table border="0" cellpadding="0" cellspacing="0" style="padding:0;text-align:left;width:100%;" width="100%">
            <tr valign="top">
                <td id="email-gutter" style="width:64px;white-space:nowrap;"></td>
                <td>
                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr valign="top">
    <td colspan="2" style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 16px 0;width:100%;">
        <div class="comment-block" style="background-color:#edf5ff;border:1px solid #dddddd;color:#000000;padding:12px;"><p>These are the steps I've taken to try to reproduce this issue:<br/>
1. Enable remote debugging by updating standalone.conf, and set the server to wait for a connection.<br/>
2. Set a breakpoint in org.jboss.as.connector.subsystems.datasources.DataSourceConfigService.start(startContext)<br/>
3. Set a breakpoint in org.jboss.aerogear.netty.extension.NettyService.start(startContext)<br/>
4. Start the server</p>

<p>Upon startup we can see the following log statement which is called from the Netty subsystem:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>10:01:34,283 INFO  [org.jboss.aerogear.netty.extension.ServerAdd] (ServerService Thread Pool -- 51) Adding dependency to [service jboss.data-source-config.SimplePushDS]
</pre>
</div></div>

<p>The debugger should have stopped one or more threads, depending on the number of datasources configured. In my case I have four. <br/>
Stepping through these one at a time will produce the following logs:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>10:07:39,557 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
10:07:41,501 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/PushEEDS]
10:07:43,852 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [java:jboss/datasources/MysqlDS]
10:07:45,680 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [java:jboss/datasources/SimplePushDS]
</pre>
</div></div>
<p>If we now resume/continue the next break point that will be hit is org.jboss.aerogear.netty.extension.NettyService.start(startContext).</p>

<p>While writing this and going over the code this looks incorrect. The service we should be depending on is the service binding this to the jndi context. The other service dependencies are probably getting satisfied so the Netty service can go ahead, but the actual datasources might not yet have been bound into jndi causing the failure reported.</p>

<p>If we use the jndi name instead of the datasource name in the configuration and then add a dependency to that BinderService it might work:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">final</span> BindInfo bindinfo = ContextNames.bindInfoFor(datasourceNode.asString());
logger.info(<span class="code-quote">"Adding dependency to ["</span> + bindinfo.getAbsoluteJndiName() + <span class="code-quote">"]"</span>);
sb.addDependencies(bindinfo.getBinderServiceName());
</pre>
</div></div>
<p>With the above code in place I could verify this by taking the following steps:<br/>
1. Enable remote debugging by updating standalone.conf, and set the server to wait for a connection.<br/>
2. Comment out the dependency we add in the ServerAdd class (we want to see the error)<br/>
2. Set a breakpoint in org.jboss.as.connector.subsystems.datasources.DataSourceEnable.addServices()<br/>
3. Set a breakpoint in org.jboss.aerogear.netty.extension.NettyService.start(startContext)<br/>
4. Start the server</p>

<p>Upon startup you should find that there two suspended threads have hit a breakpoint, on for each breakpoint set above. If we focus on the NettyService breakpoint and step through, the start method will try to start the Netty service, but since the data source is not bound yet the following exception will be thrown:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>12:04:04,199 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.netty.simplepush: org.jboss.msc.service.StartException in service jboss.netty.simplepush: [PersistenceUnit: SimplePushPU] Unable to build EntityManagerFactory
        at org.jboss.aerogear.netty.extension.NettyService.createServerBootstrap(NettyService.java:71)
        at org.jboss.aerogear.netty.extension.NettyService.start(NettyService.java:55)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [classes.jar:1.6.0_51]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [classes.jar:1.6.0_51]
        at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_51]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: SimplePushPU] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
        at org.jboss.aerogear.simplepush.server.datastore.JpaDataStore.&lt;init&gt;(JpaDataStore.java:51)
        at org.jboss.aerogear.simplepush.netty.SimplePushBootstrapFactory.createServerBootstrap(SimplePushBootstrapFactory.java:54)
        at org.jboss.aerogear.netty.extension.NettyService.createServerBootstrap(NettyService.java:69)
        ... 6 more
Caused by: org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [java:jboss/datasources/SimplePushDS]
        at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:68)
        at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116)
        at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:234)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:91)
        at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
        at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2270)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2266)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1735)
        at org.hibernate.ejb.EntityManagerFactoryImpl.&lt;init&gt;(EntityManagerFactoryImpl.java:84)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
        ... 13 more
Caused by: javax.naming.NameNotFoundException: datasources/SimplePushDS -- service jboss.naming.context.java.jboss.datasources.SimplePushDS
        at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
        at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
        at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)
        at javax.naming.InitialContext.lookup(InitialContext.java:396) [classes.jar:1.6.0_51]
        at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:65)
        ... 28 more
</pre>
</div></div>

<p>Now, redoing the above steps but this time enabling the dependency that we commented out. This time there will only be a single suspended thread which for DataSourceEnable. Not until the jndi name has been bound will the Netty Service start and since it can now lookup the datasource name the exception is avoided.</p>
</div>
        <div style="color:#505050;padding:4px 0 0 0;">                </div>
    </td>
</tr>
                    </table>
                </td>
            </tr>
        </table>
    </td>
</tr>













            </table>
        </td><!-- End #email-page -->
    </tr>
    <tr valign="top">
        <td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:10px;line-height:14px;padding: 0 16px 16px 16px;text-align:center;">
            This message is automatically generated by JIRA.<br />
            If you think it was sent incorrectly, please contact your JIRA administrators<br />
            For more information on JIRA, see: <a style='color:#326ca6;' href='http://www.atlassian.com/software/jira'>http://www.atlassian.com/software/jira</a>
        </td>
    </tr>
</table><!-- End #email-wrap -->
</div><!-- End #email-body -->