6 Replies Latest reply on Feb 22, 2008 9:07 PM by dmlloyd

    Service validation

    dmlloyd

      Say I've got a service that has some dependencies that need to be injected before it can start up.

      My first question is, when do the dependencies get injected, with relation to the service lifecycle methods? And secondly, how can I, within my service bean, validate that all the required dependencies are met? If there's a problem, can I e.g. throw an exception from my start() method to prevent the service from being started, or is there a "cleaner" way to validate dependencies?

      Thanks, sorry if these are dumb questions but I can't seem to find anything in the user manual covering these topics.

        • 1. Re: Service validation
          alesj

           

          "david.lloyd@jboss.com" wrote:
          Say I've got a service that has some dependencies that need to be injected before it can start up.
          My first question is, when do the dependencies get injected, with relation to the service lifecycle methods?

          It again depends where you want to inject. ;-)

          Lifecycle order:

          ControllerState.NOT_INSTALLED
          ControllerState.PRE_INSTALL
          ControllerState.DESCRIBED
          ControllerState.INSTANTIATED
          ControllerState.CONFIGURED
          ControllerState.CREATE
          ControllerState.START
          ControllerState.INSTALLED

          Constructor injection happens as Instantiated.
          Property injection at Configured.
          Create method invocation (+ parameter injections) at create. :-)
          Start at ...

          And I've just added that installs can be applied at any state:
          - http://jira.jboss.com/jira/browse/JBMICROCONT-242

          "david.lloyd@jboss.com" wrote:
          And secondly, how can I, within my service bean, validate that all the required dependencies are met?

          You don't need to.
          If you define your dependencies right (and it's a very pluggable system aka defining you own dependencies is trivial), MC is gonna take care that they are all met, or the service won't move fwd.

          "david.lloyd@jboss.com" wrote:
          If there's a problem, can I e.g. throw an exception from my start() method to prevent the service from being started, or is there a "cleaner" way to validate dependencies?

          If whatever exception is thrown during any state of bean/service lifecycle, the MC is gonna put this context into error state.
          See this discussion for more details:
          - http://www.jboss.org/index.html?module=bb&op=viewtopic&t=130374&start=0
          But you can manually move service in MC.
          And perhaps if the validation at that point is negative you move your service a (few) step(s) back. And proceed when you expect all is OK.
          It's again all about what is valid for you.

          • 2. Re: Service validation
            dmlloyd

            OK, then I think I'm confused - how does the controller state lifecycle relate to the service lifecycle? The service lifecycle seems to define four trasitions - create, start, stop, and destory. But the controller can be in 8 different states.

            • 3. Re: Service validation
              alesj

               

              "david.lloyd@jboss.com" wrote:
              OK, then I think I'm confused - how does the controller state lifecycle relate to the service lifecycle? The service lifecycle seems to define four trasitions - create, start, stop, and destory. But the controller can be in 8 different states.

              We have more fine grained states than the usual lifecycles. ;-)
              And what you call stop and destroy are respectively start and create on the way 'back', at uninstall.

              What are usually the states where the services get instantiated and configured?


              • 4. Re: Service validation
                dmlloyd

                 

                "alesj" wrote:
                We have more fine grained states than the usual lifecycles. ;-)
                And what you call stop and destroy are respectively start and create on the way 'back', at uninstall.


                Yeah, I figured out that much. So the lifecycle methods described in http://tinyurl.com/2qlxsq (13.3 of the user manual) represent transitions between three states in each direction. Which of the 8 controller states does each of the three states correspond to? Or are they completely independent and unrelated (and thus am I just confusing myself)?


                • 5. Re: Service validation
                  alesj

                  Which three states you have in mind?

                  I'll do a simple explanation of what each state does, or better, what each action corresponding to state does:

                  In install phase:
                  NOT_INSTALLED - initial state
                  PRE_INSTALL - initialize scoped metadata, check for hierarchy of Controllers
                  DESCRIBED - add aop dependencies, handle IoC annotations
                  INSTANTIATED - instantiate pojo
                  CONFIGURED - configure pojo's propertys with values
                  CREATE - invoke create method (if exists)
                  START - invoke start method (if exists)
                  INSTALLED - register bean into registry, apply supplies

                  In uninstall phase:
                  INSTALLED - unregister bean from registry, clear supplies
                  START - invoke stop method (if exists)
                  CREATE - invoke destroy method (if exists)
                  CONFIGURED - nullify pojo's propertys
                  INSTANTIATED - nullify target pojo
                  DESCRIBED - clear IoC annotations
                  PRE_INSTALL - clear any Controller hierarchy (if applied) and scoped metadata
                  NOT_INSTALLED - end state

                  And actually there are more than 8 Controller states, to confuse you even more. :-)
                  But the one's mentioned are relevant for the POJOs. ;-)

                  • 6. Re: Service validation
                    dmlloyd

                    Ah - I get it! I was confused after all. And in fact, re-reading the lifecycle chapter, you do explain this a bit.

                    OK, this totally makes sense now. Sorry for the dumb questions.