5. We can use a Mule component called custom-interceptor in
our flow
With this we can calculate the total amount of time
taken in our flow
6. So, we can take following Mule flow to demonstrate :-
7. So, we can use the following tag in our flow of our Mule config
to execute total time:-
<custom-interceptor
class="com.customInterceptor.TimerInterceptor" />
8. And our java class TimerInterceptor will be:-
public class TimerInterceptor extends AbstractInterceptingMessageProcessor
implements Interceptor {
private static Log logger = LogFactory.getLog(TimerInterceptor.class);
public MuleEvent process(MuleEvent event) throws MuleException {
long startTime = System.currentTimeMillis();
MuleEvent resultEvent = processNext(event);
if (logger.isInfoEnabled()) {
long executionTime = System.currentTimeMillis() - startTime;
logger.info("Custom Timer : "+resultEvent.getFlowConstruct().getName() + " took "
+ executionTime + "ms to process event ["
+ resultEvent.getId() + "]");
}
return resultEvent;
}
}
9. Now this is a complex web service that uses cache mechanism
in the flow and will fetch some data from the database
Now when we execute this flow, we will get the above in our console
10. Now since this flow uses a cache mechanism in the flow, if we
hit the service again , it will uses cache to fetch it’s data and it
will not hit the actual database.
So, in this case the execution time will be less as follow :-
Now when we execute this flow, we will get the above in our console
11. So, this is very simple, we just need to put the following
code in our flow to get the execution time:-
<custom-interceptor> with your own java class to
calculate the execution time