]> sjero.net Git - linphone/blob - p2pproxy/dependencies-src/jxse-src-2.5/impl/src/net/jxta/impl/endpoint/endpointMeter/EndpointMetric.java
remove mediastreamer2 and add it as a submodule instead.
[linphone] / p2pproxy / dependencies-src / jxse-src-2.5 / impl / src / net / jxta / impl / endpoint / endpointMeter / EndpointMetric.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.endpoint.endpointMeter;
58
59
60 import net.jxta.endpoint.*;
61 import net.jxta.util.documentSerializable.*;
62 import net.jxta.document.*;
63
64 import java.util.*;
65
66
67 /**
68  *    Aggregate Metric for Endpoint Monitoring
69  **/
70 public class EndpointMetric implements DocumentSerializable {
71     private long endpointStartTime;
72     private long endpointUpTime;
73     private int invalidIncomingMessage;
74     private int noListenerForIncomingMessage;
75     private int errorProcessingIncomingMessage;
76     private int noDestinationAddressForDemuxMessage;
77     private int noSourceAddressForDemuxMessage;
78     private int discardedLoopbackDemuxMessage;
79     private int incomingMessageFilteredOut;
80     private int incomingMessageSentToEndpointListener;
81     private int demuxMessageProcessed;
82         
83     public EndpointMetric() { 
84         endpointStartTime = System.currentTimeMillis();
85     }
86
87     public EndpointMetric(EndpointMetric prototype) { 
88         endpointStartTime = prototype.endpointStartTime;
89     }
90         
91     void invalidIncomingMessage() {
92         invalidIncomingMessage++;
93     }
94
95     void noListenerForIncomingMessage() {
96         noListenerForIncomingMessage++;
97     }
98
99     void errorProcessingIncomingMessage() {
100         errorProcessingIncomingMessage++;
101     }
102
103     void noDestinationAddressForDemuxMessage() {
104         noDestinationAddressForDemuxMessage++;
105     }
106
107     void noSourceAddressForDemuxMessage() {
108         noSourceAddressForDemuxMessage++;
109     }
110
111     void discardedLoopbackDemuxMessage() {
112         discardedLoopbackDemuxMessage++;
113     }
114
115     void incomingMessageFilteredOut() {
116         incomingMessageFilteredOut++;
117     }
118
119     void incomingMessageSentToEndpointListener() {
120         incomingMessageSentToEndpointListener++;
121     }
122
123     void demuxMessageProcessed() {
124         demuxMessageProcessed++;
125     }
126
127     void setEndpointUpTime(long endpointUpTime) {
128         this.endpointUpTime = endpointUpTime;
129     }
130
131     /** Get the time this Endpoint was created, essentially the boot time of the PeerGroup **/
132     public long getEndpointStartTime() {
133         return endpointStartTime;
134     }
135
136     /** Get the time this Endpoint has been up **/
137     public long getEndpointUpTime() {
138         return endpointUpTime;
139     }
140
141     /** The number of messages received that had invalid formats **/
142     public int getInvalidIncomingMessage() {
143         return invalidIncomingMessage;
144     }
145
146     /** The number of messages received that had no listeners **/
147     public int getNoListenerForIncomingMessage() {
148         return noListenerForIncomingMessage;
149     }
150
151     /** The number of messages whose local listeners threw exceptions **/
152     public int getErrorProcessingIncomingMessage() {
153         return errorProcessingIncomingMessage;
154     }
155
156     /** The number of messages that couldn't be demuxed because there was no destination address **/
157     public int getNoDestinationAddressForDemuxMessage() {
158         return noDestinationAddressForDemuxMessage;
159     }
160
161     /** The number of messages that couldn't be demuxed because there was no source address **/
162     public int getNoSourceAddressForDemuxMessage() {
163         return noSourceAddressForDemuxMessage;
164     }
165
166     /** The number of messages that were discarded because of loopback detection **/
167     public int getDiscardedLoopbackDemuxMessage() {
168         return discardedLoopbackDemuxMessage;
169     }
170
171     /** The number of messages that were discarded because of filtering **/
172     public int getIncomingMessageFilteredOut() {
173         return incomingMessageFilteredOut;
174     }
175
176     /** The number of messages that sent to registered listeners **/
177     public int getIncomingMessageSentToEndpointListener() {
178         return incomingMessageSentToEndpointListener;
179     }
180
181     /** The number of messages that were processed through demux **/
182     public int getDemuxMessageProcessed() {
183         return demuxMessageProcessed;
184     }
185                 
186     public void serializeTo(Element element) throws DocumentSerializationException {
187         if (endpointStartTime != 0) {
188             DocumentSerializableUtilities.addLong(element, "endpointStartTime", endpointStartTime);
189         }
190         if (endpointUpTime != 0) {
191             DocumentSerializableUtilities.addLong(element, "endpointUpTime", endpointUpTime);
192         }
193         if (invalidIncomingMessage != 0) {
194             DocumentSerializableUtilities.addInt(element, "invalidIncomingMessage", invalidIncomingMessage);
195         }
196         if (noListenerForIncomingMessage != 0) {
197             DocumentSerializableUtilities.addInt(element, "noListenerForIncomingMessage", noListenerForIncomingMessage);
198         }
199         if (errorProcessingIncomingMessage != 0) {      
200             DocumentSerializableUtilities.addInt(element, "errorProcessingIncomingMessage", errorProcessingIncomingMessage);
201         }
202         if (noDestinationAddressForDemuxMessage != 0) {
203             DocumentSerializableUtilities.addInt(element, "noDestinationAddressForDemuxMessage"
204                     ,
205                     noDestinationAddressForDemuxMessage);
206         }
207         if (noSourceAddressForDemuxMessage != 0) {
208             DocumentSerializableUtilities.addInt(element, "noSourceAddressForDemuxMessage", noSourceAddressForDemuxMessage);
209         }
210         if (discardedLoopbackDemuxMessage != 0) {
211             DocumentSerializableUtilities.addInt(element, "discardedLoopbackDemuxMessage", discardedLoopbackDemuxMessage);
212         }
213         if (incomingMessageFilteredOut != 0) {
214             DocumentSerializableUtilities.addInt(element, "incomingMessageFilteredOut", incomingMessageFilteredOut);
215         }
216         if (incomingMessageSentToEndpointListener != 0) {
217             DocumentSerializableUtilities.addInt(element, "incomingMessageSentToEndpointListener"
218                     ,
219                     incomingMessageSentToEndpointListener);
220         }
221         if (demuxMessageProcessed != 0) {
222             DocumentSerializableUtilities.addInt(element, "demuxMessageProcessed", demuxMessageProcessed);
223         }
224     }
225
226     public void initializeFrom(Element element) throws DocumentSerializationException {
227         for (Enumeration e = element.getChildren(); e.hasMoreElements();) {
228             Element childElement = (TextElement) e.nextElement();
229             String tagName = (String) childElement.getKey();
230                         
231             if (tagName.equals("endpointStartTime")) {
232                 endpointStartTime = DocumentSerializableUtilities.getLong(childElement);
233             }
234             if (tagName.equals("endpointUpTime")) {
235                 endpointUpTime = DocumentSerializableUtilities.getLong(childElement);
236             }
237             if (tagName.equals("invalidIncomingMessage")) {
238                 invalidIncomingMessage = DocumentSerializableUtilities.getInt(childElement);
239             } else if (tagName.equals("noListenerForIncomingMessage")) {
240                 noListenerForIncomingMessage = DocumentSerializableUtilities.getInt(childElement);
241             } else if (tagName.equals("errorProcessingIncomingMessage")) {
242                 errorProcessingIncomingMessage = DocumentSerializableUtilities.getInt(childElement);
243             } else if (tagName.equals("noDestinationAddressForDemuxMessage")) {
244                 noDestinationAddressForDemuxMessage = DocumentSerializableUtilities.getInt(childElement);
245             } else if (tagName.equals("noSourceAddressForDemuxMessage")) {
246                 noSourceAddressForDemuxMessage = DocumentSerializableUtilities.getInt(childElement);
247             } else if (tagName.equals("invalidIncomingMessage")) {
248                 invalidIncomingMessage = DocumentSerializableUtilities.getInt(childElement);
249             } else if (tagName.equals("discardedLoopbackDemuxMessage")) {
250                 discardedLoopbackDemuxMessage = DocumentSerializableUtilities.getInt(childElement);
251             } else if (tagName.equals("incomingMessageFilteredOut")) {
252                 incomingMessageFilteredOut = DocumentSerializableUtilities.getInt(childElement);
253             } else if (tagName.equals("incomingMessageSentToEndpointListener")) {
254                 incomingMessageSentToEndpointListener = DocumentSerializableUtilities.getInt(childElement);
255             } else if (tagName.equals("demuxMessageProcessed")) {
256                 demuxMessageProcessed = DocumentSerializableUtilities.getInt(childElement);
257             }
258         }
259
260     }
261
262     public void mergeMetrics(EndpointMetric other) {
263         if (other == null) {
264             return;
265         }
266
267         endpointStartTime = other.endpointStartTime;
268
269         if (other.endpointUpTime != 0) {
270             endpointUpTime = other.endpointUpTime;
271         }
272                         
273         invalidIncomingMessage += other.invalidIncomingMessage;
274         noListenerForIncomingMessage += other.noListenerForIncomingMessage;
275         errorProcessingIncomingMessage += other.errorProcessingIncomingMessage;
276         noDestinationAddressForDemuxMessage += other.noDestinationAddressForDemuxMessage;
277         noSourceAddressForDemuxMessage += other.noSourceAddressForDemuxMessage;
278         discardedLoopbackDemuxMessage += other.discardedLoopbackDemuxMessage;
279         incomingMessageSentToEndpointListener += other.incomingMessageSentToEndpointListener;
280         demuxMessageProcessed += other.demuxMessageProcessed;           
281     }
282 }