1 Reply Latest reply on Mar 30, 2010 3:32 PM by Ales Justin

    When is a bean moved to START state?

    jaikiran pai Master

      This question relates to a thread in JBoss AS forum where a user is running into error trying to setup a dependency between a web application and an EJB http://community.jboss.org/message/534413#534413

       

      Here's a brief overview:

       

      1) A web app adds a < depends> in its jboss-web.xml to mark a dependency on a EJB container (which is a MC bean). The web app internally looks up the bean from JNDI and hence this dependency.

      2) The EJB container (MC bean) has a "start()" lifecycle callback method (among other similar lifecycle callbacks).

      3) In its start(), the EJB container *first* deploys some other MC beans and *then* binds the EJB proxies to JNDI.

       

      When EJB container deploys some other MC beans in step#3, it results in MC resolving dependencies of other unrelated beans (known issue). Incidentally, while doing so, MC considers that the EJB container MC bean has been started even though the start() lifecycle method hasn't yet finished. MC then goes on to push the web-app to its next state considering the dependency has been fulfilled (which hasn't yet been fulfilled because the JNDI bindings in step#3 are not yet done). This results in the web-app running into NameNotFoundExceptions.

       

      Does MC set the state to START even before the start() lifecycle successfully completes?

        • 1. Re: When is a bean moved to START state?
          Ales Justin Master
          Does MC set the state to START even before the start() lifecycle successfully completes?

          No, after -- see AbstractController::incrementState.

           

                try
                {
                   install(context, fromState, toState);
          
                   fromContexts.remove(context);
                   Controller toController = context.getController();
                   Set<ControllerContext> toContexts = toController.getContextsByState(toState);
                   toContexts.add(context);
                   context.setState(toState); // HERE