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.endpoint.endpointMeter;
60 import net.jxta.endpoint.*;
61 import net.jxta.util.documentSerializable.*;
62 import net.jxta.document.*;
68 * Aggregate Metric for Endpoint Monitoring
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;
83 public EndpointMetric() {
84 endpointStartTime = System.currentTimeMillis();
87 public EndpointMetric(EndpointMetric prototype) {
88 endpointStartTime = prototype.endpointStartTime;
91 void invalidIncomingMessage() {
92 invalidIncomingMessage++;
95 void noListenerForIncomingMessage() {
96 noListenerForIncomingMessage++;
99 void errorProcessingIncomingMessage() {
100 errorProcessingIncomingMessage++;
103 void noDestinationAddressForDemuxMessage() {
104 noDestinationAddressForDemuxMessage++;
107 void noSourceAddressForDemuxMessage() {
108 noSourceAddressForDemuxMessage++;
111 void discardedLoopbackDemuxMessage() {
112 discardedLoopbackDemuxMessage++;
115 void incomingMessageFilteredOut() {
116 incomingMessageFilteredOut++;
119 void incomingMessageSentToEndpointListener() {
120 incomingMessageSentToEndpointListener++;
123 void demuxMessageProcessed() {
124 demuxMessageProcessed++;
127 void setEndpointUpTime(long endpointUpTime) {
128 this.endpointUpTime = endpointUpTime;
131 /** Get the time this Endpoint was created, essentially the boot time of the PeerGroup **/
132 public long getEndpointStartTime() {
133 return endpointStartTime;
136 /** Get the time this Endpoint has been up **/
137 public long getEndpointUpTime() {
138 return endpointUpTime;
141 /** The number of messages received that had invalid formats **/
142 public int getInvalidIncomingMessage() {
143 return invalidIncomingMessage;
146 /** The number of messages received that had no listeners **/
147 public int getNoListenerForIncomingMessage() {
148 return noListenerForIncomingMessage;
151 /** The number of messages whose local listeners threw exceptions **/
152 public int getErrorProcessingIncomingMessage() {
153 return errorProcessingIncomingMessage;
156 /** The number of messages that couldn't be demuxed because there was no destination address **/
157 public int getNoDestinationAddressForDemuxMessage() {
158 return noDestinationAddressForDemuxMessage;
161 /** The number of messages that couldn't be demuxed because there was no source address **/
162 public int getNoSourceAddressForDemuxMessage() {
163 return noSourceAddressForDemuxMessage;
166 /** The number of messages that were discarded because of loopback detection **/
167 public int getDiscardedLoopbackDemuxMessage() {
168 return discardedLoopbackDemuxMessage;
171 /** The number of messages that were discarded because of filtering **/
172 public int getIncomingMessageFilteredOut() {
173 return incomingMessageFilteredOut;
176 /** The number of messages that sent to registered listeners **/
177 public int getIncomingMessageSentToEndpointListener() {
178 return incomingMessageSentToEndpointListener;
181 /** The number of messages that were processed through demux **/
182 public int getDemuxMessageProcessed() {
183 return demuxMessageProcessed;
186 public void serializeTo(Element element) throws DocumentSerializationException {
187 if (endpointStartTime != 0) {
188 DocumentSerializableUtilities.addLong(element, "endpointStartTime", endpointStartTime);
190 if (endpointUpTime != 0) {
191 DocumentSerializableUtilities.addLong(element, "endpointUpTime", endpointUpTime);
193 if (invalidIncomingMessage != 0) {
194 DocumentSerializableUtilities.addInt(element, "invalidIncomingMessage", invalidIncomingMessage);
196 if (noListenerForIncomingMessage != 0) {
197 DocumentSerializableUtilities.addInt(element, "noListenerForIncomingMessage", noListenerForIncomingMessage);
199 if (errorProcessingIncomingMessage != 0) {
200 DocumentSerializableUtilities.addInt(element, "errorProcessingIncomingMessage", errorProcessingIncomingMessage);
202 if (noDestinationAddressForDemuxMessage != 0) {
203 DocumentSerializableUtilities.addInt(element, "noDestinationAddressForDemuxMessage"
205 noDestinationAddressForDemuxMessage);
207 if (noSourceAddressForDemuxMessage != 0) {
208 DocumentSerializableUtilities.addInt(element, "noSourceAddressForDemuxMessage", noSourceAddressForDemuxMessage);
210 if (discardedLoopbackDemuxMessage != 0) {
211 DocumentSerializableUtilities.addInt(element, "discardedLoopbackDemuxMessage", discardedLoopbackDemuxMessage);
213 if (incomingMessageFilteredOut != 0) {
214 DocumentSerializableUtilities.addInt(element, "incomingMessageFilteredOut", incomingMessageFilteredOut);
216 if (incomingMessageSentToEndpointListener != 0) {
217 DocumentSerializableUtilities.addInt(element, "incomingMessageSentToEndpointListener"
219 incomingMessageSentToEndpointListener);
221 if (demuxMessageProcessed != 0) {
222 DocumentSerializableUtilities.addInt(element, "demuxMessageProcessed", demuxMessageProcessed);
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();
231 if (tagName.equals("endpointStartTime")) {
232 endpointStartTime = DocumentSerializableUtilities.getLong(childElement);
234 if (tagName.equals("endpointUpTime")) {
235 endpointUpTime = DocumentSerializableUtilities.getLong(childElement);
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);
262 public void mergeMetrics(EndpointMetric other) {
267 endpointStartTime = other.endpointStartTime;
269 if (other.endpointUpTime != 0) {
270 endpointUpTime = other.endpointUpTime;
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;