01: /*
02: * $Id: ConnectionNotification.java 10489 2008-01-23 17:53:38Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.context.notification;
12:
13: import org.mule.api.context.notification.ServerNotification;
14: import org.mule.api.transport.Connectable;
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 ServerNotification {
21: /**
22: * Serial version
23: */
24: private static final long serialVersionUID = -6455441938378523145L;
25: public static final int CONNECTION_CONNECTED = CONNECTION_EVENT_ACTION_START_RANGE + 1;
26: public static final int CONNECTION_FAILED = CONNECTION_EVENT_ACTION_START_RANGE + 2;
27: public static final int CONNECTION_DISCONNECTED = CONNECTION_EVENT_ACTION_START_RANGE + 3;
28:
29: static {
30: registerAction("connected", CONNECTION_CONNECTED);
31: registerAction("connect failed", CONNECTION_FAILED);
32: registerAction("disconnected", CONNECTION_DISCONNECTED);
33: }
34:
35: public ConnectionNotification(Connectable resource,
36: String identifier, int action) {
37: super (resource, action);
38: resourceIdentifier = identifier;
39: }
40:
41: protected String getPayloadToString() {
42: if (source instanceof Connectable) {
43: return ((Connectable) source).getConnectionDescription();
44: }
45: return source.toString();
46: }
47:
48: public String getType() {
49: if (action == CONNECTION_DISCONNECTED) {
50: return TYPE_WARNING;
51: }
52: if (action == CONNECTION_FAILED) {
53: return TYPE_ERROR;
54: }
55: return TYPE_INFO;
56: }
57:
58: }
|