Coverage Report - org.mule.processor.SedaStageLifecycleManager
 
Classes in this File Line Coverage Branch Coverage Complexity
SedaStageLifecycleManager
0%
0/45
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.processor;
 8  
 
 9  
 import org.mule.api.MuleException;
 10  
 import org.mule.api.lifecycle.Disposable;
 11  
 import org.mule.api.lifecycle.Initialisable;
 12  
 import org.mule.api.lifecycle.InitialisationException;
 13  
 import org.mule.api.lifecycle.LifecycleCallback;
 14  
 import org.mule.api.lifecycle.LifecycleException;
 15  
 import org.mule.api.lifecycle.Startable;
 16  
 import org.mule.api.lifecycle.Stoppable;
 17  
 import org.mule.config.i18n.CoreMessages;
 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 SedaStageLifecycleManager extends SimpleLifecycleManager<SedaStageInterceptingMessageProcessor>
 30  
 {
 31  
     /**
 32  
      * logger used by this class
 33  
      */
 34  0
     protected transient final Log logger = LogFactory.getLog(SedaStageLifecycleManager.class);
 35  
 
 36  
     public SedaStageLifecycleManager(String name, SedaStageInterceptingMessageProcessor sedaStage)
 37  
     {
 38  0
         super(name, sedaStage);
 39  0
     }
 40  
 
 41  
     @Override
 42  
     protected void registerTransitions()
 43  
     {
 44  0
         super.registerTransitions();
 45  
 
 46  
         //pause resume
 47  0
         addDirectTransition(Startable.PHASE_NAME, Pausable.PHASE_NAME);
 48  
         //Note that 'Resume' state gets removed and the current state is set to 'start'. See {@link #notifyTransition}
 49  0
         addDirectTransition(Pausable.PHASE_NAME, Resumable.PHASE_NAME);
 50  0
         addDirectTransition(Pausable.PHASE_NAME, Stoppable.PHASE_NAME);
 51  0
     }
 52  
 
 53  
     @Override
 54  
     protected void notifyTransition(String destinationPhase)
 55  
     {
 56  0
         if (destinationPhase.equals(Resumable.PHASE_NAME))
 57  
         {
 58  
             //Revert back to start phase
 59  0
             completedPhases.remove(Resumable.PHASE_NAME);
 60  0
             completedPhases.remove(Pausable.PHASE_NAME);
 61  0
             setCurrentPhase(Startable.PHASE_NAME);
 62  
         }
 63  0
     }
 64  
 
 65  
     @Override
 66  
     public void fireInitialisePhase(LifecycleCallback<SedaStageInterceptingMessageProcessor> callback) throws InitialisationException
 67  
     {
 68  0
         checkPhase(Initialisable.PHASE_NAME);
 69  0
         if(logger.isInfoEnabled()) logger.info("Initialising service: " + lifecycleManagerId);
 70  
         try
 71  
         {
 72  0
             invokePhase(Initialisable.PHASE_NAME, getLifecycleObject(), callback);
 73  
         }
 74  0
         catch (InitialisationException e)
 75  
         {
 76  0
             throw e;
 77  
         }
 78  0
         catch (LifecycleException e)
 79  
         {
 80  0
             throw new InitialisationException(e, (Initialisable) object);
 81  0
         }
 82  0
     }
 83  
 
 84  
     @Override
 85  
     public void fireStartPhase(LifecycleCallback<SedaStageInterceptingMessageProcessor> callback) throws MuleException
 86  
     {
 87  0
         checkPhase(Startable.PHASE_NAME);
 88  0
         if(logger.isInfoEnabled()) logger.info("Starting service: " + lifecycleManagerId);
 89  0
         invokePhase(Startable.PHASE_NAME, getLifecycleObject(), callback);
 90  0
     }
 91  
 
 92  
     public void firePausePhase(LifecycleCallback<SedaStageInterceptingMessageProcessor> callback) throws MuleException
 93  
     {
 94  0
         checkPhase(Pausable.PHASE_NAME);
 95  0
         if(logger.isInfoEnabled()) logger.info("Pausing service: " + lifecycleManagerId);
 96  0
         invokePhase(Pausable.PHASE_NAME, getLifecycleObject(), callback);
 97  0
     }
 98  
 
 99  
     public void fireResumePhase(LifecycleCallback<SedaStageInterceptingMessageProcessor> callback) throws MuleException
 100  
     {
 101  0
         checkPhase(Resumable.PHASE_NAME);
 102  0
         if(logger.isInfoEnabled()) logger.info("Resuming service: " + lifecycleManagerId);
 103  0
         invokePhase(Resumable.PHASE_NAME, getLifecycleObject(), callback);
 104  0
     }
 105  
 
 106  
     @Override
 107  
     public void fireStopPhase(LifecycleCallback<SedaStageInterceptingMessageProcessor> callback) throws MuleException
 108  
     {
 109  0
         checkPhase(Stoppable.PHASE_NAME);
 110  0
         if(logger.isInfoEnabled()) logger.info("Stopping service: " + lifecycleManagerId);
 111  0
         invokePhase(Stoppable.PHASE_NAME, getLifecycleObject(), callback);
 112  0
     }
 113  
 
 114  
     @Override
 115  
     public void fireDisposePhase(LifecycleCallback<SedaStageInterceptingMessageProcessor> callback)
 116  
     {
 117  0
         checkPhase(Disposable.PHASE_NAME);
 118  0
         if(logger.isInfoEnabled()) logger.info("Disposing service: " + lifecycleManagerId);
 119  
         try
 120  
         {
 121  0
             invokePhase(Disposable.PHASE_NAME, getLifecycleObject(), callback);
 122  
         }
 123  0
         catch (LifecycleException e)
 124  
         {
 125  0
             logger.warn(CoreMessages.failedToDispose(lifecycleManagerId), e);
 126  0
         }
 127  0
     }
 128  
 
 129  
 }