Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
1 /*
2 * Copyright (c) 1997, 2007, 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 */
26 package com.sun.org.glassfish.external.statistics.impl;
27 import com.sun.org.glassfish.external.statistics.Statistic;
28 import java.io.Serializable;
29 import java.util.concurrent.atomic.AtomicLong;
30 import java.util.Map;
31 import java.util.concurrent.ConcurrentHashMap;
33 /**
34 * @author Sreenivas Munnangi
35 */
36 public abstract class StatisticImpl implements Statistic {
38 private final String statisticName;
39 private final String statisticUnit;
40 private final String statisticDesc;
41 protected long sampleTime = -1L;
42 private long startTime;
43 public static final String UNIT_COUNT = "count";
44 public static final String UNIT_SECOND = "second";
45 public static final String UNIT_MILLISECOND = "millisecond";
46 public static final String UNIT_MICROSECOND = "microsecond";
47 public static final String UNIT_NANOSECOND = "nanosecond";
48 public static final String START_TIME = "starttime";
49 public static final String LAST_SAMPLE_TIME = "lastsampletime";
51 protected final Map<String, Object> statMap = new ConcurrentHashMap<String, Object> ();
53 protected static final String NEWLINE = System.getProperty( "line.separator" );
55 protected StatisticImpl(String name, String unit, String desc,
56 long start_time, long sample_time) {
58 if (isValidString(name)) {
59 statisticName = name;
60 } else {
61 statisticName = "name";
62 }
64 if (isValidString(unit)) {
65 statisticUnit = unit;
66 } else {
67 statisticUnit = "unit";
68 }
70 if (isValidString(desc)) {
71 statisticDesc = desc;
72 } else {
73 statisticDesc = "description";
74 }
76 startTime = start_time;
77 sampleTime = sample_time;
78 }
80 protected StatisticImpl(String name, String unit, String desc) {
81 this(name, unit, desc, System.currentTimeMillis(), System.currentTimeMillis());
82 }
84 public synchronized Map getStaticAsMap() {
85 if (isValidString(statisticName)) {
86 statMap.put("name", statisticName);
87 }
88 if (isValidString(statisticUnit)) {
89 statMap.put("unit", statisticUnit);
90 }
91 if (isValidString(statisticDesc)) {
92 statMap.put("description", statisticDesc);
93 }
94 statMap.put(StatisticImpl.START_TIME, startTime);
95 statMap.put(StatisticImpl.LAST_SAMPLE_TIME, sampleTime);
96 return statMap;
97 }
99 public String getName() {
100 return this.statisticName;
101 }
103 public String getDescription() {
104 return this.statisticDesc;
105 }
107 public String getUnit() {
108 return this.statisticUnit;
109 }
111 public synchronized long getLastSampleTime() {
112 return sampleTime;
113 }
115 public synchronized long getStartTime() {
116 return startTime;
117 }
119 public synchronized void reset() {
120 startTime = System.currentTimeMillis();
121 }
123 public synchronized String toString() {
124 return "Statistic " + getClass().getName() + NEWLINE +
125 "Name: " + getName() + NEWLINE +
126 "Description: " + getDescription() + NEWLINE +
127 "Unit: " + getUnit() + NEWLINE +
128 "LastSampleTime: " + getLastSampleTime() + NEWLINE +
129 "StartTime: " + getStartTime();
130 }
132 protected static boolean isValidString(String str) {
133 return (str!=null && str.length()>0);
134 }
135 }