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.transport;
8   
9   import org.mule.api.MuleException;
10  import org.mule.api.lifecycle.Disposable;
11  import org.mule.api.lifecycle.Initialisable;
12  import org.mule.api.lifecycle.LifecycleCallback;
13  import org.mule.api.lifecycle.Startable;
14  import org.mule.api.lifecycle.Stoppable;
15  import org.mule.api.transport.Connector;
16  import org.mule.context.notification.ConnectionNotification;
17  import org.mule.lifecycle.SimpleLifecycleManager;
18  
19  /**
20   * Manages the lifecycle of connectors in Mule. Currently only manages the
21   * 'initialsie', 'start', 'stop' and 'dispose' phases, not the connect phase which is
22   * managed by the Retry handler
23   *
24   * @since 3.0
25   */
26  public class ConnectorLifecycleManager extends SimpleLifecycleManager<Connector>
27  {
28      public ConnectorLifecycleManager(AbstractConnector connector)
29      {
30          super(connector.getName(), connector);
31      }
32  
33      @Override
34      public void fireInitialisePhase(LifecycleCallback<Connector> callback) throws MuleException
35      {
36          checkPhase(Initialisable.PHASE_NAME);
37  
38          if (logger.isInfoEnabled())
39          {
40              logger.info("Initialising connector: " + getLifecycleObject().getName());
41          }
42  
43          // No pre notification
44          invokePhase(Initialisable.PHASE_NAME, getLifecycleObject(), callback);
45          // No post notification
46      }
47  
48      @Override
49      public void fireStartPhase(LifecycleCallback<Connector> callback) throws MuleException
50      {
51          checkPhase(Startable.PHASE_NAME);
52  
53          if (logger.isInfoEnabled())
54          {
55              logger.info("Starting connector: " + getLifecycleObject().getName());
56          }
57  
58          // No pre notification
59          invokePhase(Startable.PHASE_NAME, getLifecycleObject(), callback);
60          // No post notification
61      }
62  
63      @Override
64      public void fireStopPhase(LifecycleCallback<Connector> callback) throws MuleException
65      {
66          checkPhase(Stoppable.PHASE_NAME);
67          if (logger.isInfoEnabled())
68  
69          {
70              logger.info("Stopping connector: " + getLifecycleObject().getName());
71          }
72  
73          // No pre notification
74          invokePhase(Stoppable.PHASE_NAME, getLifecycleObject(), callback);
75          // No post notification
76      }
77  
78      @Override
79      public void fireDisposePhase(LifecycleCallback<Connector> callback) throws MuleException
80      {
81          checkPhase(Disposable.PHASE_NAME);
82  
83          if (logger.isInfoEnabled())
84          {
85              logger.info("Disposing connector: " + getLifecycleObject().getName());
86          }
87  
88          // No pre notification
89          invokePhase(Disposable.PHASE_NAME, getLifecycleObject(), callback);
90          // No post notification
91      }
92  
93      protected void fireNotification(int action)
94      {
95          getLifecycleObject().getMuleContext().fireNotification(
96              new ConnectionNotification(getLifecycleObject(), getLifecycleObject().getName(), action));
97      }
98  }