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