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