My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.javasimon.examples;

import org.javasimon.SimonManager;
import org.javasimon.StopwatchSample;
import org.javasimon.callback.CallbackSkeleton;
import org.javasimon.Split;
import org.javasimon.Stopwatch;
import org.javasimon.utils.SimonUtils;

/**
* CallbackExample shows how to implement callback that prints out some information on the specific events.
*
* @author <a href="mailto:virgo47@gmail.com">Richard "Virgo" Richter</a>
*/
public final class CallbackExample {
/**
* Entry point to the Callback Example.
*
* @param args unused
*/
public static void main(String[] args) {
SimonManager.callback().addCallback(new CallbackSkeleton() {
public void onStopwatchStart(Split split) {
System.out.println("\nStopwatch " + split.getStopwatch().getName() + " has just been started.");
}

public void onStopwatchStop(Split split, StopwatchSample sample) {
System.out.println("Stopwatch " + split.getStopwatch().getName()
+ " has just been stopped (" + SimonUtils.presentNanoTime(split.runningFor()) + ").");
}
});

Stopwatch sw = SimonManager.getStopwatch(SimonUtils.generateName());
sw.start().stop();

Split split = sw.start();
for (int i = 0; i < 1000000; i++) {
// what does JVM do with empty loop? :-)))
}
split.stop();

sw.start().stop();

System.out.println("\nAdditional stop() does nothing, Split state is preserved.");
split.stop();
System.out.println("split = " + split);
}
}

Change log

r524 by virgo47 on Apr 11, 2012   Diff
removed sample from onStopwatchStart
(waste of resources, so I decided :-)),
fixed missing enabled testing in
CounterImpl + sample is created for
callbacks only when there is at least one
in the manager
Go to: 
Project members, sign in to write a code review

Older revisions

r513 by virgo47 on Apr 6, 2012   Diff
added sample to onStopwatchStart as
well, revised Callback impls to
reflect this; simon patterns on
Manager list methods must be provided
as SimonPattern, not string (this
...
r512 by virgo47 on Apr 5, 2012   Diff
stopwatch/counter callback methods are
called OUT of synchronized blocks and
samples are provided where appropriate
(callback implementations don't use
the samples yet, I'll change this
...
r419 by virgo47 on Jan 11, 2012   Diff
fix http://code.google.com/p/javasimon
/issues/detail?id=63
All revisions of this file

File info

Size: 1460 bytes, 48 lines
Powered by Google Project Hosting