KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > management > JMSStatsImpl


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

18 package org.apache.activemq.management;
19
20 import java.util.List JavaDoc;
21
22 import org.apache.activemq.ActiveMQConnection;
23 import org.apache.activemq.util.IndentPrinter;
24
25 import java.util.concurrent.CopyOnWriteArrayList JavaDoc;
26
27 /**
28  * Statistics for a number of JMS connections
29  *
30  * @version $Revision: 1.2 $
31  */

32 public class JMSStatsImpl extends StatsImpl {
33     private List JavaDoc connections = new CopyOnWriteArrayList JavaDoc();
34
35     public JMSStatsImpl() {
36     }
37
38     public JMSConnectionStatsImpl[] getConnections() {
39         Object JavaDoc[] connectionArray = connections.toArray();
40         int size = connectionArray.length;
41         JMSConnectionStatsImpl[] answer = new JMSConnectionStatsImpl[size];
42         for (int i = 0; i < size; i++) {
43             ActiveMQConnection connection = (ActiveMQConnection) connectionArray[i];
44             answer[i] = connection.getConnectionStats();
45         }
46         return answer;
47     }
48
49     public void addConnection(ActiveMQConnection connection) {
50         connections.add(connection);
51     }
52
53     public void removeConnection(ActiveMQConnection connection) {
54         connections.remove(connection);
55     }
56
57     public void dump(IndentPrinter out) {
58         out.printIndent();
59         out.println("factory {");
60         out.incrementIndent();
61         JMSConnectionStatsImpl[] array = getConnections();
62         for (int i = 0; i < array.length; i++) {
63             JMSConnectionStatsImpl connectionStat = (JMSConnectionStatsImpl) array[i];
64             connectionStat.dump(out);
65         }
66         out.decrementIndent();
67         out.printIndent();
68         out.println("}");
69         out.flush();
70     }
71     
72     /**
73      * @param enabled the enabled to set
74      */

75     public void setEnabled(boolean enabled){
76         super.setEnabled(enabled);
77         JMSConnectionStatsImpl[] stats = getConnections();
78         for (int i = 0, size = stats.length; i < size; i++) {
79             stats[i].setEnabled(enabled);
80         }
81         
82     }
83 }
84
Popular Tags