-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathStopWatchDispatcher.java
More file actions
49 lines (40 loc) · 1.45 KB
/
StopWatchDispatcher.java
File metadata and controls
49 lines (40 loc) · 1.45 KB
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
49
package org.msgpack.rpc.dispatcher;
import org.msgpack.rpc.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* For debug.
* Measures dispatch time.
*
* User: takeshita
* Create: 12/06/15 0:53
*/
public class StopWatchDispatcher implements Dispatcher {
Dispatcher innerDispatcher;
private final static Logger logger = LoggerFactory.getLogger(StopWatchDispatcher.class);
private boolean verbose = true;
public boolean isVerbose() {
return verbose;
}
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
public StopWatchDispatcher(Dispatcher inner) {
this.innerDispatcher = inner;
}
public void dispatch(Request request) throws Exception {
if (verbose) {
logger.info(String.format("Begin dispatching %s with args %s", request.getMethodName(), request.getArguments().toString()));
}
long start = System.currentTimeMillis();
try {
innerDispatcher.dispatch(request);
long diff = System.currentTimeMillis() - start;
logger.info(String.format("Dispatch %s in %s msecs", request.getMethodName(), diff));
} catch (Exception e) {
long diff = System.currentTimeMillis() - start;
logger.info(String.format("%s : %s while dispatching %s,(in %s msecs)", e.getClass().getSimpleName(), e.getMessage(), request.getMethodName(), diff));
throw e;
}
}
}