1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
/* * @(#)JMXConnectionNotification.java 1.19 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.management.remote; import javax.management.Notification; import javax.management.ObjectName; /** * <p>Notification emitted when a client connection is opened or * closed or when notifications are lost. These notifications are * sent by connector servers (instances of {@link JMXConnectorServer}) * and by connector clients (instances of {@link JMXConnector}). For * certain connectors, a session can consist of a sequence of * connections. Connection-opened and connection-closed notifications * will be sent for each one.</p> * * <p>The notification type is one of the following:</p> * * <table> * * <tr> * <th align=left>Type</th> * <th align=left>Meaning</th> * </tr> * * <tr> * <td><code>jmx.remote.connection.opened</code></td> * <td>A new client connection has been opened.</td> * </tr> * * <tr> * <td><code>jmx.remote.connection.closed</code></td> * <td>A client connection has been closed.</td> * </tr> * * <tr> * <td><code>jmx.remote.connection.failed</code></td> * <td>A client connection has failed unexpectedly.</td> * </tr> * * <tr> * <td><code>jmx.remote.connection.notifs.lost</code></td> * <td>A client connection has potentially lost notifications. This * notification only appears on the client side.</td> * </tr> * </table> * * <p>The <code>timeStamp</code> of the notification is a time value * (consistent with {@link System#currentTimeMillis()}) indicating * when the notification was constructed.</p> * * @since 1.5 * @since.unbundled 1.0 */ public class JMXConnectionNotification extends Notification { private static final long serialVersionUID = -2331308725952627538L; /** * <p>Notification type string for a connection-opened notification. */ public static final String OPENED = "jmx.remote.connection.opened"; /** * <p>Notification type string for a connection-closed notification. */ public static final String CLOSED = "jmx.remote.connection.closed"; /** * <p>Notification type string for a connection-failed notification. */ public static final String FAILED = "jmx.remote.connection.failed"; /** * <p>Notification type string for a connection that has possibly * lost notifications.</p> */ public static final String NOTIFS_LOST = "jmx.remote.connection.notifs.lost"; /** * Constructs a new connection notification. The {@link * #getSource() source} of the notification depends on whether it * is being sent by a connector server or a connector client: * * <ul> * * <li>For a connector server, if it is registered in an MBean * server, the source is the {@link ObjectName} under which it is * registered. Otherwise, it is a reference to the connector * server object itself, an instance of a subclass of {@link * JMXConnectorServer}. * * <li>For a connector client, the source is a reference to the * connector client object, an instance of a class implementing * {@link JMXConnector}. * * </ul> * * @param type the type of the notification. This is usually one * of the constants {@link #OPENED}, {@link #CLOSED}, {@link * #FAILED}, {@link #NOTIFS_LOST}. It is not an error for it to * be a different string. * * @param source the connector server or client emitting the * notification. * * @param connectionId the ID of the connection within its * connector server. * * @param sequenceNumber a non-negative integer. It is expected * but not required that this number will be greater than any * previous <code>sequenceNumber</code> in a notification from * this source. * * @param message an unspecified text message, typically containing * a human-readable description of the event. Can be null. * * @param userData an object whose type and meaning is defined by * the connector server. Can be null. * * @exception NullPointerException if <code>type</code>, * <code>source</code>, or <code>connectionId</code> is null. * * @exception IllegalArgumentException if * <code>sequenceNumber</code> is negative. */ public JMXConnectionNotification(String type, Object source, String connectionId, long sequenceNumber, String message, Object userData) { /* We don't know whether the parent class (Notification) will throw an exception if the type or source is null, because JMX 1.2 doesn't specify that. So we make sure it is not null, in case it would throw the wrong exception (e.g. IllegalArgumentException instead of NullPointerException). Likewise for the sequence number. */ super((String) nonNull(type), nonNull(source), Math.max(0, sequenceNumber), System.currentTimeMillis(), message); if (type == null || source == null || connectionId == null) throw new NullPointerException("Illegal null argument"); if (sequenceNumber < 0) throw new IllegalArgumentException("Negative sequence number"); this.connectionId = connectionId; setUserData(userData); } private static Object nonNull(Object arg) { if (arg == null) return ""; else return arg; } /** * <p>The connection ID to which this notification pertains. * * @return the connection ID. */ public String getConnectionId() { return connectionId; } /** * @serial The connection ID to which this notification pertains. * @see #getConnectionId() **/ private final String connectionId; }