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