View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.api.lifecycle;
8   
9   import org.mule.lifecycle.phases.NotInLifecyclePhase;
10  
11  /**
12   * The LifecycleManager is responsible for managing the different lifecycle phases of the server and managing the
13   * transitions between lifecycle phases.
14   *
15   * @since 3.0
16   */
17  public interface LifecycleManager
18  {
19      static final NotInLifecyclePhase NOT_IN_LIFECYCLE_PHASE = new NotInLifecyclePhase();
20  
21      /**
22       * Applies lifecycle phase to a collection of objects.
23       * @param phase that phase to execute next
24       * @throws LifecycleException if the phase is not a valid transition of does not exist on this lifecycle manager
25       */
26      void fireLifecycle(String phase) throws LifecycleException;
27  
28      /**
29       * The current phase for the lifecycle manager.  While in transition this will reflect the last completed phase not
30       * the currently executing phase, use {@link #getExecutingPhase()} to get the phase being executed.
31       * @return The current completed phase for the lifecycle manager
32       */
33      String getCurrentPhase();
34  
35      /**
36       * Returns the lifecycle phase being executed. This will be null if the lifecycle is not in transition
37       * @return the lifecycle phase being executed
38       */
39      String getExecutingPhase();
40  
41      /**
42       * Reset the lifecycle manager state back to 'not in lifecycle' phase
43       */
44      void reset();
45  
46      /**
47       * Checks that a phase has completed
48       * @param phaseName the name of the pahse to check for
49       * @return true if that phase has completed, false if the phase has not completed, or currently processing or does not exist
50       */
51      boolean isPhaseComplete(String phaseName);
52  
53      /**
54       * Will check that the phase passed in is a valid next phase for this lifecycle manager.  If the phase is not a valid next
55       * transition an exception will be thrown
56       *
57       * @param name The name of the lifecycle to validate as a valid next transition
58       * @throws IllegalStateException if the lifecycle name is not recognised or the phase is not valid for the current lifecycle state
59       */
60      void checkPhase(String name) throws IllegalStateException;
61  
62      /**
63       * Provides access to a state machine for this lifecycle manager.  components in the registry can use this to assert lifecycle
64       * rather than managing thier own lifecycle state
65       *
66       * @return A state machine for this lifecycle manager
67       *
68       * @since 3.0
69       */
70      LifecycleState getState();
71  
72      boolean isDirectTransition(String phase);
73  
74  }