The EJB Server-Side View


Every EJB invocation must end up at a JBoss server-hosted EJB container. The following sections look at how invocations are transported to the JBoss server VM and find their way to the EJB container via the JMX bus.

Detached Invokers: The Transport Middlemen

Earlier in this chapter, we looked at the detached invoker architecture in the context of exposing RMI-compatible interfaces of MBean services. Here we will look at how detached invokers are used to expose the EJB container home and bean interfaces to clients. The generic view of the invoker architecture is presented in Figure 5.3.

Figure 5.3. The transport invoker server-side architecture.


For each type of home proxy, there is a binding to an invoker and its associated transport protocol. A container may have multiple invocation protocols active simultaneously. In the jboss.xml file, an invoker-proxy-binding-name maps to an invoker-proxy-binding/name element. At the container-configuration level, this specifies the default invoker that will be used for EJBs deployed to the container. At the bean level, the invoker-bindings specify one or more invokers to use with the EJB container MBean.

When you specify multiple invokers for a given EJB deployment, you must give the home proxy a unique JNDI binding location. You specify this in the invoker/jndi-name element value. Another issue when multiple invokers exist for an EJB is how to handle remote homes or interfaces obtained when the EJB calls other beans. Any such interfaces need to use the same invoker used to call the outer EJB in order for the resulting remote homes and interfaces to be compatible with the proxy through which the client has initiated the call. The invoker/ejb-ref elements allow you to map from a protocol-independent ENC ejb-ref to the home proxy binding for an ejb-ref target EJB home that matches the referencing invoker type.

An example of using a custom JRMPInvoker MBean that enables compressed sockets for session beans can be found in the org.jboss.test.jrmp package of the testsuite. The following example illustrates the custom JRMPInvoker configuration and its mapping to a stateless session bean:

 <server>     <mbean code="org.jboss.invocation.jrmp.server.JRMPInvoker"           name="jboss:service=invoker,type=jrmp,socketType=CompressionSocketFactory">         <attribute name="RMIObjectPort">4445</attribute>         <attribute name="RMIClientSocketFactory">             org.jboss.test.jrmp.ejb.CompressionClientSocketFactory         </attribute>         <attribute name="RMIServerSocketFactory">             org.jboss.test.jrmp.ejb.CompressionServerSocketFactory         </attribute>     </mbean> </server> 

Here the default JRMPInvoker has been customized to bind to port 4445 and to use custom socket factories that enable compression at the transport level:

 <?xml version="1.0"?> <!DOCTYPE jboss PUBLIC           "-//JBoss//DTD JBOSS 3.2//EN"           "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd"> <!-- The jboss.xml descriptor for the jrmp-comp.jar ejb unit --> <jboss>     <enterprise-beans>         <session>             <ejb-name>StatelessSession</ejb-name>             <configuration-name>Standard Stateless SessionBean</configuration-name>             <invoker-bindings>                 <invoker>                     <invoker-proxy-binding-name>                         stateless-compression-invoker                     </invoker-proxy-binding-name>                     <jndi-name>jrmp-compressed/StatelessSession</jndi-name>                 </invoker>             </invoker-bindings>         </session>     </enterprise-beans>     <invoker-proxy-bindings>         <invoker-proxy-binding>             <name>stateless-compression-invoker</name>             <invoker-mbean>                 jboss:service=invoker,type=jrmp,socketType=CompressionSocketFactory             </invoker-mbean>             <proxy-factory>org.jboss.proxy.ejb.ProxyFactory</proxy-factory>             <proxy-factory-config>                 <client-interceptors>                     <home>                         <interceptor>org.jboss.proxy.ejb.HomeInterceptor</interceptor>                         <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>                         <interceptor>org.jboss.proxy.TransactionInterceptor</interceptor>                         <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>                     </home>                     <bean>                         <interceptor>                             org.jboss.proxy.ejb.StatelessSessionInterceptor                         </interceptor>                         <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>                         <interceptor>org.jboss.proxy.TransactionInterceptor</interceptor>                         <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>                     </bean>                 </client-interceptors>             </proxy-factory-config>         </invoker-proxy-binding>     </invoker-proxy-bindings> </jboss> 

The StatelessSession EJB invoker-bindings settings specify that the stateless-compression-invoker will be used with the home interface bound under the JNDI name j rmp-compressed/StatelessSession. The stateless-compression-invoker is linked to the custom JRMP invoker we just declared.

The following example, from the org.jboss.test.hello testsuite package, is an example of using the HttpInvoker to configure a stateless session bean to use the RMI/HTTP protocol:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE jboss PUBLIC           "-//JBoss//DTD JBOSS 3.2//EN"           "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd"> <jboss>     <enterprise-beans>         <session>             <ejb-name>HelloWorldViaHTTP</ejb-name>             <jndi-name>helloworld/HelloHTTP</jndi-name>             <invoker-bindings>                 <invoker>                     <invoker-proxy-binding-name>                         stateless-http-invoker                     </invoker-proxy-binding-name>                 </invoker>             </invoker-bindings>         </session>     </enterprise-beans>     <invoker-proxy-bindings>         <!-- A custom invoker for RMI/HTTP -->         <invoker-proxy-binding>             <name>stateless-http-invoker</name>             <invoker-mbean>jboss:service=invoker,type=http</invoker-mbean>             <proxy-factory>org.jboss.proxy.ejb.ProxyFactory</proxy-factory>             <proxy-factory-config>                 <client-interceptors>                     <home>                         <interceptor>org.jboss.proxy.ejb.HomeInterceptor</interceptor>                         <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>                         <interceptor>org.jboss.proxy.TransactionInterceptor</interceptor>                         <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>                     </home>                     <bean>                         <interceptor>                             org.jboss.proxy.ejb.StatelessSessionInterceptor                         </interceptor>                         <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>                         <interceptor>org.jboss.proxy.TransactionInterceptor</interceptor>                         <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>                     </bean>                 </client-interceptors>             </proxy-factory-config>         </invoker-proxy-binding>     </invoker-proxy-bindings> </jboss> 

