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