1. /*
  2. * @(#)TargetedNotification.java 1.10 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 java.io.Serializable;
  9. import javax.management.Notification;
  10. /**
  11. * <p>A (Notification, Listener ID) pair.</p>
  12. * <p>This class is used to associate an emitted notification
  13. * with the listener ID to which it is targeted.</p>
  14. *
  15. * @since 1.5
  16. * @since.unbundled 1.0
  17. */
  18. public class TargetedNotification implements Serializable {
  19. private static final long serialVersionUID = 7676132089779300926L;
  20. // If we replace Integer with int...
  21. // /**
  22. // * <p>Constructs a <code>TargetedNotification</code> object. The
  23. // * object contains a pair (Notification, Listener ID).
  24. // * The Listener ID identifies the client listener to which that
  25. // * notification is targeted. The client listener ID is one
  26. // * previously returned by the connector server in response to an
  27. // * <code>addNotificationListener</code> request.</p>
  28. // * @param notification Notification emitted from the MBean server.
  29. // * @param listenerID The ID of the listener to which this
  30. // * notification is targeted.
  31. // */
  32. // public TargetedNotification(Notification notification,
  33. // int listenerID) {
  34. // this.notif = notification;
  35. // this.id = listenerID;
  36. // }
  37. /**
  38. * <p>Constructs a <code>TargetedNotification</code> object. The
  39. * object contains a pair (Notification, Listener ID).
  40. * The Listener ID identifies the client listener to which that
  41. * notification is targeted. The client listener ID is one
  42. * previously returned by the connector server in response to an
  43. * <code>addNotificationListener</code> request.</p>
  44. * @param notification Notification emitted from the MBean server.
  45. * @param listenerID The ID of the listener to which this
  46. * notification is targeted.
  47. * @exception IllegalArgumentException if the <var>listenerID</var>
  48. * or <var>notification</var> is null.
  49. */
  50. public TargetedNotification(Notification notification,
  51. Integer listenerID) {
  52. // If we replace integer with int...
  53. // this(notification,intValue(listenerID));
  54. if (notification == null) throw new
  55. IllegalArgumentException("Invalid notification: null");
  56. if (listenerID == null) throw new
  57. IllegalArgumentException("Invalid listener ID: null");
  58. this.notif = notification;
  59. this.id = listenerID;
  60. }
  61. /**
  62. * <p>The emitted notification.</p>
  63. *
  64. * @return The notification.
  65. */
  66. public Notification getNotification() {
  67. return notif;
  68. }
  69. /**
  70. * <p>The ID of the listener to which the notification is
  71. * targeted.</p>
  72. *
  73. * @return The listener ID.
  74. */
  75. public Integer getListenerID() {
  76. return id;
  77. }
  78. /**
  79. * Returns a textual representation of this Targeted Notification.
  80. *
  81. * @return a String representation of this Targeted Notification.
  82. **/
  83. public String toString() {
  84. return "{" + notif + ", " + id + "}";
  85. }
  86. /**
  87. * @serial A notification to transmit to the other side.
  88. * @see #getNotification()
  89. **/
  90. private final Notification notif;
  91. /**
  92. * @serial The ID of the listener to which the notification is
  93. * targeted.
  94. * @see #getListenerID()
  95. **/
  96. private final Integer id;
  97. //private final int id;
  98. // Needed if we use int instead of Integer...
  99. // private static int intValue(Integer id) {
  100. // if (id == null) throw new
  101. // IllegalArgumentException("Invalid listener ID: null");
  102. // return id.intValue();
  103. // }
  104. }