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.ActiveMQSession;
023 import org.activemq.util.IndentPrinter;
024 import javax.management.j2ee.statistics.Statistic;
025 /**
026 * Statistics for a JMS connection
027 *
028 * @version $Revision: 1.1.1.1 $
029 */
030 public class JMSConnectionStatsImpl extends StatsImpl {
031 private List sessions;
032 private boolean transactional;
033
034 public JMSConnectionStatsImpl(List sessions, boolean transactional) {
035 this.sessions = sessions;
036 this.transactional = transactional;
037 }
038
039 public JMSSessionStatsImpl[] getSessions() {
040 // lets make a snapshot before we process them
041 Object[] sessionArray = sessions.toArray();
042 int size = sessionArray.length;
043 JMSSessionStatsImpl[] answer = new JMSSessionStatsImpl[size];
044 for (int i = 0; i < size; i++) {
045 ActiveMQSession session = (ActiveMQSession) sessionArray[i];
046 answer[i] = session.getSessionStats();
047 }
048 return answer;
049 }
050
051 public void reset() {
052 super.reset();
053 JMSSessionStatsImpl[] stats = getSessions();
054 for (int i = 0, size = stats.length; i < size; i++) {
055 Statistic stat = (Statistic) stats[i];
056 if (stat instanceof Resettable) {
057 Resettable r = (Resettable) stat;
058 r.reset();
059 }
060 }
061 }
062
063
064 public boolean isTransactional() {
065 return transactional;
066 }
067
068 public String toString() {
069 StringBuffer buffer = new StringBuffer("connection{ ");
070 JMSSessionStatsImpl[] array = getSessions();
071 for (int i = 0; i < array.length; i++) {
072 if (i > 0) {
073 buffer.append(", ");
074 }
075 buffer.append(Integer.toString(i));
076 buffer.append(" = ");
077 buffer.append(array[i]);
078 }
079 buffer.append(" }");
080 return buffer.toString();
081 }
082
083 public void dump(IndentPrinter out) {
084 out.printIndent();
085 out.println("connection {");
086 out.incrementIndent();
087 JMSSessionStatsImpl[] array = getSessions();
088 for (int i = 0; i < array.length; i++) {
089 JMSSessionStatsImpl sessionStat = (JMSSessionStatsImpl) array[i];
090 out.printIndent();
091 out.println("session {");
092 out.incrementIndent();
093 sessionStat.dump(out);
094 out.decrementIndent();
095 out.printIndent();
096 out.println("}");
097 }
098 out.decrementIndent();
099 out.printIndent();
100 out.println("}");
101 out.flush();
102 }
103 }