KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ubermq > kernel > event > ConnectionEvent


1 package com.ubermq.kernel.event;
2
3 import com.ubermq.kernel.IConnectionInfo;
4
5 /**
6  * An event occurring on a connection that affects its
7  * state and may affect message processing.
8  */

9 public final class ConnectionEvent
10 {
11     /**
12      * The connection has initially connected.
13      */

14     public static final int CONNECTION_CONNECTED = 1;
15
16     /**
17      * The connection has been closed. This event may
18      * be preceded by an error condition event, if the
19      * closure was abnormal.
20      */

21     public static final int CONNECTION_CLOSED = 2;
22
23     /**
24      * The I/O processor has detected an IOException while
25      * interacting with the connection.
26      */

27     public static final int CONNECTION_IO_EXCEPTION = 3;
28
29     /**
30      * A reconnect handler has successfully reconnected the connection
31      * following an abnormal shutdown.
32      */

33     public static final int CONNECTION_RECONNECTED = 4;
34
35     /**
36      * The datagram processor cannot interpret the byte stream
37      * because the protocol is invalid.
38      */

39     public static final int CONNECTION_INVALID_PROTOCOL = 5;
40
41     /// PRIVATE MEMBERS
42

43     private final IConnectionInfo connection;
44     private final int event;
45
46     /**
47      * Creates a connection event related to the given
48      * connection.
49      *
50      * @param conn the connection
51      * @param event the event code, one of the CONNECTION_xxx constants.
52      */

53     public ConnectionEvent(IConnectionInfo conn,
54                            int event)
55     {
56         this.connection = conn;
57         this.event = event;
58     }
59
60     /**
61      * Returns the event code.
62      * @return an event code, one of CONNECTION_xxx.
63      */

64     public int getEventCode()
65     {
66         return event;
67     }
68
69     /**
70      * Returns true if the connection event represents a
71      * failure mode.
72      */

73     public boolean isFailure()
74     {
75         return (event == CONNECTION_IO_EXCEPTION ||
76                     event == CONNECTION_INVALID_PROTOCOL);
77     }
78
79     /**
80      * Obtains the connection reference.
81      * @return a JMS connection object. Generally, this can
82      * be cast into an IConnectionInfo, if necessary.
83      * @see com.ubermq.kernel.IConnectionInfo
84      */

85     public IConnectionInfo getConnection()
86     {
87         return connection;
88     }
89
90     public String JavaDoc toString()
91     {
92         switch(getEventCode())
93         {
94             case ConnectionEvent.CONNECTION_CLOSED:
95                 return "CONNECTION_CLOSED";
96             case ConnectionEvent.CONNECTION_CONNECTED:
97                 return "CONNECTION_CONNECTED";
98             case ConnectionEvent.CONNECTION_INVALID_PROTOCOL:
99                 return "CONNECTION_INVALID_PROTOCOL";
100             case ConnectionEvent.CONNECTION_IO_EXCEPTION:
101                 return "CONNECTION_IO_EXCEPTION";
102             case ConnectionEvent.CONNECTION_RECONNECTED:
103                 return "CONNECTION_RECONNECTED";
104             default:
105                 return String.valueOf(getEventCode());
106         }
107     }
108 }
109
110
Popular Tags