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