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.StringStatistic;
28 import java.util.Map;
29 import java.lang.reflect.*;
31 /**
32 * @author Sreenivas Munnangi
33 */
34 public final class StringStatisticImpl extends StatisticImpl
35 implements StringStatistic, InvocationHandler {
37 private volatile String str = null;
38 private final String initStr;
40 private final StringStatistic ss =
41 (StringStatistic) Proxy.newProxyInstance(
42 StringStatistic.class.getClassLoader(),
43 new Class[] { StringStatistic.class },
44 this);
46 public StringStatisticImpl(String str, String name, String unit,
47 String desc, long sampleTime, long startTime) {
48 super(name, unit, desc, startTime, sampleTime);
49 this.str = str;
50 initStr = str;
51 }
53 public StringStatisticImpl(String name, String unit, String desc) {
54 this("", name, unit, desc, System.currentTimeMillis(), System.currentTimeMillis());
55 }
57 public synchronized StringStatistic getStatistic() {
58 return ss;
59 }
61 public synchronized Map getStaticAsMap() {
62 Map m = super.getStaticAsMap();
63 if (getCurrent() != null) {
64 m.put("current", getCurrent());
65 }
66 return m;
67 }
69 public synchronized String toString() {
70 return super.toString() + NEWLINE + "Current-value: " + getCurrent();
71 }
73 public String getCurrent() {
74 return str;
75 }
77 public void setCurrent(String str) {
78 this.str = str;
79 sampleTime = System.currentTimeMillis();
80 }
82 @Override
83 public synchronized void reset() {
84 super.reset();
85 this.str = initStr;
86 sampleTime = -1L;
87 }
89 // todo: equals implementation
90 public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
91 Object result;
92 try {
93 result = m.invoke(this, args);
94 } catch (InvocationTargetException e) {
95 throw e.getTargetException();
96 } catch (Exception e) {
97 throw new RuntimeException("unexpected invocation exception: " +
98 e.getMessage());
99 } finally {
100 }
101 return result;
102 }
103 }