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