2 * Copyright (c) 2001-2007 Sun Microsystems, Inc. All rights reserved.
4 * The Sun Project JXTA(TM) Software License
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * 3. The end-user documentation included with the redistribution, if any, must
17 * include the following acknowledgment: "This product includes software
18 * developed by Sun Microsystems, Inc. for JXTA(TM) technology."
19 * Alternately, this acknowledgment may appear in the software itself, if
20 * and wherever such third-party acknowledgments normally appear.
22 * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must
23 * not be used to endorse or promote products derived from this software
24 * without prior written permission. For written permission, please contact
25 * Project JXTA at http://www.jxta.org.
27 * 5. Products derived from this software may not be called "JXTA", nor may
28 * "JXTA" appear in their name, without prior written permission of Sun.
30 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
32 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SUN
33 * MICROSYSTEMS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
36 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
39 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 * JXTA is a registered trademark of Sun Microsystems, Inc. in the United
42 * States and other countries.
44 * Please see the license information page at :
45 * <http://www.jxta.org/project/www/license.html> for instructions on use of
46 * the license in source files.
48 * ====================================================================
50 * This software consists of voluntary contributions made by many individuals
51 * on behalf of Project JXTA. For more information on Project JXTA, please see
52 * http://www.jxta.org.
54 * This license is based on the BSD license adopted by the Apache Foundation.
57 package net.jxta.impl.peer;
60 import net.jxta.document.*;
61 import net.jxta.util.documentSerializable.*;
62 import net.jxta.meter.*;
67 public class RemoteMonitorQuery implements DocumentSerializable {
69 public static final String CUMULATIVE_REPORT_REQUEST = "cumulativeReport";
70 public static final String REGISTER_MONITOR_REQUEST = "registerMonitor";
71 public static final String REMOVE_MONITOR_REQUEST = "removeMonitor";
72 public static final String VALIDATE_FILTER_REQUEST = "validateFilter";
73 public static final String VALIDATE_CUMULATIVE_FILTER_REQUEST = "validateCumulativeFilter";
74 public static final String GET_MONITORING_CAPABILITIES_REQUEST = "remoteMonitoringCapabilities";
75 public static final String PEER_MONITOR_INFO = "peerMonitorInfo";
76 public static final String RENEW_LEASE = "renewLease";
78 private String requestType;
79 private MonitorFilter monitorFilter;
80 private boolean includeCumulative;
81 private long reportRate = -1;
82 private long lease = -1;
85 public RemoteMonitorQuery() {} // for serialization code.
87 private RemoteMonitorQuery(String requestType) {
88 this.requestType = requestType;
91 public MonitorFilter getMonitorFilter() {
95 private String getRequestType() {
99 public long getReportRate() {
103 public long getLease() {
107 public int getLeaseId() {
111 public boolean isIncludeCumulative() {
112 return includeCumulative;
115 boolean isCumulativeReportQuery() {
116 return requestType.equals(CUMULATIVE_REPORT_REQUEST);
119 boolean isRegisterMonitorQuery() {
120 return requestType.equals(REGISTER_MONITOR_REQUEST);
123 boolean isRemoveMonitorQuery() {
124 return requestType.equals(REMOVE_MONITOR_REQUEST);
127 boolean isValidateFilterRequest() {
128 return requestType.equals(VALIDATE_FILTER_REQUEST);
131 boolean isValidateCumulativeFilterRequest() {
132 return requestType.equals(VALIDATE_CUMULATIVE_FILTER_REQUEST);
135 boolean isPeerMonitorInfoQuery() {
136 return requestType.equals(PEER_MONITOR_INFO);
139 boolean isLeaseRenewal() {
140 return requestType.equals(RENEW_LEASE);
143 static RemoteMonitorQuery createGetCumulativeReportQuery(MonitorFilter monitorFilter) {
144 RemoteMonitorQuery remoteMonitorQuery = new RemoteMonitorQuery(CUMULATIVE_REPORT_REQUEST);
146 remoteMonitorQuery.monitorFilter = monitorFilter;
147 return remoteMonitorQuery;
150 static RemoteMonitorQuery createRegisterMonitorQuery(boolean includeCumulative, MonitorFilter monitorFilter, long reportRate, long lease) {
151 RemoteMonitorQuery remoteMonitorQuery = new RemoteMonitorQuery(REGISTER_MONITOR_REQUEST);
153 remoteMonitorQuery.monitorFilter = monitorFilter;
154 remoteMonitorQuery.reportRate = reportRate;
155 remoteMonitorQuery.lease = lease;
156 remoteMonitorQuery.includeCumulative = includeCumulative;
157 return remoteMonitorQuery;
160 static RemoteMonitorQuery createRemoveMonitorListenerQuery(int leaseId) {
161 RemoteMonitorQuery remoteMonitorQuery = new RemoteMonitorQuery(REMOVE_MONITOR_REQUEST);
163 remoteMonitorQuery.leaseId = leaseId;
164 return remoteMonitorQuery;
167 static RemoteMonitorQuery createPeerMonitorInfoQuery() {
168 RemoteMonitorQuery remoteMonitorQuery = new RemoteMonitorQuery(PEER_MONITOR_INFO);
170 return remoteMonitorQuery;
173 static RemoteMonitorQuery createLeaseRenewalQuery(int leaseId, long requestedLease) {
174 RemoteMonitorQuery remoteMonitorQuery = new RemoteMonitorQuery(RENEW_LEASE);
176 remoteMonitorQuery.leaseId = leaseId;
177 remoteMonitorQuery.lease = requestedLease;
178 return remoteMonitorQuery;
181 public void serializeTo(Element element) throws DocumentSerializationException {
182 DocumentSerializableUtilities.addString(element, "requestType", requestType);
184 if (monitorFilter != null) {
185 DocumentSerializableUtilities.addDocumentSerializable(element, "monitorFilter", monitorFilter);
189 DocumentSerializableUtilities.addLong(element, "lease", lease);
193 DocumentSerializableUtilities.addInt(element, "leaseId", leaseId);
196 if (reportRate > 0) {
197 DocumentSerializableUtilities.addLong(element, "reportRate", reportRate);
200 if (includeCumulative) {
201 DocumentSerializableUtilities.addBoolean(element, "includeCumulative", includeCumulative);
205 public void initializeFrom(Element element) throws DocumentSerializationException {
206 for (Enumeration e = element.getChildren(); e.hasMoreElements();) {
207 Element childElement = (TextElement) e.nextElement();
208 String tagName = (String) childElement.getKey();
210 if (tagName.equals("requestType")) {
211 requestType = DocumentSerializableUtilities.getString(childElement);
212 } else if (tagName.equals("monitorFilter")) {
213 monitorFilter = (MonitorFilter) DocumentSerializableUtilities.getDocumentSerializable(childElement
215 MonitorFilter.class);
216 } else if (tagName.equals("lease")) {
217 lease = DocumentSerializableUtilities.getLong(childElement);
218 } else if (tagName.equals("leaseId")) {
219 leaseId = DocumentSerializableUtilities.getInt(childElement);
220 } else if (tagName.equals("reportRate")) {
221 reportRate = DocumentSerializableUtilities.getLong(childElement);
222 } else if (tagName.equals("includeCumulative")) {
223 includeCumulative = DocumentSerializableUtilities.getBoolean(childElement);