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.context.notification;
8   
9   import org.mule.api.context.notification.ServerNotification;
10  import org.mule.api.transport.Connectable;
11  
12  /**
13   * Is fired by a connector when a connection is made or disconnected.
14   * A disconnection can be caused by network failure, JMX, or the server shutting down.
15   */
16  public class ConnectionNotification extends ServerNotification
17  {
18      /**
19       * Serial version
20       */
21      private static final long serialVersionUID = -6455441938378523145L;
22      public static final int CONNECTION_CONNECTED = CONNECTION_EVENT_ACTION_START_RANGE + 1;
23      public static final int CONNECTION_FAILED = CONNECTION_EVENT_ACTION_START_RANGE + 2;
24      public static final int CONNECTION_DISCONNECTED = CONNECTION_EVENT_ACTION_START_RANGE + 3;
25  
26      static {
27          registerAction("connected", CONNECTION_CONNECTED);
28          registerAction("connect failed", CONNECTION_FAILED);
29          registerAction("disconnected", CONNECTION_DISCONNECTED);
30      }
31  
32      public ConnectionNotification(Connectable resource, String identifier, int action)
33      {
34          super((resource == null ? identifier : resource.getConnectionDescription()), action);
35          resourceIdentifier = identifier;
36      }
37  
38      @Override
39      protected String getPayloadToString()
40      {
41          return source.toString();
42      }
43  
44      @Override
45      public String getType()
46      {
47          if (action == CONNECTION_DISCONNECTED)
48          {
49              return TYPE_WARNING;
50          }
51          if (action == CONNECTION_FAILED)
52          {
53              return TYPE_ERROR;
54          }
55          return TYPE_INFO;
56      }
57  
58  }