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

jaikiran do-not-reply at jboss.com
Thu Oct 16 04:23:14 EDT 2008


anonymous wrote :  When MBeanA's start method is called, it calls a method on MBeanB via its injected reference, which delegates to the singleton. The problem is that at this point, a field in the singleton has not been initialized, as MBeanB's start method hasn't yet been called.
  | 

As per the documentation http://docs.jboss.org/ejb3/app-server/reference/build/reference/en/html/jboss_extensions.html:

anonymous wrote : start() - called by the server when the service is started and all the services it depends upon have been started too. At this point the service (and all the services it depends on) is fully functional.

So what you are observing should not have happened. So i decided to give it a try with a simple application with 2 dependent services (MyService depends on AnotherService):

@Service (objectName = "org.myapp:name=MyService")
  | @Management(MyService.class)
  | @Depends({"org.myapp:name=AnotherService"})
  | public class MyServiceImpl implements MyService {
  | 
  | 	
  | 	public void create() throws Exception {
  | 		System.out.println("Created " + this.getClass().getName() + " at " + new Timestamp(System.currentTimeMillis()));
  | 		
  | 	}
  | 
  | 	public void start() throws Exception {
  | 		System.out.println("Started " + this.getClass().getName() + " at " + new Timestamp(System.currentTimeMillis()));
  | 		
  | 		
  | 	}
  | 	
  | }
  | 
  | 

@Service (objectName = "org.myapp:name=AnotherService")
  | @Management(AnotherService.class)
  | public class AnotherServiceImpl implements AnotherService {
  | 
  | 	public void create() throws Exception {
  | 		System.out.println("Created " + this.getClass().getName() + " at " + new Timestamp(System.currentTimeMillis()));
  | 		
  | 	}
  | 
  | 	public void start() throws Exception {
  | 		System.out.println("Started " + this.getClass().getName() + " at " + new Timestamp(System.currentTimeMillis()));
  | 		
  | 	}
  | 
  | }
  | 
  | 
  | 

Since MyService depends on AnotherService, the start() of AnotherService will be called first and then the start() of the MyService. And that's exactly how it behaves as can be seen in the logs:

