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