[jboss-user] [Microcontainer] - Re: Service validation

alesj do-not-reply at jboss.com
Fri Feb 22 16:22:20 EST 2008


"david.lloyd at 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 at 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 at 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. 

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

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



More information about the jboss-user mailing list