001 /**
002 *
003 * Copyright 2004 Protique Ltd
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.activemq.management;
019
020 import java.util.List;
021
022 import org.activemq.ActiveMQConnection;
023 import org.activemq.util.IndentPrinter;
024
025 import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList;
026
027 /**
028 * Statistics for a number of JMS connections
029 *
030 * @version $Revision: 1.1.1.1 $
031 */
032 public class JMSStatsImpl extends StatsImpl {
033 private List connections = new CopyOnWriteArrayList();
034
035 public JMSStatsImpl() {
036 }
037
038 public JMSConnectionStatsImpl[] getConnections() {
039 Object[] connectionArray = connections.toArray();
040 int size = connectionArray.length;
041 JMSConnectionStatsImpl[] answer = new JMSConnectionStatsImpl[size];
042 for (int i = 0; i < size; i++) {
043 ActiveMQConnection connection = (ActiveMQConnection) connectionArray[i];
044 answer[i] = connection.getConnectionStats();
045 }
046 return answer;
047 }
048
049 public void addConnection(ActiveMQConnection connection) {
050 connections.add(connection);
051 }
052
053 public void removeConnection(ActiveMQConnection connection) {
054 connections.remove(connection);
055 }
056
057 public void dump(IndentPrinter out) {
058 out.printIndent();
059 out.println("factory {");
060 out.incrementIndent();
061 JMSConnectionStatsImpl[] array = getConnections();
062 for (int i = 0; i < array.length; i++) {
063 JMSConnectionStatsImpl connectionStat = (JMSConnectionStatsImpl) array[i];
064 connectionStat.dump(out);
065 }
066 out.decrementIndent();
067 out.printIndent();
068 out.println("}");
069 out.flush();
070 }
071 }