]> sjero.net Git - linphone/blob - p2pproxy/dependencies-src/jxse-src-2.5/impl/src/net/jxta/impl/peer/RemoteMonitorQuery.java
remove mediastreamer2 and add it as a submodule instead.
[linphone] / p2pproxy / dependencies-src / jxse-src-2.5 / impl / src / net / jxta / impl / peer / RemoteMonitorQuery.java
1 /*
2  * Copyright (c) 2001-2007 Sun Microsystems, Inc.  All rights reserved.
3  *  
4  *  The Sun Project JXTA(TM) Software License
5  *  
6  *  Redistribution and use in source and binary forms, with or without 
7  *  modification, are permitted provided that the following conditions are met:
8  *  
9  *  1. Redistributions of source code must retain the above copyright notice,
10  *     this list of conditions and the following disclaimer.
11  *  
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.
15  *  
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.
21  *  
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.
26  *  
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.
29  *  
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.
40  *  
41  *  JXTA is a registered trademark of Sun Microsystems, Inc. in the United 
42  *  States and other countries.
43  *  
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.
47  *  
48  *  ====================================================================
49  *  
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.
53  *  
54  *  This license is based on the BSD license adopted by the Apache Foundation. 
55  */
56
57 package net.jxta.impl.peer;
58
59
60 import net.jxta.document.*;
61 import net.jxta.util.documentSerializable.*;
62 import net.jxta.meter.*;
63
64 import java.util.*;
65
66
67 public class RemoteMonitorQuery implements DocumentSerializable {
68
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";
77         
78     private String requestType;
79     private MonitorFilter monitorFilter;
80     private boolean includeCumulative;
81     private long reportRate = -1;
82     private long lease = -1;
83     private int leaseId;
84
85     public RemoteMonitorQuery() {} // for serialization code.
86
87     private RemoteMonitorQuery(String requestType) { 
88         this.requestType = requestType;
89     }
90
91     public MonitorFilter getMonitorFilter() {
92         return monitorFilter;
93     }
94
95     private String getRequestType() {
96         return requestType;
97     }
98
99     public long getReportRate() {
100         return reportRate;
101     }
102
103     public long getLease() {
104         return lease;
105     }
106
107     public int getLeaseId() {
108         return leaseId;
109     }
110
111     public boolean isIncludeCumulative() {
112         return includeCumulative;
113     }
114         
115     boolean isCumulativeReportQuery() {
116         return requestType.equals(CUMULATIVE_REPORT_REQUEST);
117     }
118
119     boolean isRegisterMonitorQuery() {
120         return requestType.equals(REGISTER_MONITOR_REQUEST);
121     }
122
123     boolean isRemoveMonitorQuery() {
124         return requestType.equals(REMOVE_MONITOR_REQUEST);
125     }
126
127     boolean isValidateFilterRequest() {
128         return requestType.equals(VALIDATE_FILTER_REQUEST);
129     }
130
131     boolean isValidateCumulativeFilterRequest() {
132         return requestType.equals(VALIDATE_CUMULATIVE_FILTER_REQUEST);
133     }
134
135     boolean isPeerMonitorInfoQuery() {
136         return requestType.equals(PEER_MONITOR_INFO);
137     }
138
139     boolean isLeaseRenewal() {
140         return requestType.equals(RENEW_LEASE);
141     }
142
143     static RemoteMonitorQuery createGetCumulativeReportQuery(MonitorFilter monitorFilter) {
144         RemoteMonitorQuery remoteMonitorQuery = new RemoteMonitorQuery(CUMULATIVE_REPORT_REQUEST);
145
146         remoteMonitorQuery.monitorFilter = monitorFilter;
147         return remoteMonitorQuery;
148     }
149                 
150     static RemoteMonitorQuery createRegisterMonitorQuery(boolean includeCumulative, MonitorFilter monitorFilter, long reportRate, long lease) {
151         RemoteMonitorQuery remoteMonitorQuery = new RemoteMonitorQuery(REGISTER_MONITOR_REQUEST);
152
153         remoteMonitorQuery.monitorFilter = monitorFilter;
154         remoteMonitorQuery.reportRate = reportRate;
155         remoteMonitorQuery.lease = lease;
156         remoteMonitorQuery.includeCumulative = includeCumulative;
157         return remoteMonitorQuery;
158     }
159
160     static RemoteMonitorQuery createRemoveMonitorListenerQuery(int leaseId) {
161         RemoteMonitorQuery remoteMonitorQuery = new RemoteMonitorQuery(REMOVE_MONITOR_REQUEST);
162
163         remoteMonitorQuery.leaseId = leaseId;
164         return remoteMonitorQuery;
165     }
166
167     static RemoteMonitorQuery createPeerMonitorInfoQuery() {
168         RemoteMonitorQuery remoteMonitorQuery = new RemoteMonitorQuery(PEER_MONITOR_INFO);
169
170         return remoteMonitorQuery;              
171     }
172
173     static RemoteMonitorQuery createLeaseRenewalQuery(int leaseId, long requestedLease) {
174         RemoteMonitorQuery remoteMonitorQuery = new RemoteMonitorQuery(RENEW_LEASE);
175
176         remoteMonitorQuery.leaseId = leaseId;
177         remoteMonitorQuery.lease = requestedLease;
178         return remoteMonitorQuery;
179     }
180
181     public void serializeTo(Element element) throws DocumentSerializationException {
182         DocumentSerializableUtilities.addString(element, "requestType", requestType);
183
184         if (monitorFilter != null) {
185             DocumentSerializableUtilities.addDocumentSerializable(element, "monitorFilter", monitorFilter);
186         }
187                         
188         if (lease > 0) {
189             DocumentSerializableUtilities.addLong(element, "lease", lease);
190         }
191
192         if (leaseId > -1) {
193             DocumentSerializableUtilities.addInt(element, "leaseId", leaseId);
194         }                       
195
196         if (reportRate > 0) {           
197             DocumentSerializableUtilities.addLong(element, "reportRate", reportRate);
198         }
199
200         if (includeCumulative) { 
201             DocumentSerializableUtilities.addBoolean(element, "includeCumulative", includeCumulative);
202         }
203     }
204
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();
209                         
210             if (tagName.equals("requestType")) { 
211                 requestType = DocumentSerializableUtilities.getString(childElement);
212             } else if (tagName.equals("monitorFilter")) { 
213                 monitorFilter = (MonitorFilter) DocumentSerializableUtilities.getDocumentSerializable(childElement
214                         ,
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);
224             }
225         }
226     }
227 }