View Javadoc

1   /*
2    * $Id: ConnectionNotification.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.impl.internal.notifications;
12  
13  import org.mule.umo.manager.UMOServerNotification;
14  import org.mule.umo.provider.UMOConnectable;
15  
16  /**
17   * Is fired by a connector when a connection is made, or disconnected of the
18   * connection fails.
19   */
20  public class ConnectionNotification extends UMOServerNotification
21  {
22      /**
23       * Serial version
24       */
25      private static final long serialVersionUID = -6455441938378523145L;
26      public static final int CONNECTION_CONNECTED = CONNECTION_EVENT_ACTION_START_RANGE + 1;
27      public static final int CONNECTION_FAILED = CONNECTION_EVENT_ACTION_START_RANGE + 2;
28      public static final int CONNECTION_DISCONNECTED = CONNECTION_EVENT_ACTION_START_RANGE + 3;
29  
30      private static final transient String[] ACTIONS = new String[]{"connected", "connect failed",
31          "disconnected"};
32  
33      public ConnectionNotification(UMOConnectable resource, String identifier, int action)
34      {
35          super(resource, action);
36          resourceIdentifier = identifier;
37      }
38  
39      protected String getPayloadToString()
40      {
41          if (source instanceof UMOConnectable)
42          {
43              return ((UMOConnectable) source).getConnectionDescription();
44          }
45          return source.toString();
46      }
47  
48      protected String getActionName(int action)
49      {
50          int i = action - CONNECTION_EVENT_ACTION_START_RANGE;
51          if (i - 1 > ACTIONS.length)
52          {
53              return String.valueOf(action);
54          }
55          return ACTIONS[i - 1];
56      }
57  
58      public String getType()
59      {
60          if (action == CONNECTION_DISCONNECTED)
61          {
62              return TYPE_WARNING;
63          }
64          if (action == CONNECTION_FAILED)
65          {
66              return TYPE_ERROR;
67          }
68          return TYPE_INFO;
69      }
70  
71  }