7 Replies Latest reply on Jul 24, 2007 2:20 AM by Ales Justin

    Emulating ServiceMBeanSupport

    Elias Ross Master

      ServiceMBeanSupport exposes methods stop, start, create, destroy. These are implemented to in turn call the ServiceController, which then calls jbossInternalLifecycle(), which then calls startService(), stopService(), etc. This means if somebody does a call to "stop", the controller state will be changed, dependent services will be stopped as well, etc. This is different than the Microcontainer which treats "stop" as a callback, "stop" will be called after state is changed.

      In JBoss 5.0 some of the state management is handled by the Microcontainer. But a lot is still handled by the ServiceController.

      What I would like to do is if have a POJO such as:

      public class MyService {
       public void start() throws Exception { ... }
       public void stop() throws Exception { ... }
       public String getState() { return null; }

      is called by the Microcontainer, before the START controller state is reached.

      If somebody (other than the Microcontainer) calls
      , I'd like AOP to intercept this call and instead call the Microcontainer to handle the stop transition. I'm a newbie and not sure how to write this AOP declaration in the -beans.xml. Probably what I will have is an annotation (@Service ?) marking classes to apply this to.

      When I write my Interceptor, how do I know if the Microcontainer is calling me due to Lifecycle transition, or the call is from "somebody else"?

      I'd like to also intercept calls to the method "getState()" and return the Microcontainer state. Or, I'd like to "inject" state somehow.
      public class MyService {
       State state;
       public State getState() { return state; }