NotificationResult.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* NotificationResult.java -- Wrapper for a series of buffered notifications.
  2. Copyright (C) 2008 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.management.remote;
  32. import java.io.Serializable;
  33. /**
  34. * <p>
  35. * Wraps the result of a query for buffered notifications. In a remote
  36. * scenario, it may be more practical for the server to buffer individual
  37. * notifications from its beans and then return them in bulk on request.
  38. * This class contains the notifications returned by such a request.
  39. * </p>
  40. * <p>
  41. * It consists of a series of {@link Notification} and identifier pairs,
  42. * wrapped in a {@link TargetedNotification} object. The identifiers
  43. * serve to pair up the notification with the listener that requested
  44. * it. Two positive numbers are also included: the first sequence number
  45. * used by the returned notifications, and the sequence number of the
  46. * notification which will be returned by the next query. The first
  47. * sequence number may be greater than the next sequence number if some
  48. * notifications have been lost.
  49. * </p>
  50. *
  51. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  52. * @since 1.5
  53. */
  54. public class NotificationResult
  55. implements Serializable
  56. {
  57. /**
  58. * Compatible with JDK 1.6
  59. */
  60. private static final long serialVersionUID = 1191800228721395279L;
  61. /**
  62. * The sequence number of the first notification.
  63. */
  64. private long earliestSequenceNumber;
  65. /**
  66. * The sequence number of the next notification to be
  67. * returned by a future query.
  68. */
  69. private long nextSequenceNumber;
  70. /**
  71. * The pairs of notifications and identifiers returned
  72. * by the query.
  73. */
  74. private TargetedNotification[] targetedNotifications;
  75. /**
  76. * Constructs a new {@link NotificationResult} using the specified
  77. * sequence numbers and the supplied array of notification pairs.
  78. *
  79. * @param startSeqNumber the sequence number of the first notification
  80. * being returned.
  81. * @param nextSeqNumber the sequence numbr of the next notification
  82. * that will be returned from a future query.
  83. * @param notifications the notification and identifier pairs. This
  84. * may be empty.
  85. * @throws IllegalArgumentException if a sequence number is negative
  86. * or <code>notifications</code> is
  87. * <code>null</code>.
  88. */
  89. public NotificationResult(long startSeqNumber, long nextSeqNumber,
  90. TargetedNotification[] notifications)
  91. {
  92. if (startSeqNumber < 0)
  93. throw new IllegalArgumentException("Starting sequence number is " +
  94. "less than 0.");
  95. if (nextSeqNumber < 0)
  96. throw new IllegalArgumentException("Next sequence number is " +
  97. "less than 0.");
  98. if (notifications == null)
  99. throw new IllegalArgumentException("The array of notifications is null.");
  100. earliestSequenceNumber = startSeqNumber;
  101. nextSequenceNumber = nextSeqNumber;
  102. targetedNotifications = notifications;
  103. }
  104. /**
  105. * Returns the sequence number of the earliest notification
  106. * in the buffer.
  107. *
  108. * @return the sequence number of the earliest notification.
  109. */
  110. public long getEarliestSequenceNumber()
  111. {
  112. return earliestSequenceNumber;
  113. }
  114. /**
  115. * Returns the sequence number of the next notification to
  116. * be returned by a future query.
  117. *
  118. * @return the sequence number of the next notification.
  119. */
  120. public long getNextSequenceNumber()
  121. {
  122. return nextSequenceNumber;
  123. }
  124. /**
  125. * Returns the notification and identifier pairs returned
  126. * by the query.
  127. *
  128. * @return the notification and identifier pairs.
  129. */
  130. public TargetedNotification[] getTargetedNotifications()
  131. {
  132. return targetedNotifications;
  133. }
  134. /**
  135. * Returns a textual representation of the object.
  136. *
  137. * @return a textual representation.
  138. */
  139. public String toString()
  140. {
  141. return getClass().getName() +
  142. "[earliestSequenceNumber=" + earliestSequenceNumber +
  143. ",nextSequenceNumber=" + nextSequenceNumber +
  144. ",targetedNotifications=" + targetedNotifications +
  145. "]";
  146. }
  147. }