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/StatisticImpl.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,135 @@ 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.Statistic; 1.31 +import java.io.Serializable; 1.32 +import java.util.concurrent.atomic.AtomicLong; 1.33 +import java.util.Map; 1.34 +import java.util.concurrent.ConcurrentHashMap; 1.35 + 1.36 +/** 1.37 + * @author Sreenivas Munnangi 1.38 + */ 1.39 +public abstract class StatisticImpl implements Statistic { 1.40 + 1.41 + private final String statisticName; 1.42 + private final String statisticUnit; 1.43 + private final String statisticDesc; 1.44 + protected long sampleTime = -1L; 1.45 + private long startTime; 1.46 + public static final String UNIT_COUNT = "count"; 1.47 + public static final String UNIT_SECOND = "second"; 1.48 + public static final String UNIT_MILLISECOND = "millisecond"; 1.49 + public static final String UNIT_MICROSECOND = "microsecond"; 1.50 + public static final String UNIT_NANOSECOND = "nanosecond"; 1.51 + public static final String START_TIME = "starttime"; 1.52 + public static final String LAST_SAMPLE_TIME = "lastsampletime"; 1.53 + 1.54 + protected final Map<String, Object> statMap = new ConcurrentHashMap<String, Object> (); 1.55 + 1.56 + protected static final String NEWLINE = System.getProperty( "line.separator" ); 1.57 + 1.58 + protected StatisticImpl(String name, String unit, String desc, 1.59 + long start_time, long sample_time) { 1.60 + 1.61 + if (isValidString(name)) { 1.62 + statisticName = name; 1.63 + } else { 1.64 + statisticName = "name"; 1.65 + } 1.66 + 1.67 + if (isValidString(unit)) { 1.68 + statisticUnit = unit; 1.69 + } else { 1.70 + statisticUnit = "unit"; 1.71 + } 1.72 + 1.73 + if (isValidString(desc)) { 1.74 + statisticDesc = desc; 1.75 + } else { 1.76 + statisticDesc = "description"; 1.77 + } 1.78 + 1.79 + startTime = start_time; 1.80 + sampleTime = sample_time; 1.81 + } 1.82 + 1.83 + protected StatisticImpl(String name, String unit, String desc) { 1.84 + this(name, unit, desc, System.currentTimeMillis(), System.currentTimeMillis()); 1.85 + } 1.86 + 1.87 + public synchronized Map getStaticAsMap() { 1.88 + if (isValidString(statisticName)) { 1.89 + statMap.put("name", statisticName); 1.90 + } 1.91 + if (isValidString(statisticUnit)) { 1.92 + statMap.put("unit", statisticUnit); 1.93 + } 1.94 + if (isValidString(statisticDesc)) { 1.95 + statMap.put("description", statisticDesc); 1.96 + } 1.97 + statMap.put(StatisticImpl.START_TIME, startTime); 1.98 + statMap.put(StatisticImpl.LAST_SAMPLE_TIME, sampleTime); 1.99 + return statMap; 1.100 + } 1.101 + 1.102 + public String getName() { 1.103 + return this.statisticName; 1.104 + } 1.105 + 1.106 + public String getDescription() { 1.107 + return this.statisticDesc; 1.108 + } 1.109 + 1.110 + public String getUnit() { 1.111 + return this.statisticUnit; 1.112 + } 1.113 + 1.114 + public synchronized long getLastSampleTime() { 1.115 + return sampleTime; 1.116 + } 1.117 + 1.118 + public synchronized long getStartTime() { 1.119 + return startTime; 1.120 + } 1.121 + 1.122 + public synchronized void reset() { 1.123 + startTime = System.currentTimeMillis(); 1.124 + } 1.125 + 1.126 + public synchronized String toString() { 1.127 + return "Statistic " + getClass().getName() + NEWLINE + 1.128 + "Name: " + getName() + NEWLINE + 1.129 + "Description: " + getDescription() + NEWLINE + 1.130 + "Unit: " + getUnit() + NEWLINE + 1.131 + "LastSampleTime: " + getLastSampleTime() + NEWLINE + 1.132 + "StartTime: " + getStartTime(); 1.133 + } 1.134 + 1.135 + protected static boolean isValidString(String str) { 1.136 + return (str!=null && str.length()>0); 1.137 + } 1.138 +}