JBoss.org Community Documentation
EJB 2.0 added local interfaces that do not use RMI call by value semantics. These interfaces use a call by reference semantic and therefore do not incur any RMI serialization overhead. An EJB local reference is a link in an application component naming environment that points to a deployed EJB local home interface. The name used by the application component is a logical link that isolates the component from the actual name of the EJB local home in the deployment environment. The J2EE specification recommends that all references to enterprise beans be organized in the java:comp/env/ejb
context of the application component's environment.
An EJB local reference is declared using an ejb-local-ref
element in the deployment descriptor. Each ejb-local-ref
element describes the interface requirements that the referencing application component has for the referenced enterprise bean. The ejb-local-ref
element contains the following child elements:
An optional description element that provides the purpose of the reference.
An
ejb-ref-name
element that specifies the name of the reference relative to the java:comp/env
context. To place the reference under the recommended java:comp/env/ejb
context, use an ejb/link-name
form for the ejb-ref-name
value.
An
ejb-ref-type
element that specifies the type of the EJB. This must be either Entity
or Session
.
A local-home element that gives the fully qualified class name of the EJB local home interface.
A local element that gives the fully qualified class name of the EJB local interface.
An
ejb-link
element that links the reference to another enterprise bean in the ejb-jar
file or in the same J2EE application unit. The ejb-link
value is the ejb-name
of the referenced bean. If there are multiple enterprise beans with the same ejb-name
, the value uses the path name specifying the location of the ejb-jar
file that contains the referenced component. The path name is relative to the referencing ejb-jar
file. The Application Assembler appends the ejb-name
of the referenced bean to the path name separated by #
. This allows multiple beans with the same name to be uniquely identified. An ejb-link
element must be specified in JBoss to match the local reference to the corresponding EJB.
An EJB local reference is scoped to the application component whose declaration contains the ejb-local-ref
element. This means that the EJB local reference is not accessible from other application components at runtime, and that other application components may define ejb-local-ref
elements with the same ejb-ref-name
without causing a name conflict. Example 4.10, “An example ejb-jar.xml ejb-local-ref descriptor fragment” provides an ejb-jar.xml
fragment that illustrates the use of the ejb-local-ref
element. A code sample that illustrates accessing the ProbeLocalHome
reference declared in Example 4.10, “An example ejb-jar.xml ejb-local-ref descriptor fragment” is given in Example 4.11, “ENC ejb-local-ref access code fragment”.
<!-- ... --> <session> <ejb-name>Probe</ejb-name> <home>org.jboss.test.perf.interfaces.ProbeHome</home> <remote>org.jboss.test.perf.interfaces.Probe</remote> <local-home>org.jboss.test.perf.interfaces.ProbeLocalHome</local-home> <local>org.jboss.test.perf.interfaces.ProbeLocal</local> <ejb-class>org.jboss.test.perf.ejb.ProbeBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Bean</transaction-type> </session> <session> <ejb-name>PerfTestSession</ejb-name> <home>org.jboss.test.perf.interfaces.PerfTestSessionHome</home> <remote>org.jboss.test.perf.interfaces.PerfTestSession</remote> <ejb-class>org.jboss.test.perf.ejb.PerfTestSessionBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> <ejb-ref> <ejb-ref-name>ejb/ProbeHome</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>org.jboss.test.perf.interfaces.SessionHome</home> <remote>org.jboss.test.perf.interfaces.Session</remote> <ejb-link>Probe</ejb-link> </ejb-ref> <ejb-local-ref> <ejb-ref-name>ejb/ProbeLocalHome</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home>org.jboss.test.perf.interfaces.ProbeLocalHome</local-home> <local>org.jboss.test.perf.interfaces.ProbeLocal</local> <ejb-link>Probe</ejb-link> </ejb-local-ref> </session> <!-- ... -->
Example 4.10. An example ejb-jar.xml ejb-local-ref descriptor fragment
InitialContext iniCtx = new InitialContext(); Context ejbCtx = (Context) iniCtx.lookup("java:comp/env/ejb"); ProbeLocalHome home = (ProbeLocalHome) ejbCtx.lookup("ProbeLocalHome");
Example 4.11. ENC ejb-local-ref access code fragment