Coverage Report - org.mule.construct.FlowConstructLifecycleManager
 
Classes in this File Line Coverage Branch Coverage Complexity
FlowConstructLifecycleManager
0%
0/45
0%
0/14
0
 
 1  
 /*
 2  
  * $Id: FlowConstructLifecycleManager.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.construct;
 11  
 
 12  
 import org.mule.api.MuleException;
 13  
 import org.mule.api.construct.FlowConstruct;
 14  
 import org.mule.api.lifecycle.Disposable;
 15  
 import org.mule.api.lifecycle.Initialisable;
 16  
 import org.mule.api.lifecycle.LifecycleCallback;
 17  
 import org.mule.api.lifecycle.Startable;
 18  
 import org.mule.api.lifecycle.Stoppable;
 19  
 import org.mule.context.notification.FlowConstructNotification;
 20  
 import org.mule.lifecycle.SimpleLifecycleManager;
 21  
 import org.mule.service.Pausable;
 22  
 import org.mule.service.Resumable;
 23  
 
 24  
 import org.apache.commons.logging.Log;
 25  
 import org.apache.commons.logging.LogFactory;
 26  
 
 27  
 /**
 28  
  * The lifecycle manager responsible for managing lifecycle transitions for a Mule service.  The Mule service adds some additional
 29  
  * states, namely pause and resume.  The lifecycle manager manages lifecycle notifications and logging as well.
 30  
  */
 31  
 public class FlowConstructLifecycleManager extends SimpleLifecycleManager<FlowConstruct>
 32  
 {
 33  
     /**
 34  
      * logger used by this class
 35  
      */
 36  0
     protected transient final Log logger = LogFactory.getLog(FlowConstructLifecycleManager.class);
 37  
 
 38  
 
 39  
     public FlowConstructLifecycleManager(FlowConstruct flowConstruct)
 40  
     {
 41  0
         super(flowConstruct.getName(), flowConstruct);
 42  0
     }
 43  
 
 44  
     @Override
 45  
     protected void registerTransitions()
 46  
     {
 47  0
         super.registerTransitions();
 48  
 
 49  
         //pause resume
 50  0
         addDirectTransition(Startable.PHASE_NAME, Pausable.PHASE_NAME);
 51  
         //Note that 'Resume' state gets removed and the current state is set to 'start'. See {@link #notifyTransition}
 52  0
         addDirectTransition(Pausable.PHASE_NAME, Resumable.PHASE_NAME);
 53  0
         addDirectTransition(Pausable.PHASE_NAME, Stoppable.PHASE_NAME);
 54  0
     }
 55  
 
 56  
     @Override
 57  
     protected void notifyTransition(String currentPhase)
 58  
     {
 59  0
         if(currentPhase.equals(Resumable.PHASE_NAME))
 60  
         {
 61  
             //Revert back to start phase
 62  0
             completedPhases.remove(Resumable.PHASE_NAME);
 63  0
             completedPhases.remove(Pausable.PHASE_NAME);
 64  0
             setCurrentPhase(Startable.PHASE_NAME);
 65  
         }
 66  0
     }
 67  
 
 68  
     @Override
 69  
     public void fireInitialisePhase(LifecycleCallback<FlowConstruct> callback) throws MuleException
 70  
     {
 71  0
         checkPhase(Initialisable.PHASE_NAME);
 72  
         //TODO No pre notification
 73  0
         if(logger.isInfoEnabled()) logger.info("Initialising flow: " + getLifecycleObject().getName());
 74  0
         invokePhase(Initialisable.PHASE_NAME, getLifecycleObject(), callback);
 75  0
         fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_INITIALISED);
 76  0
     }
 77  
 
 78  
 
 79  
     @Override
 80  
     public void fireStartPhase(LifecycleCallback<FlowConstruct> callback) throws MuleException
 81  
     {
 82  0
         checkPhase(Startable.PHASE_NAME);
 83  0
         if(logger.isInfoEnabled()) logger.info("Starting flow: " + getLifecycleObject().getName());
 84  
         //TODO No pre notification
 85  0
         invokePhase(Startable.PHASE_NAME, getLifecycleObject(), callback);
 86  0
         fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_STARTED);
 87  0
     }
 88  
 
 89  
 
 90  
     public void firePausePhase(LifecycleCallback<FlowConstruct> callback) throws MuleException
 91  
     {
 92  0
         checkPhase(Pausable.PHASE_NAME);
 93  0
         if(logger.isInfoEnabled()) logger.info("Pausing flow: " + getLifecycleObject().getName());
 94  
 
 95  
         //TODO No pre notification
 96  0
         invokePhase(Pausable.PHASE_NAME, getLifecycleObject(), callback);
 97  0
         fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_PAUSED);
 98  0
     }
 99  
 
 100  
     public void fireResumePhase(LifecycleCallback<FlowConstruct> callback) throws MuleException
 101  
     {
 102  0
         checkPhase(Resumable.PHASE_NAME);
 103  0
         if(logger.isInfoEnabled()) logger.info("Resuming flow: " + getLifecycleObject().getName());
 104  
         //TODO No pre notification
 105  0
         invokePhase(Resumable.PHASE_NAME, getLifecycleObject(), callback);
 106  0
         fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_RESUMED);
 107  0
     }
 108  
 
 109  
     @Override
 110  
     public void fireStopPhase(LifecycleCallback<FlowConstruct> callback) throws MuleException
 111  
     {
 112  0
         checkPhase(Stoppable.PHASE_NAME);
 113  0
         if(logger.isInfoEnabled()) logger.info("Stopping flow: " + getLifecycleObject().getName());
 114  
         //TODO No pre notification
 115  0
         invokePhase(Stoppable.PHASE_NAME, getLifecycleObject(), callback);
 116  0
         fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_STOPPED);
 117  0
     }
 118  
 
 119  
     @Override
 120  
     public void fireDisposePhase(LifecycleCallback<FlowConstruct> callback) throws MuleException
 121  
     {
 122  0
         checkPhase(Disposable.PHASE_NAME);
 123  0
         if(logger.isInfoEnabled()) logger.info("Disposing flow: " + getLifecycleObject().getName());
 124  
         //TODO No pre notification
 125  0
         invokePhase(Disposable.PHASE_NAME, getLifecycleObject(), callback);
 126  0
         fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_DISPOSED);
 127  0
     }
 128  
 
 129  
     protected void fireNotification(int action)
 130  
     {
 131  0
         getLifecycleObject().getMuleContext().fireNotification(new FlowConstructNotification(getLifecycleObject(), action));
 132  0
     }
 133  
 }