View Javadoc

1   /*
2    * $Id: SimpleLifecycleManager.java 19289 2010-09-01 22:19:15Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.lifecycle;
11  
12  import org.mule.api.MuleException;
13  import org.mule.api.lifecycle.Disposable;
14  import org.mule.api.lifecycle.Initialisable;
15  import org.mule.api.lifecycle.LifecycleCallback;
16  import org.mule.api.lifecycle.LifecycleException;
17  import org.mule.api.lifecycle.Startable;
18  import org.mule.api.lifecycle.Stoppable;
19  import org.mule.lifecycle.phases.NotInLifecyclePhase;
20  
21  /**
22   * This {@link org.mule.api.lifecycle.LifecycleManager} implementation is designed to track the lifecycle of objects
23   * that support the {@link org.mule.api.lifecycle.Initialisable.PHASE_NAME}, {@link org.mule.api.lifecycle.Startable.PHASE_NAME}, 
24   * {@link org.mule.api.lifecycle.Stoppable.PHASE_NAME} and {@link org.mule.api.lifecycle.Disposable.PHASE_NAME} phases and
25   * adds convenience methods for firing these phases by callbacks.  
26   * 
27   * This is an internal class used by Mule for managing state for objects such as {@link org.mule.api.service.Service}, {@link Connector} and
28   * {@link Agent}, all of which can be controlled externally via JMX
29   * @param <O> the object type being managed by this {@link org.mule.api.lifecycle.LifecycleManager}
30   */
31  public abstract class SimpleLifecycleManager<O> extends AbstractLifecycleManager<O>
32  {
33      public SimpleLifecycleManager(String id, O object)
34      {
35          super(id, object);
36      }
37  
38      @Override
39      protected void registerTransitions()
40      {
41          //init dispose
42          addDirectTransition(NotInLifecyclePhase.PHASE_NAME, Initialisable.PHASE_NAME);
43          addDirectTransition(NotInLifecyclePhase.PHASE_NAME, Disposable.PHASE_NAME);
44          addDirectTransition(Initialisable.PHASE_NAME, Startable.PHASE_NAME);
45  
46          //If an object fails to start, the object can be left in an initialise state, but the container can be started
47          addDirectTransition(Initialisable.PHASE_NAME, Stoppable.PHASE_NAME);
48          addDirectTransition(Initialisable.PHASE_NAME, Disposable.PHASE_NAME);
49  
50          //start stop
51          addDirectTransition(Startable.PHASE_NAME, Stoppable.PHASE_NAME);
52          addDirectTransition(Stoppable.PHASE_NAME, Startable.PHASE_NAME);
53          addDirectTransition(Stoppable.PHASE_NAME, Disposable.PHASE_NAME);
54      }
55  
56      public void fireLifecycle(String phase) throws LifecycleException
57      {
58          throw new UnsupportedOperationException("SimpleLifecycleManager.fireLifecycle");
59      }
60  
61      public abstract void fireInitialisePhase(LifecycleCallback<O> callback) throws MuleException;
62  
63      public abstract void fireStartPhase(LifecycleCallback<O> callback) throws MuleException;
64  
65      public abstract void fireStopPhase(LifecycleCallback<O> callback) throws MuleException;
66  
67      public abstract void fireDisposePhase(LifecycleCallback<O> callback) throws MuleException;
68  }