Source code: org/activemq/management/JMSConnectionStatsImpl.java
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.activemq.management;
19
20 import java.util.List;
21
22 import org.activemq.ActiveMQSession;
23 import org.activemq.util.IndentPrinter;
24 import javax.management.j2ee.statistics.Statistic;
25 /**
26 * Statistics for a JMS connection
27 *
28 * @version $Revision: 1.1.1.1 $
29 */
30 public class JMSConnectionStatsImpl extends StatsImpl {
31 private List sessions;
32 private boolean transactional;
33
34 public JMSConnectionStatsImpl(List sessions, boolean transactional) {
35 this.sessions = sessions;
36 this.transactional = transactional;
37 }
38
39 public JMSSessionStatsImpl[] getSessions() {
40 // lets make a snapshot before we process them
41 Object[] sessionArray = sessions.toArray();
42 int size = sessionArray.length;
43 JMSSessionStatsImpl[] answer = new JMSSessionStatsImpl[size];
44 for (int i = 0; i < size; i++) {
45 ActiveMQSession session = (ActiveMQSession) sessionArray[i];
46 answer[i] = session.getSessionStats();
47 }
48 return answer;
49 }
50
51 public void reset() {
52 super.reset();
53 JMSSessionStatsImpl[] stats = getSessions();
54 for (int i = 0, size = stats.length; i < size; i++) {
55 Statistic stat = (Statistic) stats[i];
56 if (stat instanceof Resettable) {
57 Resettable r = (Resettable) stat;
58 r.reset();
59 }
60 }
61 }
62
63
64 public boolean isTransactional() {
65 return transactional;
66 }
67
68 public String toString() {
69 StringBuffer buffer = new StringBuffer("connection{ ");
70 JMSSessionStatsImpl[] array = getSessions();
71 for (int i = 0; i < array.length; i++) {
72 if (i > 0) {
73 buffer.append(", ");
74 }
75 buffer.append(Integer.toString(i));
76 buffer.append(" = ");
77 buffer.append(array[i]);
78 }
79 buffer.append(" }");
80 return buffer.toString();
81 }
82
83 public void dump(IndentPrinter out) {
84 out.printIndent();
85 out.println("connection {");
86 out.incrementIndent();
87 JMSSessionStatsImpl[] array = getSessions();
88 for (int i = 0; i < array.length; i++) {
89 JMSSessionStatsImpl sessionStat = (JMSSessionStatsImpl) array[i];
90 out.printIndent();
91 out.println("session {");
92 out.incrementIndent();
93 sessionStat.dump(out);
94 out.decrementIndent();
95 out.printIndent();
96 out.println("}");
97 }
98 out.decrementIndent();
99 out.printIndent();
100 out.println("}");
101 out.flush();
102 }
103 }