001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. 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 */ 017package org.apache.activemq.management; 018 019 020/** 021 * A range statistic implementation 022 * 023 * 024 */ 025public class RangeStatisticImpl extends StatisticImpl { 026 private long highWaterMark; 027 private long lowWaterMark; 028 private long current; 029 030 public RangeStatisticImpl(String name, String unit, String description) { 031 super(name, unit, description); 032 } 033 034 public void reset() { 035 if (isDoReset()) { 036 super.reset(); 037 current = 0; 038 lowWaterMark = 0; 039 highWaterMark = 0; 040 } 041 } 042 043 public long getHighWaterMark() { 044 return highWaterMark; 045 } 046 047 public long getLowWaterMark() { 048 return lowWaterMark; 049 } 050 051 public long getCurrent() { 052 return current; 053 } 054 055 public void setCurrent(long current) { 056 this.current = current; 057 if (current > highWaterMark) { 058 highWaterMark = current; 059 } 060 if (current < lowWaterMark || lowWaterMark == 0) { 061 lowWaterMark = current; 062 } 063 updateSampleTime(); 064 } 065 066 protected void appendFieldDescription(StringBuffer buffer) { 067 buffer.append(" current: "); 068 buffer.append(Long.toString(current)); 069 buffer.append(" lowWaterMark: "); 070 buffer.append(Long.toString(lowWaterMark)); 071 buffer.append(" highWaterMark: "); 072 buffer.append(Long.toString(highWaterMark)); 073 super.appendFieldDescription(buffer); 074 } 075}