View Javadoc

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