Here a custom invoker-proxy-binding named stateless-http-invoker is defined. It uses the HttpInvoker MBean as the detached invoker. The jboss:service=invoker,type=http name is the default name of the HttpInvoker MBean, as found in the http-invoker.sar/META-INF/jboss-service.xml descriptor, and its service descriptor fragment is shown here:

 <!-- The HTTP invoker service configuration --> <mbean code="org.jboss.invocation.http.server.HttpInvoker"        name="jboss:service=invoker,type=http">     <!-- Use a URL of the form http://<hostname>:8080/invoker/EJBInvokerServlet          where <hostname> is InetAddress.getHostname value on which the server          is running. -->     <attribute name="InvokerURLPrefix">http://</attribute>     <attribute name="InvokerURLSuffix">:8080/invoker/EJBInvokerServlet</attribute>     <attribute name="UseHostName">true</attribute> </mbean> 

The client proxy posts the EJB invocation content to the EJBInvokerServlet URL specified in the HttpInvoker service configuration.

The HA JRMPInvoker: Clustered RMI/JRMP Transport

The org.jboss.invocation.jrmp.server.JRMPInvokerHA service is an extension of the JRMPInvoker that is a cluster-aware invoker. The JRMPInvokerHA fully supports all the attributes of the JRMPInvoker. This means that customized bindings of the port, interface, and socket transport are available to clustered RMI/JRMP as well.

The HA HttpInvoker: Clustered RMI/HTTP Transport

The RMI/HTTP layer allows for software load balancing of the invocations in a clustered environment. An HA-capable extension of the HTTP invoker has been added that borrows much of its functionality from the HA-RMI/JRMP clustering.

To enable HA-RMI/HTTP, you need to configure the invokers for the EJB container. You do this through either a jboss.xml descriptor or the standardjboss.xml descriptor. Listing 5.3 shows an example of a stateless session configuration taken from the org.jboss.test.hello testsuite package.

Listing 5.3. A jboss.xml Stateless Session Configuration for HA-RMI/HTTP
 <jboss>     <enterprise-beans>         <session>             <ejb-name>HelloWorldViaClusteredHTTP</ejb-name>             <jndi-name>helloworld/HelloHA-HTTP</jndi-name>             <invoker-bindings>                 <invoker>                     <invoker-proxy-binding-name>                         stateless-httpHA-invoker                     </invoker-proxy-binding-name>                 </invoker>             </invoker-bindings>             <clustered>true</clustered>         </session>     </enterprise-beans>     <invoker-proxy-bindings>         <invoker-proxy-binding>             <name>stateless-httpHA-invoker</name>             <invoker-mbean>jboss:service=invoker,type=httpHA</invoker-mbean>             <proxy-factory>org.jboss.proxy.ejb.ProxyFactoryHA</proxy-factory>             <proxy-factory-config>                 <client-interceptors>                     <home>                         <interceptor>org.jboss.proxy.ejb.HomeInterceptor </interceptor>                         <interceptor>org.jboss.proxy.SecurityInterceptor </interceptor>                         <interceptor>org.jboss.proxy.TransactionInterceptor </interceptor>                         <interceptor>org.jboss.invocation.InvokerInterceptor </interceptor>                     </home>                     <bean>                         <interceptor>                             org.jboss.proxy.ejb.StatelessSessionInterceptor                         </interceptor>                         <interceptor>org.jboss.proxy.SecurityInterceptor </interceptor>                         <interceptor>org.jboss.proxy.TransactionInterceptor </interceptor>                         <interceptor>org.jboss.invocation.InvokerInterceptor </interceptor>                     </bean>                 </client-interceptors>             </proxy-factory-config>         </invoker-proxy-binding>     </invoker-proxy-bindings> </jboss> 

The stateless-httpHA-invoker invoker-proxy-binding references the jboss:service=invoker,type=httpHA invoker service. This service would be configured as follows:

 <mbean code="org.jboss.invocation.http.server.HttpInvokerHA"        name="jboss:service=invoker,type=httpHA">     <!-- Use a URL of the form          http://<hostname>:8080/invoker/EJBInvokerHAServlet          where <hostname> is InetAddress.getHostname value on which the server          is running.     -->     <attribute name="InvokerURLPrefix">http://</attribute>     <attribute name="InvokerURLSuffix">:8080/invoker/EJBInvokerHAServlet </attribute>     <attribute name="UseHostName">true</attribute> </mbean> 

The URL used by the invoker proxy is the EJBInvokerHAServlet mapping, as deployed on the cluster node. The HttpInvokerHA instances across the cluster form a collection of candidate HTTP URLs that are made available to the client-side proxy for failover and/or load balancing.



JBoss 4. 0(c) The Official Guide
JBoss 4.0 - The Official Guide
ISBN: B003D7JU58
EAN: N/A
Year: 2006
Pages: 137

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net