KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > framework > ComponentStats


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.framework;
18
19 import javax.management.JMException JavaDoc;
20 import javax.management.MBeanAttributeInfo JavaDoc;
21 import javax.management.MBeanOperationInfo JavaDoc;
22
23 import org.apache.servicemix.jbi.management.AttributeInfoHelper;
24 import org.apache.servicemix.jbi.management.BaseLifeCycle;
25 import org.apache.servicemix.jbi.management.OperationInfoHelper;
26
27 /**
28  * Defines basic statistics on the Component
29  */

30 public class ComponentStats extends BaseLifeCycle implements ComponentStatsMBean {
31
32     private ComponentMBeanImpl component;
33
34     /**
35      * Constructor
36      *
37      * @param lcc
38      */

39     public ComponentStats(ComponentMBeanImpl component) {
40         this.component = component;
41     }
42
43     /**
44      * Get the type of the item
45      * @return the type
46      */

47     public String JavaDoc getType() {
48         return "Component";
49     }
50
51     public String JavaDoc getSubType() {
52         return "Statistics";
53     }
54
55     /**
56      * Get the name of the item
57      * @return the name
58      */

59     public String JavaDoc getName() {
60         return component.getName();
61     }
62
63     /**
64      * Get the Description of the item
65      * @return the description
66      */

67     public String JavaDoc getDescription() {
68         return "Statistics for " + component.getDescription();
69     }
70
71     /**
72      * Get the Inbound MessageExchange count
73      *
74      * @return inbound count
75      */

76     public long getInboundExchangeCount() {
77         return component.getMessagingStats().getInboundExchanges().getCount();
78     }
79
80     /**
81      * Get the Inbound MessageExchange rate (number/sec)
82      *
83      * @return the inbound exchange rate
84      */

85     public double getInboundExchangeRate() {
86         return component.getMessagingStats().getInboundExchangeRate().getAverageTime();
87     }
88
89     /**
90      * Get the Outbound MessageExchange count
91      *
92      * @return outbound count
93      */

94     public long getOutboundExchangeCount() {
95         return component.getMessagingStats().getOutboundExchanges().getCount();
96     }
97
98     /**
99      * Get the Outbound MessageExchange rate (number/sec)
100      *
101      * @return the outbound exchange rate
102      */

103     public double getOutboundExchangeRate() {
104         return component.getMessagingStats().getOutboundExchangeRate().getAverageTime();
105     }
106
107     /**
108      * @return size of the inbound Queue
109      */

110     public int getInboundQueueSize() {
111         if (component.getDeliveryChannel() != null) {
112             return component.getDeliveryChannel().getQueueSize();
113         } else {
114             return 0;
115         }
116     }
117
118     /**
119      * Reset all stats counters
120      */

121     public void reset() {
122         component.getMessagingStats().reset();
123     }
124
125     /**
126      * Get an array of MBeanAttributeInfo
127      *
128      * @return array of AttributeInfos
129      * @throws JMException
130      */

131     public MBeanAttributeInfo JavaDoc[] getAttributeInfos() throws JMException JavaDoc {
132         AttributeInfoHelper helper = new AttributeInfoHelper();
133         helper.addAttribute(getObjectToManage(), "inboundQueueSize", "size of the inbound queue");
134         helper.addAttribute(getObjectToManage(), "inboundExchangeCount", "count of inbound exchanges");
135         helper.addAttribute(getObjectToManage(), "outboundExchangeCount", "count of outbound exchanges");
136         helper.addAttribute(getObjectToManage(), "inboundExchangeRate", "rate of inbound exchanges/sec");
137         helper.addAttribute(getObjectToManage(), "outboundExchangeRate", "rate of outbound exchanges/sec");
138         return helper.getAttributeInfos();
139     }
140
141     /**
142      * Get an array of MBeanOperationInfo
143      *
144      * @return array of OperationInfos
145      */

146     public MBeanOperationInfo JavaDoc[] getOperationInfos() {
147         OperationInfoHelper helper = new OperationInfoHelper();
148         helper.addOperation(getObjectToManage(), "reset", "reset statistic counters");
149         return helper.getOperationInfos();
150     }
151
152 }
153
Popular Tags