Coverage Report - org.mule.config.spring.SpringRegistryLifecycleManager
 
Classes in this File Line Coverage Branch Coverage Complexity
SpringRegistryLifecycleManager
0%
0/8
N/A
0
SpringRegistryLifecycleManager$SpringContextDisposePhase
0%
0/7
N/A
0
SpringRegistryLifecycleManager$SpringContextInitialisePhase
0%
0/5
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.config.spring;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.lifecycle.Disposable;
 11  
 import org.mule.api.lifecycle.Initialisable;
 12  
 import org.mule.api.lifecycle.LifecycleException;
 13  
 import org.mule.api.lifecycle.LifecyclePhase;
 14  
 import org.mule.api.lifecycle.Startable;
 15  
 import org.mule.api.lifecycle.Stoppable;
 16  
 import org.mule.api.registry.Registry;
 17  
 import org.mule.lifecycle.EmptyLifecycleCallback;
 18  
 import org.mule.lifecycle.RegistryLifecycleManager;
 19  
 import org.mule.lifecycle.phases.ContainerManagedLifecyclePhase;
 20  
 import org.mule.lifecycle.phases.MuleContextStartPhase;
 21  
 import org.mule.lifecycle.phases.MuleContextStopPhase;
 22  
 import org.mule.lifecycle.phases.NotInLifecyclePhase;
 23  
 import org.mule.registry.AbstractRegistryBroker;
 24  
 
 25  
 public class SpringRegistryLifecycleManager extends RegistryLifecycleManager
 26  
 {
 27  
     public SpringRegistryLifecycleManager(String id, Registry object, MuleContext muleContext)
 28  
     {
 29  0
         super(id, object, muleContext);
 30  0
     }
 31  
 
 32  
     protected void registerPhases()
 33  
     {
 34  0
         registerPhase(NotInLifecyclePhase.PHASE_NAME, NOT_IN_LIFECYCLE_PHASE,
 35  
             new EmptyLifecycleCallback<AbstractRegistryBroker>());
 36  0
         registerPhase(Initialisable.PHASE_NAME, new SpringContextInitialisePhase());
 37  0
         registerPhase(Startable.PHASE_NAME, new MuleContextStartPhase(),
 38  
             new EmptyLifecycleCallback<AbstractRegistryBroker>());
 39  0
         registerPhase(Stoppable.PHASE_NAME, new MuleContextStopPhase(),
 40  
             new EmptyLifecycleCallback<AbstractRegistryBroker>());
 41  0
         registerPhase(Disposable.PHASE_NAME, new SpringContextDisposePhase());
 42  0
     }
 43  
 
 44  
     // ///////////////////////////////////////////////////////////////////////////////////
 45  
     // Spring custom lifecycle phases
 46  
     // ///////////////////////////////////////////////////////////////////////////////////
 47  
 
 48  
     /**
 49  
      * A lifecycle phase that will delegate any lifecycle invocations to a container
 50  
      * such as Spring or Guice
 51  
      */
 52  
     class SpringContextInitialisePhase extends ContainerManagedLifecyclePhase
 53  
     {
 54  
         public SpringContextInitialisePhase()
 55  0
         {
 56  0
             super(Initialisable.PHASE_NAME, Initialisable.class, Disposable.PHASE_NAME);
 57  0
             registerSupportedPhase(NotInLifecyclePhase.PHASE_NAME);
 58  0
         }
 59  
 
 60  
         /**
 61  
          * We don't need to apply any lifecycle here since Spring manages that for us
 62  
          * 
 63  
          * @param o the object apply lifecycle to. This parameter will be ignorred
 64  
          * @throws LifecycleException never thrown
 65  
          */
 66  
         @Override
 67  
         public void applyLifecycle(Object o) throws LifecycleException
 68  
         {
 69  
             // Spring starts initialised, do nothing here
 70  0
         }
 71  
     }
 72  
 
 73  
     /**
 74  
      * A lifecycle phase that will delegate to the
 75  
      * {@link org.mule.config.spring.SpringRegistry#doDispose()} method which in turn
 76  
      * will destroy the application context managed by this registry
 77  
      */
 78  
     class SpringContextDisposePhase extends ContainerManagedLifecyclePhase
 79  
     {
 80  
         public SpringContextDisposePhase()
 81  0
         {
 82  0
             super(Disposable.PHASE_NAME, Disposable.class, Initialisable.PHASE_NAME);
 83  0
             registerSupportedPhase(NotInLifecyclePhase.PHASE_NAME);
 84  
             // You can dispose from all phases
 85  0
             registerSupportedPhase(LifecyclePhase.ALL_PHASES);
 86  0
         }
 87  
 
 88  
         @Override
 89  
         public void applyLifecycle(Object o) throws LifecycleException
 90  
         {
 91  0
             ((SpringRegistry) o).doDispose();
 92  0
         }
 93  
     }
 94  
 
 95  
 }