View Javadoc

1   /*
2    * $Id: RegistryBrokerLifecycleManager.java 21528 2011-03-10 16:00:09Z dfeist $
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  
11  package org.mule.lifecycle;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.lifecycle.Disposable;
15  import org.mule.api.lifecycle.Initialisable;
16  import org.mule.api.lifecycle.InitialisationException;
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.api.registry.Registry;
22  import org.mule.lifecycle.phases.MuleContextDisposePhase;
23  import org.mule.lifecycle.phases.MuleContextInitialisePhase;
24  import org.mule.lifecycle.phases.MuleContextStartPhase;
25  import org.mule.lifecycle.phases.MuleContextStopPhase;
26  import org.mule.registry.AbstractRegistryBroker;
27  
28  public class RegistryBrokerLifecycleManager extends RegistryLifecycleManager
29  {
30  
31      public RegistryBrokerLifecycleManager(String id, Registry object, MuleContext muleContext)
32      {
33          super(id, object, muleContext);
34      }
35  
36      @Override
37      protected void registerPhases()
38      {
39          RegistryLifecycleCallback callback = new RegistryLifecycleCallback();
40          registerPhase(Initialisable.PHASE_NAME, new MuleContextInitialisePhase(),
41              new EmptyLifecycleCallback<AbstractRegistryBroker>());
42          registerPhase(Startable.PHASE_NAME, new MuleContextStartPhase(), callback);
43          registerPhase(Stoppable.PHASE_NAME, new MuleContextStopPhase(), callback);
44          registerPhase(Disposable.PHASE_NAME, new MuleContextDisposePhase(),
45              new EmptyLifecycleCallback<AbstractRegistryBroker>());
46      }
47  
48      public void fireInitialisePhase(LifecycleCallback<AbstractRegistryBroker> callback)
49          throws InitialisationException
50      {
51          checkPhase(Initialisable.PHASE_NAME);
52  
53          if (logger.isInfoEnabled())
54          {
55              logger.info("Initialising RegistryBroker");
56          }
57  
58          // No pre notification
59          try
60          {
61              invokePhase(Initialisable.PHASE_NAME, getLifecycleObject(), callback);
62          }
63          catch (LifecycleException e)
64          {
65              throw new InitialisationException(e, object);
66          }
67          // No post notification
68      }
69  
70      public void fireDisposePhase(LifecycleCallback<AbstractRegistryBroker> callback)
71      {
72          checkPhase(Disposable.PHASE_NAME);
73  
74          if (logger.isInfoEnabled())
75          {
76              logger.info("Disposing RegistryBroker");
77          }
78  
79          // No pre notification
80          try
81          {
82              invokePhase(Disposable.PHASE_NAME, getLifecycleObject(), callback);
83          }
84          catch (LifecycleException e)
85          {
86              logger.error("Failed to shut down registry broker cleanly: ", e);
87          }
88          // No post notification
89      }
90  
91  }