1. /*
  2. * @(#)NotificationResult.java 1.6 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. import javax.management.ObjectName;
  11. /**
  12. * <p>Result of a query for buffered notifications. Notifications in
  13. * a notification buffer have positive, monotonically increasing
  14. * sequence numbers. The result of a notification query contains the
  15. * following elements:</p>
  16. *
  17. * <ul>
  18. *
  19. * <li>The sequence number of the earliest notification still in
  20. * the buffer.
  21. *
  22. * <li>The sequence number of the next notification available for
  23. * querying. This will be the starting sequence number for the next
  24. * notification query.
  25. *
  26. * <li>An array of (Notification,listenerID) pairs corresponding to
  27. * the returned notifications and the listeners they correspond to.
  28. *
  29. * </ul>
  30. *
  31. * <p>It is possible for the <code>nextSequenceNumber</code> to be less
  32. * than the <code>earliestSequenceNumber</code>. This signifies that
  33. * notifications between the two might have been lost.</p>
  34. *
  35. * @since 1.5
  36. * @since.unbundled 1.0
  37. */
  38. public class NotificationResult implements Serializable {
  39. private static final long serialVersionUID = 1191800228721395279L;
  40. /**
  41. * <p>Constructs a notification query result.</p>
  42. *
  43. * @param earliestSequenceNumber the sequence number of the
  44. * earliest notification still in the buffer.
  45. * @param nextSequenceNumber the sequence number of the next
  46. * notification available for querying.
  47. * @param targetedNotifications the notifications resulting from
  48. * the query, and the listeners they correspond to. This array
  49. * can be empty.
  50. *
  51. * @exception IllegalArgumentException if
  52. * <code>targetedNotifications</code> is null or if
  53. * <code>earliestSequenceNumber</code> or
  54. * <code>nextSequenceNumber</code> is negative.
  55. */
  56. public NotificationResult(long earliestSequenceNumber,
  57. long nextSequenceNumber,
  58. TargetedNotification[] targetedNotifications) {
  59. if (targetedNotifications == null) {
  60. final String msg = "Notifications null";
  61. throw new IllegalArgumentException(msg);
  62. }
  63. if (earliestSequenceNumber < 0 || nextSequenceNumber < 0)
  64. throw new IllegalArgumentException("Bad sequence numbers");
  65. /* We used to check nextSequenceNumber >= earliestSequenceNumber
  66. here. But in fact the opposite can legitimately be true if
  67. notifications have been lost. */
  68. this.earliestSequenceNumber = earliestSequenceNumber;
  69. this.nextSequenceNumber = nextSequenceNumber;
  70. this.targetedNotifications = targetedNotifications;
  71. }
  72. /**
  73. * Returns the sequence number of the earliest notification still
  74. * in the buffer.
  75. *
  76. * @return the sequence number of the earliest notification still
  77. * in the buffer.
  78. */
  79. public long getEarliestSequenceNumber() {
  80. return earliestSequenceNumber;
  81. }
  82. /**
  83. * Returns the sequence number of the next notification available
  84. * for querying.
  85. *
  86. * @return the sequence number of the next notification available
  87. * for querying.
  88. */
  89. public long getNextSequenceNumber() {
  90. return nextSequenceNumber;
  91. }
  92. /**
  93. * Returns the notifications resulting from the query, and the
  94. * listeners they correspond to.
  95. *
  96. * @return the notifications resulting from the query, and the
  97. * listeners they correspond to. This array can be empty.
  98. */
  99. public TargetedNotification[] getTargetedNotifications() {
  100. return targetedNotifications;
  101. }
  102. /**
  103. * Returns a string representation of the object. The result
  104. * should be a concise but informative representation that is easy
  105. * for a person to read.
  106. *
  107. * @return a string representation of the object.
  108. */
  109. public String toString() {
  110. return "NotificationResult: earliest=" + getEarliestSequenceNumber() +
  111. "; next=" + getNextSequenceNumber() + "; nnotifs=" +
  112. getTargetedNotifications().length;
  113. }
  114. private final long earliestSequenceNumber;
  115. private final long nextSequenceNumber;
  116. private final TargetedNotification[] targetedNotifications;
  117. }