13:42:24,590 INFO  [JBossASKernel] Created KernelDeployment for: myapp_ejb3.jar
  | 13:42:24,605 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=ServiceTest.ear,jar=myapp_ejb3.jar,name=AnotherServiceImpl,service=EJB3
  | 13:42:24,605 INFO  [JBossASKernel]   with dependencies:
  | 13:42:24,605 INFO  [JBossASKernel]   and demands:
  | 13:42:24,605 INFO  [JBossASKernel]      jboss.ejb:service=EJBTimerService
  | 13:42:24,605 INFO  [JBossASKernel]   and supplies:
  | 13:42:24,605 INFO  [JBossASKernel]      Class:org.myapp.service.AnotherService
  | 13:42:24,605 INFO  [JBossASKernel]      jndi:ServiceTest/AnotherServiceImpl/remote
  | 13:42:24,605 INFO  [JBossASKernel]      jndi:ServiceTest/AnotherServiceImpl/local
  | 13:42:24,605 INFO  [JBossASKernel]      jndi:ServiceTest/AnotherServiceImpl/local-org.myapp.service.AnotherService
  | 13:42:24,605 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=ServiceTest.ear,jar=myapp_ejb3.jar,name=AnotherServiceImpl,service=EJB3) to KernelDeployment of: myapp_ejb3.jar
  | 13:42:24,605 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=ServiceTest.ear,jar=myapp_ejb3.jar,name=MyServiceImpl,service=EJB3
  | 13:42:24,605 INFO  [JBossASKernel]   with dependencies:
  | 13:42:24,605 INFO  [JBossASKernel]   and demands:
  | 13:42:24,605 INFO  [JBossASKernel]      jboss.ejb:service=EJBTimerService
  | 13:42:24,605 INFO  [JBossASKernel]      org.myapp:name=AnotherService
  | 13:42:24,605 INFO  [JBossASKernel]   and supplies:
  | 13:42:24,605 INFO  [JBossASKernel]      jndi:ServiceTest/MyServiceImpl/local
  | 13:42:24,605 INFO  [JBossASKernel]      jndi:ServiceTest/MyServiceImpl/local-org.myapp.service.MyService
  | 13:42:24,605 INFO  [JBossASKernel]      Class:org.myapp.service.MyService
  | 13:42:24,605 INFO  [JBossASKernel]      jndi:ServiceTest/MyServiceImpl/remote
  | 13:42:24,605 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=ServiceTest.ear,jar=myapp_ejb3.jar,name=MyServiceImpl,service=EJB3) to KernelDeployment of: myapp_ejb3.jar
  | 13:42:25,027 INFO  [EJBContainer] STARTED EJB: org.myapp.service.AnotherServiceImpl ejbName: AnotherServiceImpl
  | 13:42:25,136 INFO  [JBossASKernel] installing bean: org.myapp:name=AnotherService
  | 13:42:25,136 INFO  [JBossASKernel]   with dependencies:
  | 13:42:25,136 INFO  [JBossASKernel]   and demands:
  | 13:42:25,136 INFO  [JBossASKernel]      jboss.ejb:service=EJBTimerService
  | 13:42:25,136 INFO  [JBossASKernel]   and supplies:
  | 13:42:25,136 INFO  [JBossASKernel]      Class:org.myapp.service.AnotherService
  | 13:42:25,136 INFO  [JBossASKernel]      jndi:ServiceTest/AnotherServiceImpl/remote
  | 13:42:25,136 INFO  [JBossASKernel]      jndi:ServiceTest/AnotherServiceImpl/local
  | 13:42:25,136 INFO  [JBossASKernel]      jndi:ServiceTest/AnotherServiceImpl/local-org.myapp.service.AnotherService
  | 13:42:25,136 INFO  [JBossASKernel] Installing bean(org.myapp:name=AnotherService) into kernel
  | 13:42:25,230 INFO  [STDOUT] Created org.myapp.service.AnotherServiceImpl at 2008-10-16 13:42:25.23
  | 13:42:25,855 INFO  [STDOUT] Started org.myapp.service.AnotherServiceImpl at 2008-10-16 13:42:25.855
  | 13:42:26,527 INFO  [EJBContainer] STARTED EJB: org.myapp.service.MyServiceImpl ejbName: MyServiceImpl
  | 13:42:26,558 INFO  [JBossASKernel] installing bean: org.myapp:name=MyService
  | 13:42:26,558 INFO  [JBossASKernel]   with dependencies:
  | 13:42:26,558 INFO  [JBossASKernel]   and demands:
  | 13:42:26,558 INFO  [JBossASKernel]      jboss.ejb:service=EJBTimerService
  | 13:42:26,558 INFO  [JBossASKernel]      org.myapp:name=AnotherService
  | 13:42:26,558 INFO  [JBossASKernel]   and supplies:
  | 13:42:26,558 INFO  [JBossASKernel]      jndi:ServiceTest/MyServiceImpl/local
  | 13:42:26,558 INFO  [JBossASKernel]      jndi:ServiceTest/MyServiceImpl/local-org.myapp.service.MyService
  | 13:42:26,558 INFO  [JBossASKernel]      Class:org.myapp.service.MyService
  | 13:42:26,558 INFO  [JBossASKernel]      jndi:ServiceTest/MyServiceImpl/remote
  | 13:42:26,558 INFO  [JBossASKernel] Installing bean(org.myapp:name=MyService) into kernel
  | 13:42:26,574 INFO  [STDOUT] Created org.myapp.service.MyServiceImpl at 2008-10-16 13:42:26.574
  | 13:42:26,590 INFO  [STDOUT] Started org.myapp.service.MyServiceImpl at 2008-10-16 13:42:26.59
  | 

So are you sure that the problem is not something else in your example?

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

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



More information about the jboss-user mailing list