src/share/jaxws_classes/com/sun/org/glassfish/external/statistics/impl/RangeStatisticImpl.java

Print this page


   1 /*
   2  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 
  28 package com.sun.org.glassfish.external.statistics.impl;
  29 import com.sun.org.glassfish.external.statistics.RangeStatistic;
  30 import java.util.concurrent.atomic.AtomicLong;
  31 import java.util.Map;
  32 import java.lang.reflect.*;
  33 
  34 /**
  35  * @author Sreenivas Munnangi
  36  */
  37 public final class RangeStatisticImpl extends StatisticImpl
  38     implements RangeStatistic, InvocationHandler {
  39 
  40     private long currentVal = 0L;
  41     private long highWaterMark = Long.MIN_VALUE;
  42     private long lowWaterMark = Long.MAX_VALUE;
  43     private final long initCurrentVal;
  44     private final long initHighWaterMark;
  45     private final long initLowWaterMark;
  46 
  47     private final RangeStatistic rs =
  48             (RangeStatistic) Proxy.newProxyInstance(
  49             RangeStatistic.class.getClassLoader(),
  50             new Class[] { RangeStatistic.class },


 108     }
 109 
 110     @Override
 111     public synchronized void reset() {
 112         super.reset();
 113         currentVal = initCurrentVal;
 114         highWaterMark = initHighWaterMark;
 115         lowWaterMark = initLowWaterMark;
 116         sampleTime = -1L;
 117     }
 118 
 119     public synchronized String toString() {
 120         return super.toString() + NEWLINE +
 121             "Current: " + getCurrent() + NEWLINE +
 122             "LowWaterMark: " + getLowWaterMark() + NEWLINE +
 123             "HighWaterMark: " + getHighWaterMark();
 124     }
 125 
 126     // todo: equals implementation
 127     public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {


 128         Object result;
 129         try {
 130             result = m.invoke(this, args);
 131         } catch (InvocationTargetException e) {
 132             throw e.getTargetException();
 133         } catch (Exception e) {
 134             throw new RuntimeException("unexpected invocation exception: " +
 135                        e.getMessage());
 136         } finally {
 137         }
 138         return result;
 139     }
 140 }
   1 /*
   2  * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 
  28 package com.sun.org.glassfish.external.statistics.impl;
  29 import com.sun.org.glassfish.external.statistics.RangeStatistic;

  30 import java.util.Map;
  31 import java.lang.reflect.*;
  32 
  33 /**
  34  * @author Sreenivas Munnangi
  35  */
  36 public final class RangeStatisticImpl extends StatisticImpl
  37     implements RangeStatistic, InvocationHandler {
  38 
  39     private long currentVal = 0L;
  40     private long highWaterMark = Long.MIN_VALUE;
  41     private long lowWaterMark = Long.MAX_VALUE;
  42     private final long initCurrentVal;
  43     private final long initHighWaterMark;
  44     private final long initLowWaterMark;
  45 
  46     private final RangeStatistic rs =
  47             (RangeStatistic) Proxy.newProxyInstance(
  48             RangeStatistic.class.getClassLoader(),
  49             new Class[] { RangeStatistic.class },


 107     }
 108 
 109     @Override
 110     public synchronized void reset() {
 111         super.reset();
 112         currentVal = initCurrentVal;
 113         highWaterMark = initHighWaterMark;
 114         lowWaterMark = initLowWaterMark;
 115         sampleTime = -1L;
 116     }
 117 
 118     public synchronized String toString() {
 119         return super.toString() + NEWLINE +
 120             "Current: " + getCurrent() + NEWLINE +
 121             "LowWaterMark: " + getLowWaterMark() + NEWLINE +
 122             "HighWaterMark: " + getHighWaterMark();
 123     }
 124 
 125     // todo: equals implementation
 126     public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 127         checkMethod(m);
 128 
 129         Object result;
 130         try {
 131             result = m.invoke(this, args);
 132         } catch (InvocationTargetException e) {
 133             throw e.getTargetException();
 134         } catch (Exception e) {
 135             throw new RuntimeException("unexpected invocation exception: " +
 136                        e.getMessage());

 137         }
 138         return result;
 139     }
 140 }