KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > messaging > MessagingStats


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.jbi.messaging;
18
19 import org.apache.activemq.management.CountStatisticImpl;
20 import org.apache.activemq.management.StatsImpl;
21 import org.apache.activemq.management.TimeStatisticImpl;
22 import org.apache.activemq.util.IndentPrinter;
23
24 /**
25  * Basic J2EE stats for the messaging in the NMR
26  *
27  * @version $Revision: 426415 $
28  */

29 public class MessagingStats extends StatsImpl {
30     private String JavaDoc componentName;
31     protected CountStatisticImpl inboundExchanges;
32     protected CountStatisticImpl outboundExchanges;
33     protected TimeStatisticImpl inboundExchangeRate;
34     protected TimeStatisticImpl outboundExchangeRate;
35
36     /**
37      * Default Constructor
38      * @param componentName
39      */

40     public MessagingStats(String JavaDoc componentName) {
41         this.componentName = componentName;
42         inboundExchanges = new CountStatisticImpl("inboundExchanges", "Number of Inbound MessageExchanges");
43         outboundExchanges = new CountStatisticImpl("outboundExchanges", "Number of Outbound MessageExchanges");
44         inboundExchangeRate = new TimeStatisticImpl("inboundExchangeRate", "time taken to process an Exchange");
45         outboundExchangeRate = new TimeStatisticImpl("outboundExchangeRate", "time taken to send an Exchange");
46         addStatistic("inboundExchanges", inboundExchanges);
47         addStatistic("outboundExchanges", outboundExchanges);
48         addStatistic("inboundExchangeRate", inboundExchangeRate);
49         addStatistic("outboundExchangeRate", outboundExchangeRate);
50     }
51     
52     /**
53      * @return Returns the componentName.
54      */

55     public String JavaDoc getComponentName() {
56         return componentName;
57     }
58     /**
59      * @return Returns the inboundExchangeRate.
60      */

61     public TimeStatisticImpl getInboundExchangeRate() {
62         return inboundExchangeRate;
63     }
64     /**
65      * @return Returns the inboundExchanges.
66      */

67     public CountStatisticImpl getInboundExchanges() {
68         return inboundExchanges;
69     }
70     /**
71      * @return Returns the outboundExchangeRate.
72      */

73     public TimeStatisticImpl getOutboundExchangeRate() {
74         return outboundExchangeRate;
75     }
76     /**
77      * @return Returns the outboundExchanges.
78      */

79     public CountStatisticImpl getOutboundExchanges() {
80         return outboundExchanges;
81     }
82
83     /**
84      * reset the Stats
85      */

86     public synchronized void reset() {
87         super.reset();
88         inboundExchanges.reset();
89         outboundExchanges.reset();
90         inboundExchangeRate.reset();
91         outboundExchangeRate.reset();
92     }
93
94     /**
95      * @return pretty print
96      */

97     public String JavaDoc toString() {
98         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
99         buffer.append("Component: ");
100         buffer.append(componentName);
101         buffer.append(" { ");
102         buffer.append(inboundExchanges);
103         buffer.append(" ");
104         buffer.append(inboundExchangeRate);
105         buffer.append(" ");
106         buffer.append(outboundExchanges);
107         buffer.append(" ");
108         buffer.append(outboundExchangeRate);
109         buffer.append(" }");
110         return buffer.toString();
111     }
112
113     /**
114      * Dump out to an IndentPrinter
115      *
116      * @param out
117      */

118     public void dump(IndentPrinter out) {
119         out.printIndent();
120         out.println("Component: ");
121         out.print(componentName);
122         out.println(" {");
123         out.incrementIndent();
124         out.println(inboundExchanges);
125         out.printIndent();
126         out.println(inboundExchangeRate);
127         out.printIndent();
128         out.println(outboundExchanges);
129         out.printIndent();
130         out.decrementIndent();
131         out.printIndent();
132         out.println("}");
133     }
134     
135 }
Popular Tags