Version 3

    The DynamicInterceptor

     

    JBoss XMBeans introduced in the 3.2.x series provide the ability to plugin

    interceptors to the MBean invocation chain. Those interceptors need to

    implement the org.jboss.mx.interceptor.Interceptor interface and they

    are specified statically in the xmbean descriptor when the MBean gets

    deployed.

     

    This is a nice feature of JBoss that predates the JBoss AOP technology and

    allows you to code to an interceptor design. It is by no means as powerful

    as JBoss AOP, but it is simple and will work, as long as you are dealing

    with (X)MBeans.

     

    Now, what if you want to to dynamically add/remove an interceptor to an

    (X)MBean?

     

    Starting from JBoss v4.0.3, the DynamicInterceptor provides this

    capability. It is a normal interceptor added to any (X)MBean as follows:

     

      <!-- Sample from ejb-deployer -->
      ...
        <xmbean>
          <description>The EJBDeployer responsible for ejb jar deployment</description>
          <descriptors>
            <interceptors>
            
              <interceptor code="org.jboss.mx.interceptor.DynamicInterceptor"></interceptor>  <!-- HERE -->
              
            </interceptors>
          </descriptors>
          <class>org.jboss.ejb.EJBDeployer</class>
      ... 
    

     

    When added to the (X)MBean, the DynamicInterceptor "implements" two new operations

    addOperationInterceptor(Interceptor) and removeOperationInterceptor(Interceptor),

    corresponding to a new internal interface org.jboss.mx.server.Interceptable.

    Adding and removing interceptors is done over the normal MBean inteface, so it

    is necessary to declare those operations as part of the (X)Mbean interface.

     

    In the case of a standalone xmbean descriptor, just use the interceptable

    ENTITY defined in the jboss_xmbean_1_1.dtd, jboss_xmbean_1_2.dtd:

      ...
      <!-- Operations section -->
      &interceptable;
      ...
    

     

    In the case of an xmbean descriptor inlined to the mbean deployment descriptor,

    the interceptable ENTITY is not available, so you need to use:

      ...
      <!-- Operations section -->
      <operation>
        <description>Add dynamically an operation interceptor</description>
        <name>addOperationInterceptor</name>
        <parameter>
          <description>The Interceptor</description>
          <name>interceptor</name>
          <type>org.jboss.mx.interceptor.Interceptor</type>
        </parameter>
      </operation>
    
      <operation>
        <description>Remove dynamically an operation interceptor</description>
        <name>removeOperationInterceptor</name>
        <parameter>
          <description>The Interceptor</description>
          <name>interceptor</name>
          <type>org.jboss.mx.interceptor.Interceptor</type>
        </parameter>
      </operation>
      ...
    

     

    The addition of the DynamicInterceptor has minimal impact to an (X)Mbean.

    The only difference is that whenever one of the above methods gets called,

    it will be served by the DynamicInterceptor and not delegated to the target

    MBean.

     

    Note that, any interceptor added dynamically to the (X)MBean, is put

    first in the internal interceptor chain. Also, the dynamically introduced

    interceptor(s) will only intercept operation calls, and not attribute

    get/sets. This is a limitation that maybe removed in the future.

     

    Having (X)Mbean-ized and DynamicInterceptor enabled your MBeans, you can

    proceed to add/remove dynamically interceptors to it. A convenient way

    to do this is by extending the org.jboss.system.InterceptorServiceMBeanSupport

    base class.

     

    Related:

     

    InterceptorServiceMBeanSupport

     

    HowDoIXMBeanIzeAnExistingStandardMBean

     

    Referenced by: