<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
EJBTHREE-2198 EJB resource providers for switchboard and the dependency issues
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/jaikiran">jaikiran pai</a> in <i>EJB3 Development</i> - <a href="http://community.jboss.org/message/571870#571870">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p><span>Here's a quick overview of what the @EJB, ejb-ref, ejb-local-ref resource provider is expected to do. More details about what a ResourceProvider is and what role it plays can be found in this wiki </span><a class="jive-link-external-small" href="http://community.jboss.org/docs/DOC-15954" target="_blank">http://community.jboss.org/wiki/Switchboard</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5>Goal:</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Consider this @EJB reference (in a servlet, for example):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> MyServlet
<font color="navy">{</font>
 
    @EJB
    <font color="navy"><b>private</b></font> MyBeanIntf bean;
   
<font color="navy">}</font>
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>And then consider this EJB:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">@Stateless
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> MySLSB <font color="navy"><b>implements</b></font> MyBeanIntf   
<font color="navy">{</font>
...
   
<font color="navy">}</font>   
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>So ultimately, when the web application is being deployed, the servlet container shouldn't "start" unless the Resource (check the above wiki for what it means) corresponding to:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">@EJB
<font color="navy"><b>private</b></font> MyBeanIntf bean;
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>is made available in the ENC (java:comp/env) of the servlet.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5>EJB container implementation details:</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The JBoss EJB3 container in AS6 is a MC bean. When the JBoss EJB3 container finds a EJB (MySLSB in this case), among various other things, it binds the proxies to (JBoss specific) jndi names during its "start" (MC) lifecycle method. This has been legacy since AS5.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span>Starting AS6 when we started supporting EJB3.1, we also bind the EJB proxies to a spec compliant JNDI name (along with the JBoss specific jndi names). The binding to EJB3.1 compliant JNDI names is done by the EJBBinder </span><a class="jive-link-external-small" href="https://github.com/jbossejb3/jboss-ejb3-jndi/blob/master/binder/src/main/java/org/jboss/ejb3/jndi/binder/EJBBinder.java" target="_blank">https://github.com/jbossejb3/jboss-ejb3-jndi/blob/master/binder/src/main/java/org/jboss/ejb3/jndi/binder/EJBBinder.java</a><span> and has no interaction with the EJB containers. i.e. binding to EJB3.1 spec compliant jndi names is (intentionally) completely decoupled from EJB containers. The EJBBinder is deployed as a MC bean by the EJBBinderDeployer </span><a class="jive-link-external-small" href="https://github.com/jbossejb3/jboss-ejb3-jndi/blob/master/deployers/src/main/java/org/jboss/ejb3/jndi/deployers/EJBBinderDeployer.java" target="_blank">https://github.com/jbossejb3/jboss-ejb3-jndi/blob/master/deployers/src/main/java/org/jboss/ejb3/jndi/deployers/EJBBinderDeployer.java</a><span>, so that the binding happens during the "start" lifecycle of that MC bean (when any necessary dependencies on the EJBBinder are satisfied)</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Currently in AS6, we bind the EJB3.1 jndi names as LinkRefs to jboss specific jndi names. So the EJBBinder creates and returns a LinkRef to the JBoss specific jndi name which will be created by the JBoss EJB3 containers.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5><br/>The ResourceProvider details and the problem:</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The ResourceProvider for @EJB, ejb-local-ref and ejb-ref is responsible for resolving the MC bean name of the EJBBinder from a ejb-ref, ejb-local-ref and @EJB. How the resolution is done is currently not relevant for this discussion. Let's just assume that we somehow manage to resolve it to a EJBBinder. The ResourceProvider then return this EJBBinder back to switchboard which converts this to a MC dependency. i.e. SwitchBoard adds a dependency on the servlet container for this EJBBinder MC bean to be installed before the servlet container can make available the servlet. Ideally, this should all work out, but there's a minor little detail in this implementation which causes it to fail. Let's see why:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>1) Web container (through SwitchBoard and RPs) adds a dependency on the EJBBinder responsible for setting up EJB3.1 spec compliant java:global jndi name of MySLSB<br/>2) EJBBinder is added as a MC bean<br/>3) EJBContainer corresponding to MyBean is added as a MC bean<br/>4) MC starts installing MC beans. Let's assume it picks up EJBBinder first. EJBBinder "starts" and binds to java:global a LinkRef<br/>5) MC sees that the EJBBinder dependency for web container is now satisfied and triggers the web container startup<br/>6) Web container starts initialzing instances (like load-on-startup servlets, filters etc...)<br/>7) While injecting from ENC to filter/servlet, container runs into error because the EJBContainer (#3) which is responsible for setting up the JBoss specific JNDI names, which are the target of the LinkRef created in #4, hasn't yet been triggered for "start" by MC.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5><br/>Solution:</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>For AS6 we somehow need to add a dependency on the EJBBinder such that it isn't installed until the JBoss specific jndi names aren't bound into JNDI. It isn't easy because the code responsible for deploying EJBBinder as a MC bean (i.e. EJBBinderDeployer) somehow needs to know what the JBoss specific JNDI names are for each of the exposed view of the bean.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Note that this may not be the only solution and there might be other ways to get past this. But the goal is to get this up and running as quickly as possible without having to change a lot of stuff.</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/571870#571870">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2030">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>