src/share/jaxws_classes/com/sun/org/glassfish/external/statistics/impl/TimeStatisticImpl.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 
  30 import com.sun.org.glassfish.external.statistics.TimeStatistic;
  31 import java.util.concurrent.atomic.AtomicLong;
  32 import java.util.Map;
  33 import java.lang.reflect.*;
  34 
  35 /**
  36  * @author Sreenivas Munnangi
  37  */
  38 public final class TimeStatisticImpl extends StatisticImpl
  39     implements TimeStatistic, InvocationHandler {
  40 
  41     private long count = 0L;
  42     private long maxTime = 0L;
  43     private long minTime = 0L;
  44     private long totTime = 0L;
  45     private final long initCount;
  46     private final long initMaxTime;
  47     private final long initMinTime;
  48     private final long initTotTime;
  49 
  50     private final TimeStatistic ts =
  51             (TimeStatistic) Proxy.newProxyInstance(


 128     /**
 129      * Returns the amount of time that it took for all invocations,
 130      * since measurement started.
 131      */
 132     public synchronized long getTotalTime() {
 133         return totTime;
 134     }
 135 
 136     @Override
 137     public synchronized void reset() {
 138         super.reset();
 139         count = initCount;
 140         maxTime = initMaxTime;
 141         minTime = initMinTime;
 142         totTime = initTotTime;
 143         sampleTime = -1L;
 144     }
 145 
 146     // todo: equals implementation
 147     public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {


 148         Object result;
 149         try {
 150             result = m.invoke(this, args);
 151         } catch (InvocationTargetException e) {
 152             throw e.getTargetException();
 153         } catch (Exception e) {
 154             throw new RuntimeException("unexpected invocation exception: " +
 155                        e.getMessage());
 156         } finally {
 157         }
 158         return result;
 159     }
 160 }
   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 
  30 import com.sun.org.glassfish.external.statistics.TimeStatistic;

  31 import java.util.Map;
  32 import java.lang.reflect.*;
  33 
  34 /**
  35  * @author Sreenivas Munnangi
  36  */
  37 public final class TimeStatisticImpl extends StatisticImpl
  38     implements TimeStatistic, InvocationHandler {
  39 
  40     private long count = 0L;
  41     private long maxTime = 0L;
  42     private long minTime = 0L;
  43     private long totTime = 0L;
  44     private final long initCount;
  45     private final long initMaxTime;
  46     private final long initMinTime;
  47     private final long initTotTime;
  48 
  49     private final TimeStatistic ts =
  50             (TimeStatistic) Proxy.newProxyInstance(


 127     /**
 128      * Returns the amount of time that it took for all invocations,
 129      * since measurement started.
 130      */
 131     public synchronized long getTotalTime() {
 132         return totTime;
 133     }
 134 
 135     @Override
 136     public synchronized void reset() {
 137         super.reset();
 138         count = initCount;
 139         maxTime = initMaxTime;
 140         minTime = initMinTime;
 141         totTime = initTotTime;
 142         sampleTime = -1L;
 143     }
 144 
 145     // todo: equals implementation
 146     public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
 147         checkMethod(m);
 148 
 149         Object result;
 150         try {
 151             result = m.invoke(this, args);
 152         } catch (InvocationTargetException e) {
 153             throw e.getTargetException();
 154         } catch (Exception e) {
 155             throw new RuntimeException("unexpected invocation exception: " +
 156                        e.getMessage());

 157         }
 158         return result;
 159     }
 160 }