1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jmonit.features;
17
18 import org.jmonit.Monitor;
19 import org.jmonit.Stopwatch;
20 import org.jmonit.events.MonitoringEventBus;
21 import org.jmonit.spi.Plugin;
22
23
24
25
26 public class LocalStopwatch
27 extends Stopwatch
28 implements Plugin<Stopwatch>
29 {
30
31 private static ThreadLocal<Stopwatch> local = new ThreadLocal<Stopwatch>();
32
33 private Monitor monitor;
34
35 public void cancel()
36 {
37 local.get().cancel();
38 }
39
40 public long getElapsedTime()
41 {
42 return local.get().getElapsedTime();
43 }
44
45 public boolean isPaused()
46 {
47 return local.get().isPaused();
48 }
49
50 public boolean isStarted()
51 {
52 return local.get().isStarted();
53 }
54
55 public boolean isStoped()
56 {
57 return local.get().isStoped();
58 }
59
60 public void pause()
61 {
62 local.get().pause();
63 }
64
65 public void resume()
66 {
67 local.get().resume();
68 }
69
70 public void start()
71 {
72 Stopwatch localExecution = Stopwatch.start( monitor );
73 local.set( localExecution );
74 }
75
76 public long stop()
77 {
78 return local.get().stop();
79 }
80
81 public long stop( boolean canceled )
82 {
83 return local.get().stop( canceled );
84 }
85
86
87
88
89
90
91 public Stopwatch getFeature()
92 {
93 return this;
94 }
95
96
97
98
99
100
101 public void setMonitoringEventBus( MonitoringEventBus bus )
102 {
103
104 }
105
106
107
108
109
110
111 public void setMonitor( Monitor monitor )
112 {
113 this.monitor = monitor;
114 }
115
116 public static final org.jmonit.spi.Factory<Stopwatch> FACTORY =
117 new org.jmonit.spi.Factory<Stopwatch>()
118 {
119 public LocalStopwatch newPluginInstance()
120 {
121 return new LocalStopwatch();
122 }
123 };
124 }