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 Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,140 @@ 1.4 +/* 1.5 + * Copyright (c) 2009, 2013, 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 + 1.30 + 1.31 +package com.sun.org.glassfish.external.statistics.impl; 1.32 +import com.sun.org.glassfish.external.statistics.RangeStatistic; 1.33 +import java.util.Map; 1.34 +import java.lang.reflect.*; 1.35 + 1.36 +/** 1.37 + * @author Sreenivas Munnangi 1.38 + */ 1.39 +public final class RangeStatisticImpl extends StatisticImpl 1.40 + implements RangeStatistic, InvocationHandler { 1.41 + 1.42 + private long currentVal = 0L; 1.43 + private long highWaterMark = Long.MIN_VALUE; 1.44 + private long lowWaterMark = Long.MAX_VALUE; 1.45 + private final long initCurrentVal; 1.46 + private final long initHighWaterMark; 1.47 + private final long initLowWaterMark; 1.48 + 1.49 + private final RangeStatistic rs = 1.50 + (RangeStatistic) Proxy.newProxyInstance( 1.51 + RangeStatistic.class.getClassLoader(), 1.52 + new Class[] { RangeStatistic.class }, 1.53 + this); 1.54 + 1.55 + public RangeStatisticImpl(long curVal, long highMark, long lowMark, 1.56 + String name, String unit, String desc, 1.57 + long startTime, long sampleTime) { 1.58 + super(name, unit, desc, startTime, sampleTime); 1.59 + currentVal = curVal; 1.60 + initCurrentVal = curVal; 1.61 + highWaterMark = highMark; 1.62 + initHighWaterMark = highMark; 1.63 + lowWaterMark = lowMark; 1.64 + initLowWaterMark = lowMark; 1.65 + } 1.66 + 1.67 + public synchronized RangeStatistic getStatistic() { 1.68 + return rs; 1.69 + } 1.70 + 1.71 + public synchronized Map getStaticAsMap() { 1.72 + Map m = super.getStaticAsMap(); 1.73 + m.put("current", getCurrent()); 1.74 + m.put("lowwatermark", getLowWaterMark()); 1.75 + m.put("highwatermark", getHighWaterMark()); 1.76 + return m; 1.77 + } 1.78 + 1.79 + public synchronized long getCurrent() { 1.80 + return currentVal; 1.81 + } 1.82 + 1.83 + public synchronized void setCurrent(long curVal) { 1.84 + currentVal = curVal; 1.85 + lowWaterMark = (curVal >= lowWaterMark ? lowWaterMark : curVal); 1.86 + highWaterMark = (curVal >= highWaterMark ? curVal : highWaterMark); 1.87 + sampleTime = System.currentTimeMillis(); 1.88 + } 1.89 + 1.90 + /** 1.91 + * Returns the highest value of this statistic, since measurement started. 1.92 + */ 1.93 + public synchronized long getHighWaterMark() { 1.94 + return highWaterMark; 1.95 + } 1.96 + 1.97 + public synchronized void setHighWaterMark(long hwm) { 1.98 + highWaterMark = hwm; 1.99 + } 1.100 + 1.101 + /** 1.102 + * Returns the lowest value of this statistic, since measurement started. 1.103 + */ 1.104 + public synchronized long getLowWaterMark() { 1.105 + return lowWaterMark; 1.106 + } 1.107 + 1.108 + public synchronized void setLowWaterMark(long lwm) { 1.109 + lowWaterMark = lwm; 1.110 + } 1.111 + 1.112 + @Override 1.113 + public synchronized void reset() { 1.114 + super.reset(); 1.115 + currentVal = initCurrentVal; 1.116 + highWaterMark = initHighWaterMark; 1.117 + lowWaterMark = initLowWaterMark; 1.118 + sampleTime = -1L; 1.119 + } 1.120 + 1.121 + public synchronized String toString() { 1.122 + return super.toString() + NEWLINE + 1.123 + "Current: " + getCurrent() + NEWLINE + 1.124 + "LowWaterMark: " + getLowWaterMark() + NEWLINE + 1.125 + "HighWaterMark: " + getHighWaterMark(); 1.126 + } 1.127 + 1.128 + // todo: equals implementation 1.129 + public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { 1.130 + checkMethod(m); 1.131 + 1.132 + Object result; 1.133 + try { 1.134 + result = m.invoke(this, args); 1.135 + } catch (InvocationTargetException e) { 1.136 + throw e.getTargetException(); 1.137 + } catch (Exception e) { 1.138 + throw new RuntimeException("unexpected invocation exception: " + 1.139 + e.getMessage()); 1.140 + } 1.141 + return result; 1.142 + } 1.143 +}