JMSConnectionStatsImpl xref

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