Version 2

    Abstract baseclass SubDeployerInterceptorSupport

     

    As of JBoss v4.0.3, there is a new baseclass that helps writing

    MBean services that dynamically hooks-up a JMX Interceptor to one or more

    SubDeployers that have been configured as Interceptables.

     

    The reason to do this is if you want to plugin functionality that is

    optional to a SubDeployer. For example, the code in JBoss HEAD uses this

    feature to enable WebService support for the ejb, ejb3 and web deployers.

     

    This is better that operating on JMX subdeployer notifications, since the

    notifications are produced after the deployment lifecycle events

    (i.e. init, create, start, stop, destroy) have taken place, plus you have

    no control over the fate of the deployment.

     

    In contrast, a SubDeployerInterceptor service can intercept calls to

    the targeted SubDeployers, do its own thing and potentially fail

    a deployment by throwing an exception.

     

    org.jboss.deployment.SubDeployerInterceptorSupport is just a subclass

    of org.jboss.system.InterceptorServiceMBeanSupport, that knows about

    the SubDeployer interface, and thus can qualify the intercepted calls.

     

    Instead of invoke(Invocation), you override any of the methods below.

    Normally, you'll apply your own logic before and/or after invoking

    invokeNext(invocation) to let the call proceed to the target SubDeployer:

      /**
        * Override
        */   
       protected Object init(Invocation invocation, DeploymentInfo di) throws Throwable
       {
          return invokeNext(invocation);
       }
    
       /**
        * Override
        */
       protected Object create(Invocation invocation, DeploymentInfo di) throws Throwable
       {
          return invokeNext(invocation);
       }
    
       /**
        * Override
        */
       protected Object start(Invocation invocation, DeploymentInfo di) throws Throwable
       {
          return invokeNext(invocation);
       }
    
       /**
        * Override
        */
       protected Object stop(Invocation invocation, DeploymentInfo di) throws Throwable
       {
          return invokeNext(invocation);
       }
    
       /**
        * Override
        */
       protected Object destroy(Invocation invocation, DeploymentInfo di) throws Throwable
       {
          return invokeNext(invocation);
       }
    

     

    To add/remove the jmx interceptor to the target mbeans, you may call

    the attach()/detach() method in the base class. By default, those

    methods are called inside startService()/stopService():

       /**
        * Override
        */
       protected void startService() throws Exception
       {
          attach();
       }
       
       /**
        * Override
        */
       protected void stopService()
       {
          detach();
       }
    

    The final step is to configure the target Interceptables attribute.

    For example, to attach to the ejb, ejb3 and web deployer use:

       ...
       <depends-list optional-attribute-name="Interceptables">
          <depends-list-element>jboss.ejb:service=EJBDeployer</depends-list-element>
          <depends-list-element>jboss.ejb3:service=EJB3Deployer</depends-list-element>
          <depends-list-element>jboss.web:service=WebServer</depends-list-element>
       </depends-list>
    

    Those 3 SubDeployers have already been (X)Mbean-ized in JBoss 4.x and HEAD.

    To enable other SubDeployers as Interceptables, except for the (X)MBean

    descriptor we need to make sure the SubDeployers use a dynamic MBeanServer

    proxy, rather than a direct 'this' reference, when registering with the MainDeployer.

     

    This is done as follows for the EJBDeployer:

    public class EJBDeployer extends SubDeployerSupport
       implements EJBDeployerMBean
    {
       ...
       /** Hold a proxy reference to myself, used when registering to MainDeployer */
       private SubDeployer thisProxy;
       ...
       protected void startService() throws Exception
       {
          ...
          // Do NOT call super.startService()!
    
          // make a proxy to myself, so that calls from the MainDeployer
          // can go through the MBeanServer, so interceptors can be added
          thisProxy = (SubDeployer)
             MBeanProxyExt.create(SubDeployer.class, super.getServiceName(), super.getServer());
          
          // Register with the main deployer
          mainDeployer.addDeployer(thisProxy);
       }
    
       protected void stopService() throws Exception
       {
          ...
          // Do NOT call super.stopService();
          
          // deregister with MainDeployer
          mainDeployer.removeDeployer(thisProxy);
          ...
       }
    

           

     

    SubDeployer interceptors that we may consider adding, could be related to

    security, logging, etc.

     

    Related:

     

    DynamicInterceptor

     

    InterceptorServiceMBeanSupport

     

    HowDoIXMBeanIzeAnExistingStandardMBean

     

    Referenced by: