aoqi@0: /* aoqi@0: * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: aoqi@0: aoqi@0: package com.sun.org.glassfish.external.statistics.impl; aoqi@0: import com.sun.org.glassfish.external.statistics.BoundaryStatistic; aoqi@0: import java.util.Map; aoqi@0: import java.lang.reflect.*; aoqi@0: aoqi@0: /** aoqi@0: * @author Sreenivas Munnangi aoqi@0: */ aoqi@0: public final class BoundaryStatisticImpl extends StatisticImpl aoqi@0: implements BoundaryStatistic, InvocationHandler { aoqi@0: aoqi@0: private final long lowerBound; aoqi@0: private final long upperBound; aoqi@0: aoqi@0: private final BoundaryStatistic bs = aoqi@0: (BoundaryStatistic) Proxy.newProxyInstance( aoqi@0: BoundaryStatistic.class.getClassLoader(), aoqi@0: new Class[] { BoundaryStatistic.class }, aoqi@0: this); aoqi@0: aoqi@0: public BoundaryStatisticImpl(long lower, long upper, String name, aoqi@0: String unit, String desc, long startTime, aoqi@0: long sampleTime) { aoqi@0: super(name, unit, desc, startTime, sampleTime); aoqi@0: upperBound = upper; aoqi@0: lowerBound = lower; aoqi@0: } aoqi@0: aoqi@0: public synchronized BoundaryStatistic getStatistic() { aoqi@0: return bs; aoqi@0: } aoqi@0: aoqi@0: public synchronized Map getStaticAsMap() { aoqi@0: Map m = super.getStaticAsMap(); aoqi@0: m.put("lowerbound", getLowerBound()); aoqi@0: m.put("upperbound", getUpperBound()); aoqi@0: return m; aoqi@0: } aoqi@0: aoqi@0: public synchronized long getLowerBound() { aoqi@0: return lowerBound; aoqi@0: } aoqi@0: aoqi@0: public synchronized long getUpperBound() { aoqi@0: return upperBound; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public synchronized void reset() { aoqi@0: super.reset(); aoqi@0: sampleTime = -1L; aoqi@0: } aoqi@0: aoqi@0: // todo: equals implementation aoqi@0: public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { aoqi@0: checkMethod(m); aoqi@0: aoqi@0: Object result; aoqi@0: try { aoqi@0: result = m.invoke(this, args); aoqi@0: } catch (InvocationTargetException e) { aoqi@0: throw e.getTargetException(); aoqi@0: } catch (Exception e) { aoqi@0: throw new RuntimeException("unexpected invocation exception: " + aoqi@0: e.getMessage()); aoqi@0: } aoqi@0: return result; aoqi@0: } aoqi@0: }