KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > remote > JMXConnectionNotification


1 /*
2  * @(#)JMXConnectionNotification.java 1.18 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8
9 package javax.management.remote;
10
11 import javax.management.Notification JavaDoc;
12 import javax.management.ObjectName JavaDoc;
13
14 /**
15  * <p>Notification emitted when a client connection is opened or
16  * closed or when notifications are lost. These notifications are
17  * sent by connector servers (instances of {@link JMXConnectorServer})
18  * and by connector clients (instances of {@link JMXConnector}). For
19  * certain connectors, a session can consist of a sequence of
20  * connections. Connection-opened and connection-closed notifications
21  * will be sent for each one.</p>
22  *
23  * <p>The notification type is one of the following:</p>
24  *
25  * <table>
26  *
27  * <tr>
28  * <th align=left>Type</th>
29  * <th align=left>Meaning</th>
30  * </tr>
31  *
32  * <tr>
33  * <td><code>jmx.remote.connection.opened</code></td>
34  * <td>A new client connection has been opened.</td>
35  * </tr>
36  *
37  * <tr>
38  * <td><code>jmx.remote.connection.closed</code></td>
39  * <td>A client connection has been closed.</td>
40  * </tr>
41  *
42  * <tr>
43  * <td><code>jmx.remote.connection.failed</code></td>
44  * <td>A client connection has failed unexpectedly.</td>
45  * </tr>
46  *
47  * <tr>
48  * <td><code>jmx.remote.connection.notifs.lost</code></td>
49  * <td>A client connection has potentially lost notifications. This
50  * notification only appears on the client side.</td>
51  * </tr>
52  * </table>
53  *
54  * <p>The <code>timeStamp</code> of the notification is a time value
55  * (consistent with {@link System#currentTimeMillis()}) indicating
56  * when the notification was constructed.</p>
57  *
58  * @since 1.5
59  * @since.unbundled 1.0
60  */

61 public class JMXConnectionNotification extends Notification JavaDoc {
62
63     private static final long serialVersionUID = -2331308725952627538L;
64
65     /**
66      * <p>Notification type string for a connection-opened notification.
67      */

68     public static final String JavaDoc OPENED = "jmx.remote.connection.opened";
69
70     /**
71      * <p>Notification type string for a connection-closed notification.
72      */

73     public static final String JavaDoc CLOSED = "jmx.remote.connection.closed";
74
75     /**
76      * <p>Notification type string for a connection-failed notification.
77      */

78     public static final String JavaDoc FAILED = "jmx.remote.connection.failed";
79
80     /**
81      * <p>Notification type string for a connection that has possibly
82      * lost notifications.</p>
83      */

84     public static final String JavaDoc NOTIFS_LOST =
85     "jmx.remote.connection.notifs.lost";
86
87     /**
88      * Constructs a new connection notification. The {@link
89      * #getSource() source} of the notification depends on whether it
90      * is being sent by a connector server or a connector client:
91      *
92      * <ul>
93      *
94      * <li>For a connector server, if it is registered in an MBean
95      * server, the source is the {@link ObjectName} under which it is
96      * registered. Otherwise, it is a reference to the connector
97      * server object itself, an instance of a subclass of {@link
98      * JMXConnectorServer}.
99      *
100      * <li>For a connector client, the source is a reference to the
101      * connector client object, an instance of a class implementing
102      * {@link JMXConnector}.
103      *
104      * </ul>
105      *
106      * @param type the type of the notification. This is usually one
107      * of the constants {@link #OPENED}, {@link #CLOSED}, {@link
108      * #FAILED}, {@link #NOTIFS_LOST}. It is not an error for it to
109      * be a different string.
110      *
111      * @param source the connector server or client emitting the
112      * notification.
113      *
114      * @param connectionId the ID of the connection within its
115      * connector server.
116      *
117      * @param sequenceNumber a non-negative integer. It is expected
118      * but not required that this number will be greater than any
119      * previous <code>sequenceNumber</code> in a notification from
120      * this source.
121      *
122      * @param message an unspecified text message, typically containing
123      * a human-readable description of the event. Can be null.
124      *
125      * @param userData an object whose type and meaning is defined by
126      * the connector server. Can be null.
127      *
128      * @exception NullPointerException if <code>type</code>,
129      * <code>source</code>, or <code>connectionId</code> is null.
130      *
131      * @exception IllegalArgumentException if
132      * <code>sequenceNumber</code> is negative.
133      */

134     public JMXConnectionNotification(String JavaDoc type,
135                      Object JavaDoc source,
136                      String JavaDoc connectionId,
137                      long sequenceNumber,
138                      String JavaDoc message,
139                      Object JavaDoc userData) {
140     /* We don't know whether the parent class (Notification) will
141        throw an exception if the type or source is null, because
142        JMX 1.2 doesn't specify that. So we make sure it is not
143        null, in case it would throw the wrong exception
144        (e.g. IllegalArgumentException instead of
145        NullPointerException). Likewise for the sequence number. */

146     super((String JavaDoc) nonNull(type),
147           nonNull(source),
148           Math.max(0, sequenceNumber),
149           System.currentTimeMillis(),
150           message);
151     if (type == null || source == null || connectionId == null)
152         throw new NullPointerException JavaDoc("Illegal null argument");
153     if (sequenceNumber < 0)
154         throw new IllegalArgumentException JavaDoc("Negative sequence number");
155     this.connectionId = connectionId;
156     setUserData(userData);
157     }
158
159     private static Object JavaDoc nonNull(Object JavaDoc arg) {
160     if (arg == null)
161         return "";
162     else
163         return arg;
164     }
165
166     /**
167      * <p>The connection ID to which this notification pertains.
168      *
169      * @return the connection ID.
170      */

171     public String JavaDoc getConnectionId() {
172     return connectionId;
173     }
174
175     /**
176      * @serial The connection ID to which this notification pertains.
177      * @see #getConnectionId()
178      **/

179     private final String JavaDoc connectionId;
180 }
181
Popular Tags