Coverage Report - org.mule.lifecycle.MuleContextLifecycleManager
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleContextLifecycleManager
0%
0/27
N/A
0
MuleContextLifecycleManager$MuleContextLifecycleCallback
0%
0/3
N/A
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.lifecycle;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.MuleException;
 11  
 import org.mule.api.context.MuleContextAware;
 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.LifecycleException;
 16  
 import org.mule.api.lifecycle.Startable;
 17  
 import org.mule.api.lifecycle.Stoppable;
 18  
 import org.mule.lifecycle.phases.NotInLifecyclePhase;
 19  
 
 20  
 /**
 21  
  * This is a specialized class that extends {@link RegistryLifecycleManager} and will
 22  
  * invoke lifecycle on the registry instance for the MuleContext.  This class must only be used by the MuleContext.
 23  
  */
 24  
 public class MuleContextLifecycleManager extends AbstractLifecycleManager<MuleContext> implements MuleContextAware
 25  
 {
 26  
 
 27  
     private MuleContext muleContext;
 28  
 
 29  0
     private MuleContextLifecycleCallback callback = new MuleContextLifecycleCallback();
 30  
 
 31  
     public MuleContextLifecycleManager()
 32  
     {
 33  
         //We cannot pass in a MuleContext on creation since the context is not actually created when this object is needed
 34  0
         super("MuleContext", null);
 35  0
     }
 36  
 
 37  
     @Override
 38  
     protected void registerTransitions()
 39  
     {
 40  
         //init dispose
 41  0
         addDirectTransition(NotInLifecyclePhase.PHASE_NAME, Initialisable.PHASE_NAME);
 42  0
         addDirectTransition(NotInLifecyclePhase.PHASE_NAME, Disposable.PHASE_NAME);
 43  0
         addDirectTransition(Initialisable.PHASE_NAME, Startable.PHASE_NAME);
 44  0
         addDirectTransition(Initialisable.PHASE_NAME, Disposable.PHASE_NAME);
 45  
 
 46  
         //start stop
 47  0
         addDirectTransition(Startable.PHASE_NAME, Stoppable.PHASE_NAME);
 48  0
         addDirectTransition(Stoppable.PHASE_NAME, Startable.PHASE_NAME);
 49  0
         addDirectTransition(Stoppable.PHASE_NAME, Disposable.PHASE_NAME);
 50  0
     }
 51  
 
 52  
     public void setMuleContext(MuleContext context)
 53  
     {
 54  0
         this.muleContext = context;
 55  0
         this.object = muleContext;
 56  0
     }
 57  
 
 58  
     public void fireLifecycle(String destinationPhase) throws LifecycleException
 59  
     {
 60  0
         checkPhase(destinationPhase);
 61  0
         invokePhase(destinationPhase, object, callback);
 62  0
     }
 63  
 
 64  
      protected void invokePhase(String phase, Object object, LifecycleCallback callback) throws LifecycleException
 65  
     {
 66  
         try
 67  
         {
 68  0
             setExecutingPhase(phase);
 69  0
             callback.onTransition(phase, object);
 70  0
             setCurrentPhase(phase);
 71  
         }
 72  0
         catch (LifecycleException e)
 73  
         {
 74  0
             throw e;
 75  
         }
 76  0
         catch (MuleException e)
 77  
         {
 78  0
             throw new LifecycleException(e, this);
 79  
         }
 80  
         finally
 81  
         {
 82  0
             setExecutingPhase(null);
 83  0
         }
 84  
 
 85  0
     }
 86  
 
 87  0
     class MuleContextLifecycleCallback implements LifecycleCallback<MuleContext>
 88  
     {
 89  
         public void onTransition(String phaseName, MuleContext muleContext) throws MuleException
 90  
         {
 91  0
             muleContext.getRegistry().fireLifecycle(phaseName);
 92  0
         }
 93  
     }
 94  
 }