KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.activemq.ActiveMQSession;
21 import org.apache.activemq.util.IndentPrinter;
22
23 import java.util.List JavaDoc;
24 /**
25  * Statistics for a JMS connection
26  *
27  * @version $Revision: 1.2 $
28  */

29 public class JMSConnectionStatsImpl extends StatsImpl {
30     private List JavaDoc sessions;
31     private boolean transactional;
32
33     public JMSConnectionStatsImpl(List JavaDoc sessions, boolean transactional) {
34         this.sessions = sessions;
35         this.transactional = transactional;
36     }
37
38     public JMSSessionStatsImpl[] getSessions() {
39         // lets make a snapshot before we process them
40
Object JavaDoc[] sessionArray = sessions.toArray();
41         int size = sessionArray.length;
42         JMSSessionStatsImpl[] answer = new JMSSessionStatsImpl[size];
43         for (int i = 0; i < size; i++) {
44             ActiveMQSession session = (ActiveMQSession) sessionArray[i];
45             answer[i] = session.getSessionStats();
46         }
47         return answer;
48     }
49
50     public void reset() {
51         super.reset();
52         JMSSessionStatsImpl[] stats = getSessions();
53         for (int i = 0, size = stats.length; i < size; i++) {
54             stats[i].reset();
55         }
56     }
57     
58     /**
59      * @param enabled the enabled to set
60      */

61     public void setEnabled(boolean enabled){
62         super.setEnabled(enabled);
63         JMSSessionStatsImpl[] stats = getSessions();
64         for (int i = 0, size = stats.length; i < size; i++) {
65             stats[i].setEnabled(enabled);
66         }
67         
68     }
69
70
71     public boolean isTransactional() {
72         return transactional;
73     }
74
75     public String JavaDoc toString() {
76         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("connection{ ");
77         JMSSessionStatsImpl[] array = getSessions();
78         for (int i = 0; i < array.length; i++) {
79             if (i > 0) {
80                 buffer.append(", ");
81             }
82             buffer.append(Integer.toString(i));
83             buffer.append(" = ");
84             buffer.append(array[i]);
85         }
86         buffer.append(" }");
87         return buffer.toString();
88     }
89
90     public void dump(IndentPrinter out) {
91         out.printIndent();
92         out.println("connection {");
93         out.incrementIndent();
94         JMSSessionStatsImpl[] array = getSessions();
95         for (int i = 0; i < array.length; i++) {
96             JMSSessionStatsImpl sessionStat = (JMSSessionStatsImpl) array[i];
97             out.printIndent();
98             out.println("session {");
99             out.incrementIndent();
100             sessionStat.dump(out);
101             out.decrementIndent();
102             out.printIndent();
103             out.println("}");
104         }
105         out.decrementIndent();
106         out.printIndent();
107         out.println("}");
108         out.flush();
109     }
110 }
111
Popular Tags