Version 6

    Service Lifecycle and Dependencies

     

    Service Lifecycle

    JBoss recognises four special operations on your service's management interface.

    • create()

      - the service should do any setup and not reference another service

    • start()

      - the service can reference other services

    • stop()

      - destroys links to other services

    • destroy()

      - destroys itself

    You will notice it is two phase. In most circumstances only one phase is required, usually

    start

    ,

    stop

    to do work on other services, e.g. binding/unbinding to jndi.

    NOTE: you do not have to implement all lifecyle operations

     

    Dependencies

    With the lifecycle operations implementated, you can setup dependencies between services.

    i.e. JBoss ensures that the

    create()

    operation on the dependee service is invoked before the dependent service.

     

    e.g. if the

    DatabaseService

    depends upon the

    TransactionService

    , the order of the operations at deployment will be:

    TransactionService.create()
    DBService.create()
    TransactionService.start()
    DBService.start()
    

    and at undeployment in the reverse order

    DBService.stop()
    TransactionService.stop()
    DBService.destroy()
    TransactionService.destroy()
    

     

    Notification based Dependencies

     

    There are cases where it is desirable to associate the lifecycle of an MBean

    with the the reception of certain JMX Notifications. Consider, for example, a service that needs to be started only after the reception of a notification indicating that the Tomcat connectors are active. For this kind of dependencies

    you can use the BarrierController service.