KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > remote > NotificationResult


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
8 package javax.management.remote;
9
10 import java.io.Serializable JavaDoc;
11
12 import javax.management.Notification JavaDoc;
13 import javax.management.ObjectName JavaDoc;
14
15 /**
16  * <p>Result of a query for buffered notifications. Notifications in
17  * a notification buffer have positive, monotonically increasing
18  * sequence numbers. The result of a notification query contains the
19  * following elements:</p>
20  *
21  * <ul>
22  *
23  * <li>The sequence number of the earliest notification still in
24  * the buffer.
25  *
26  * <li>The sequence number of the next notification available for
27  * querying. This will be the starting sequence number for the next
28  * notification query.
29  *
30  * <li>An array of (Notification,listenerID) pairs corresponding to
31  * the returned notifications and the listeners they correspond to.
32  *
33  * </ul>
34  *
35  * <p>It is possible for the <code>nextSequenceNumber</code> to be less
36  * than the <code>earliestSequenceNumber</code>. This signifies that
37  * notifications between the two might have been lost.</p>
38  *
39  * @since 1.5
40  * @since.unbundled 1.0
41  */

42 public class NotificationResult implements Serializable JavaDoc {
43
44     private static final long serialVersionUID = 1191800228721395279L;
45
46     /**
47      * <p>Constructs a notification query result.</p>
48      *
49      * @param earliestSequenceNumber the sequence number of the
50      * earliest notification still in the buffer.
51      * @param nextSequenceNumber the sequence number of the next
52      * notification available for querying.
53      * @param targetedNotifications the notifications resulting from
54      * the query, and the listeners they correspond to. This array
55      * can be empty.
56      *
57      * @exception IllegalArgumentException if
58      * <code>targetedNotifications</code> is null or if
59      * <code>earliestSequenceNumber</code> or
60      * <code>nextSequenceNumber</code> is negative.
61      */

62     public NotificationResult(long earliestSequenceNumber,
63                   long nextSequenceNumber,
64                   TargetedNotification JavaDoc[] targetedNotifications) {
65     if (targetedNotifications == null) {
66         final String JavaDoc msg = "Notifications null";
67         throw new IllegalArgumentException JavaDoc(msg);
68     }
69
70     if (earliestSequenceNumber < 0 || nextSequenceNumber < 0)
71         throw new IllegalArgumentException JavaDoc("Bad sequence numbers");
72     /* We used to check nextSequenceNumber >= earliestSequenceNumber
73        here. But in fact the opposite can legitimately be true if
74        notifications have been lost. */

75
76     this.earliestSequenceNumber = earliestSequenceNumber;
77     this.nextSequenceNumber = nextSequenceNumber;
78     this.targetedNotifications = targetedNotifications;
79     }
80
81     /**
82      * Returns the sequence number of the earliest notification still
83      * in the buffer.
84      *
85      * @return the sequence number of the earliest notification still
86      * in the buffer.
87      */

88     public long getEarliestSequenceNumber() {
89     return earliestSequenceNumber;
90     }
91
92     /**
93      * Returns the sequence number of the next notification available
94      * for querying.
95      *
96      * @return the sequence number of the next notification available
97      * for querying.
98      */

99     public long getNextSequenceNumber() {
100     return nextSequenceNumber;
101     }
102
103     /**
104      * Returns the notifications resulting from the query, and the
105      * listeners they correspond to.
106      *
107      * @return the notifications resulting from the query, and the
108      * listeners they correspond to. This array can be empty.
109      */

110     public TargetedNotification JavaDoc[] getTargetedNotifications() {
111     return targetedNotifications;
112     }
113
114     /**
115      * Returns a string representation of the object. The result
116      * should be a concise but informative representation that is easy
117      * for a person to read.
118      *
119      * @return a string representation of the object.
120      */

121     public String JavaDoc toString() {
122     return "NotificationResult: earliest=" + getEarliestSequenceNumber() +
123         "; next=" + getNextSequenceNumber() + "; nnotifs=" +
124         getTargetedNotifications().length;
125     }
126
127     private final long earliestSequenceNumber;
128     private final long nextSequenceNumber;
129     private final TargetedNotification JavaDoc[] targetedNotifications;
130 }
131
Popular Tags