[jboss-user] [EJB 3.0] - Re: MBean start ordering in 5.0CR2

huberth do-not-reply at jboss.com
Fri Oct 17 09:11:32 EDT 2008


I've got it.  Try this:

public interface LifeCycle
  | {
  |     public void create() throws Exception;
  |     public void start() throws Exception;
  | 
  |     public void destroy();
  |     public void stop();
  | }

@Management(LifeCycle.class)
  | @Service(objectName = "myorg:service=MBeanB")
  | public class MBeanB implements LifeCycle
  | {
  |     private static final Logger logger = Logger.getLogger(MBeanB.class);
  | 
  |     public void create() throws Exception
  |     {
  |         logger.log(Level.INFO, "Creating");
  |     }
  | 
  |     public void start() throws Exception
  |     {
  |         logger.log(Level.INFO, "Starting");
  |     }
  | 
  |     public void destroy()
  |     {
  |         logger.log(Level.INFO, "Destroying");
  |     }
  | 
  |     public void stop()
  |     {
  |         logger.log(Level.INFO, "Stopping");
  |     }
  | }

@Management(LifeCycle.class)
  | @Depends("myorg:service=MBeanB")
  | @Service(objectName = "myorg:service=MBeanA")
  | public class MBeanA implements LifeCycle
  | {
  |     private static final Logger logger = Logger.getLogger(MBeanA.class);
  | 
  |     public void create() throws Exception
  |     {
  |         logger.log(Level.INFO, "Creating");
  |     }
  | 
  |     public void start() throws Exception
  |     {
  |         logger.log(Level.INFO, "Starting");
  |     }
  | 
  |     public void destroy()
  |     {
  |         logger.log(Level.INFO, "Destroying");
  |     }
  | 
  |     public void stop()
  |     {
  |         logger.log(Level.INFO, "Stopping");
  |     }
  | }

Then put MBeanA into a.jar and MBeanB into b.jar (the jar names matter - the relative alphabetical sort order to be precise).  Create an exploded ear in the deploy directory with no application.xml (not sure if this part matters, but it's what I've been doing) and place the two jars in it.

I get the following logs, indicating they started out of order:

2008/10/17 08:54:18.813 INFO  (main) [com.myorg.common.server.MBeanA.create:36] Creating
  | 2008/10/17 08:54:18.835 INFO  (main) [com.myorg.common.server.MBeanA.start:41] Starting
  | 2008/10/17 08:54:18.842 INFO  (main) [com.myorg.common.server.MBeanB.create:35] Creating
  | 2008/10/17 08:54:18.896 INFO  (main) [com.myorg.common.server.MBeanB.start:40] Starting

The ear's contents are sorted first by suffix, then by name to come up with the attempted installation order.  Since MBeanA comes first, but can't be installed yet due to an unresolved dependency, it is skipped.  When MBeanB is installed, we recurse looking for newly resolved dependencies, at which time we find MBeanB and attempt to install it.  Unfortunately, as I mentioned previously, the create/start methods get invoked only after this recursion.

So the recursion is probably correct, but the great distance (code-wise) between the state transitions and the invocation of the corresponding life cycle methods is probably the real problem.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4182902#4182902

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4182902



More information about the jboss-user mailing list