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 javax.management.j2ee.statistics.Statistic;
    21
    22  /***
    23   * Base class for a Statistic implementation
    24   *
    25   * @version $Revision: 1.1 $
    26   */
    27  public class StatisticImpl implements Statistic, Resettable {
    28      private String name;
    29      private String unit;
    30      private String description;
    31      private long startTime;
    32      private long lastSampleTime;
    33
    34      public StatisticImpl(String name, String unit, String description) {
    35          this.name = name;
    36          this.unit = unit;
    37          this.description = description;
    38          startTime = System.currentTimeMillis();
    39          lastSampleTime = startTime;
    40      }
    41
    42      public void reset() {
    43          startTime = System.currentTimeMillis();
    44          lastSampleTime = startTime;
    45      }
    46
    47      protected void updateSampleTime() {
    48          lastSampleTime = System.currentTimeMillis();
    49      }
    50
    51      public String toString() {
    52          StringBuffer buffer = new StringBuffer();
    53          buffer.append(name);
    54          buffer.append("{");
    55          appendFieldDescription(buffer);
    56          buffer.append(" }");
    57          return buffer.toString();
    58      }
    59
    60      public String getName() {
    61          return name;
    62      }
    63
    64      public String getUnit() {
    65          return unit;
    66      }
    67
    68      public String getDescription() {
    69          return description;
    70      }
    71
    72      public long getStartTime() {
    73          return startTime;
    74      }
    75
    76      public long getLastSampleTime() {
    77          return lastSampleTime;
    78      }
    79
    80      protected void appendFieldDescription(StringBuffer buffer) {
    81          buffer.append(" unit: ");
    82          buffer.append(unit);
    83          buffer.append(" startTime: ");
    84          //buffer.append(new Date(startTime));
    85          buffer.append(startTime);
    86          buffer.append(" lastSampleTime: ");
    87          //buffer.append(new Date(lastSampleTime));
    88          buffer.append(lastSampleTime);
    89          buffer.append(" description: ");
    90          buffer.append(description);
    91      }
    92  }