1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.api.processor.policy; |
12 | |
|
13 | |
import org.mule.api.MuleEvent; |
14 | |
import org.mule.api.MuleException; |
15 | |
|
16 | |
import org.apache.commons.logging.Log; |
17 | |
import org.apache.commons.logging.LogFactory; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | 0 | public class TimingPolicy implements AroundPolicy |
23 | |
{ |
24 | |
|
25 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
26 | |
|
27 | |
public String getName() |
28 | |
{ |
29 | 0 | return "simple timing policy"; |
30 | |
} |
31 | |
|
32 | |
public MuleEvent invoke(PolicyInvocation invocation) throws MuleException |
33 | |
{ |
34 | 0 | final MuleEvent invocationEvent = invocation.getEvent(); |
35 | 0 | long startTime = System.currentTimeMillis(); |
36 | |
|
37 | 0 | final MuleEvent result = invocation.proceed(); |
38 | |
|
39 | 0 | long executionTime = System.currentTimeMillis() - startTime; |
40 | 0 | if (logger.isInfoEnabled()) |
41 | |
{ |
42 | 0 | logger.info(String.format("%s took %dms to process event [%s]", |
43 | |
invocationEvent.getFlowConstruct().getName(), |
44 | |
executionTime, invocationEvent.getId())); |
45 | |
} |
46 | |
|
47 | 0 | return result; |
48 | |
} |
49 | |
} |