View Javadoc

1   /*
2    * $Id: TimerInterceptor.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.interceptor;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleException;
15  import org.mule.api.interceptor.Interceptor;
16  import org.mule.processor.AbstractInterceptingMessageProcessor;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  
21  /**
22   * <code>TimerInterceptor</code> simply times and displays the time taken to process
23   * an event.
24   */
25  public class TimerInterceptor extends AbstractInterceptingMessageProcessor implements Interceptor
26  {
27      /**
28       * logger used by this class
29       */
30      private static Log logger = LogFactory.getLog(TimerInterceptor.class);
31  
32      public MuleEvent process(MuleEvent event) throws MuleException
33      {
34          long startTime = System.currentTimeMillis();
35  
36          MuleEvent resultEvent = processNext(event);
37  
38          if (logger.isInfoEnabled())
39          {
40              long executionTime = System.currentTimeMillis() - startTime;
41              logger.info(resultEvent.getFlowConstruct().getName() + " took " + executionTime
42                          + "ms to process event [" + resultEvent.getId() + "]");
43          }
44  
45          return resultEvent;
46      }
47  }