View Javadoc

1   /*** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * 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   **/
18  package org.codehaus.activemq.management;
19  
20  import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList;
21  import org.codehaus.activemq.ActiveMQConnection;
22  import org.codehaus.activemq.util.IndentPrinter;
23  
24  import javax.management.j2ee.statistics.JMSConnectionStats;
25  import javax.management.j2ee.statistics.JMSStats;
26  import java.util.List;
27  
28  /***
29   * Statistics for a number of JMS connections
30   *
31   * @version $Revision: 1.2 $
32   */
33  public class JMSStatsImpl extends StatsImpl implements JMSStats {
34      private List connections = new CopyOnWriteArrayList();
35  
36      public JMSStatsImpl() {
37      }
38  
39      public JMSConnectionStats[] getConnections() {
40          Object[] connectionArray = connections.toArray();
41          int size = connectionArray.length;
42          JMSConnectionStats[] answer = new JMSConnectionStats[size];
43          for (int i = 0; i < size; i++) {
44              ActiveMQConnection connection = (ActiveMQConnection) connectionArray[i];
45              answer[i] = connection.getConnectionStats();
46          }
47          return answer;
48      }
49  
50      public void addConnection(ActiveMQConnection connection) {
51          connections.add(connection);
52      }
53  
54      public void removeConnection(ActiveMQConnection connection) {
55          connections.remove(connection);
56      }
57  
58      public void dump(IndentPrinter out) {
59          out.printIndent();
60          out.println("factory {");
61          out.incrementIndent();
62          JMSConnectionStats[] array = getConnections();
63          for (int i = 0; i < array.length; i++) {
64              JMSConnectionStatsImpl connectionStat = (JMSConnectionStatsImpl) array[i];
65              connectionStat.dump(out);
66          }
67          out.decrementIndent();
68          out.printIndent();
69          out.println("}");
70          out.flush();
71      }
72  }