The AS7 book!

JBoss Tuning

Top Programming Sites
Home JBoss AS Monitoring JBoss's EJB Container

Monitoring JBoss's EJB Container

In this short article we will show how easily you can write an Interceptor class which is added in the chain of Stateless interceptors. The purpose of this Interceptor is adding debugging information to your Stateless Bean Pool.
JBoss 5 EJB container is based on the concept of interceptors. These are simple classed based on the Proxy pattern, which allow to execute all the required steps before method invocation (security checks, instance creation, transaction propagation etc.).

The great benefit of interceptors is that they are a seamless way to add Aspect Oriented Programming to your business methods.

EJB 3 Interceptors are defined in the file server/<your server>/deploy/ejb3-interceptors.xml.

Here's the section we want to operate on:
 <domain name="Stateless Bean" extends="Intercepted Bean" inheritBindings="true">
     . . . .
      <bind pointcut="execution(public * *->*(..))">
         
         <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.tx.CMTTxInterceptorFactory"/>
         <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.tx.BMTTxInterceptorFactory"/>
         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
         <!-- interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/ -->
         <stack-ref name="EJBInterceptors"/>
      </bind>
      <annotation expr="!class(@org.jboss.ejb3.annotation.Pool)">
         @org.jboss.ejb3.annotation.Pool (value="ThreadlocalPool", maxSize=30, timeout=10000)
      </annotation>
</domain>

#2 Update jboss-ejb3-core.jar

<!--------- OUR INTERCEPTOR ---------->
   
   <interceptor class="com.sample.PoolInterceptor" scope="PER_VM"/>
   
   ........
   
   <domain name="Stateless Bean" extends="Intercepted Bean" inheritBindings="true">
         
         <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.tx.CMTTxInterceptorFactory"/>
         <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.tx.BMTTxInterceptorFactory"/>
         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
         
         <!--------- OUR INTERCEPTOR ---------->
         <interceptor-ref name="com.sample.PoolInterceptor"/> 
         
         
         <stack-ref name="EJBInterceptors"/>
      </bind>
      <annotation expr="!class(@org.jboss.ejb3.annotation.Pool)">
         @org.jboss.ejb3.annotation.Pool (value="StrictMaxPool", maxSize=1000, timeout=100000)
      </annotation>
   </domain>


Compile the interceptor and add the class to the jboss-ejb3-core.jar

jboss as stateless slsb ejb pool
 That's all! restart the server and verify that your SLSB now debugs information about the current/max size of instances.
Monitoring JBoss's EJB Container
 

License

Mastertheboss.com Unless stated, all the contents of this site is licensed under Creative Comons License
Licenza Creative Commons