1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/org/glassfish/external/statistics/impl/RangeStatisticImpl.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,138 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.org.glassfish.external.statistics.impl; 1.30 +import com.sun.org.glassfish.external.statistics.RangeStatistic; 1.31 +import java.util.concurrent.atomic.AtomicLong; 1.32 +import java.util.Map; 1.33 +import java.lang.reflect.*; 1.34 + 1.35 +/** 1.36 + * @author Sreenivas Munnangi 1.37 + */ 1.38 +public final class RangeStatisticImpl extends StatisticImpl 1.39 + implements RangeStatistic, InvocationHandler { 1.40 + 1.41 + private long currentVal = 0L; 1.42 + private long highWaterMark = Long.MIN_VALUE; 1.43 + private long lowWaterMark = Long.MAX_VALUE; 1.44 + private final long initCurrentVal; 1.45 + private final long initHighWaterMark; 1.46 + private final long initLowWaterMark; 1.47 + 1.48 + private final RangeStatistic rs = 1.49 + (RangeStatistic) Proxy.newProxyInstance( 1.50 + RangeStatistic.class.getClassLoader(), 1.51 + new Class[] { RangeStatistic.class }, 1.52 + this); 1.53 + 1.54 + public RangeStatisticImpl(long curVal, long highMark, long lowMark, 1.55 + String name, String unit, String desc, 1.56 + long startTime, long sampleTime) { 1.57 + super(name, unit, desc, startTime, sampleTime); 1.58 + currentVal = curVal; 1.59 + initCurrentVal = curVal; 1.60 + highWaterMark = highMark; 1.61 + initHighWaterMark = highMark; 1.62 + lowWaterMark = lowMark; 1.63 + initLowWaterMark = lowMark; 1.64 + } 1.65 + 1.66 + public synchronized RangeStatistic getStatistic() { 1.67 + return rs; 1.68 + } 1.69 + 1.70 + public synchronized Map getStaticAsMap() { 1.71 + Map m = super.getStaticAsMap(); 1.72 + m.put("current", getCurrent()); 1.73 + m.put("lowwatermark", getLowWaterMark()); 1.74 + m.put("highwatermark", getHighWaterMark()); 1.75 + return m; 1.76 + } 1.77 + 1.78 + public synchronized long getCurrent() { 1.79 + return currentVal; 1.80 + } 1.81 + 1.82 + public synchronized void setCurrent(long curVal) { 1.83 + currentVal = curVal; 1.84 + lowWaterMark = (curVal >= lowWaterMark ? lowWaterMark : curVal); 1.85 + highWaterMark = (curVal >= highWaterMark ? curVal : highWaterMark); 1.86 + sampleTime = System.currentTimeMillis(); 1.87 + } 1.88 + 1.89 + /** 1.90 + * Returns the highest value of this statistic, since measurement started. 1.91 + */ 1.92 + public synchronized long getHighWaterMark() { 1.93 + return highWaterMark; 1.94 + } 1.95 + 1.96 + public synchronized void setHighWaterMark(long hwm) { 1.97 + highWaterMark = hwm; 1.98 + } 1.99 + 1.100 + /** 1.101 + * Returns the lowest value of this statistic, since measurement started. 1.102 + */ 1.103 + public synchronized long getLowWaterMark() { 1.104 + return lowWaterMark; 1.105 + } 1.106 + 1.107 + public synchronized void setLowWaterMark(long lwm) { 1.108 + lowWaterMark = lwm; 1.109 + } 1.110 + 1.111 + @Override 1.112 + public synchronized void reset() { 1.113 + super.reset(); 1.114 + currentVal = initCurrentVal; 1.115 + highWaterMark = initHighWaterMark; 1.116 + lowWaterMark = initLowWaterMark; 1.117 + sampleTime = -1L; 1.118 + } 1.119 + 1.120 + public synchronized String toString() { 1.121 + return super.toString() + NEWLINE + 1.122 + "Current: " + getCurrent() + NEWLINE + 1.123 + "LowWaterMark: " + getLowWaterMark() + NEWLINE + 1.124 + "HighWaterMark: " + getHighWaterMark(); 1.125 + } 1.126 + 1.127 + // todo: equals implementation 1.128 + public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { 1.129 + Object result; 1.130 + try { 1.131 + result = m.invoke(this, args); 1.132 + } catch (InvocationTargetException e) { 1.133 + throw e.getTargetException(); 1.134 + } catch (Exception e) { 1.135 + throw new RuntimeException("unexpected invocation exception: " + 1.136 + e.getMessage()); 1.137 + } finally { 1.138 + } 1.139 + return result; 1.140 + } 1.141 +}