1 /* 2 * $Id: LifecycleManager.java 19191 2010-08-25 21:05:23Z tcarlson $ 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.api.lifecycle; 11 12 import org.mule.lifecycle.phases.NotInLifecyclePhase; 13 14 /** 15 * The LifecycleManager is responsible for managing the different lifecycle phases of the server and managing the 16 * transitions between lifecycle phases. 17 * 18 * @since 3.0 19 */ 20 public interface LifecycleManager 21 { 22 static final NotInLifecyclePhase NOT_IN_LIFECYCLE_PHASE = new NotInLifecyclePhase(); 23 24 /** 25 * Applies lifecycle phase to a collection of objects. 26 * @param phase that phase to execute next 27 * @throws LifecycleException if the phase is not a valid transition of does not exist on this lifecycle manager 28 */ 29 void fireLifecycle(String phase) throws LifecycleException; 30 31 /** 32 * The current phase for the lifecycle manager. While in transition this will reflect the last completed phase not 33 * the currently executing phase, use {@link #getExecutingPhase()} to get the phase being executed. 34 * @return The current completed phase for the lifecycle manager 35 */ 36 String getCurrentPhase(); 37 38 /** 39 * Returns the lifecycle phase being executed. This will be null if the lifecycle is not in transition 40 * @return the lifecycle phase being executed 41 */ 42 String getExecutingPhase(); 43 44 /** 45 * Reset the lifecycle manager state back to 'not in lifecycle' phase 46 */ 47 void reset(); 48 49 /** 50 * Checks that a phase has completed 51 * @param phaseName the name of the pahse to check for 52 * @return true if that phase has completed, false if the phase has not completed, or currently processing or does not exist 53 */ 54 boolean isPhaseComplete(String phaseName); 55 56 /** 57 * Will check that the phase passed in is a valid next phase for this lifecycle manager. If the phase is not a valid next 58 * transition an exception will be thrown 59 * 60 * @param name The name of the lifecycle to validate as a valid next transition 61 * @throws IllegalStateException if the lifecycle name is not recognised or the phase is not valid for the current lifecycle state 62 */ 63 void checkPhase(String name) throws IllegalStateException; 64 65 /** 66 * Provides access to a state machine for this lifecycle manager. components in the registry can use this to assert lifecycle 67 * rather than managing thier own lifecycle state 68 * 69 * @return A state machine for this lifecycle manager 70 * 71 * @since 3.0 72 */ 73 LifecycleState getState(); 74 75 boolean isDirectTransition(String phase); 76 77 }