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