View Javadoc

1   /*
2    * $Id: TimerInterceptor.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.interceptors;
12  
13  import org.mule.umo.Invocation;
14  import org.mule.umo.UMOException;
15  import org.mule.umo.UMOInterceptor;
16  import org.mule.umo.UMOMessage;
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 an
23   * event.
24   */
25  public class TimerInterceptor implements UMOInterceptor
26  {
27      /**
28       * logger used by this class
29       */
30      private static Log logger = LogFactory.getLog(TimerInterceptor.class);
31  
32      /*
33       * (non-Javadoc)
34       * 
35       * @see org.mule.umo.UMOInterceptor#intercept(org.mule.umo.UMOEvent)
36       */
37      public UMOMessage intercept(Invocation invocation) throws UMOException
38      {
39          long startTime = System.currentTimeMillis();
40          UMOMessage result = invocation.execute();
41          long executionTime = System.currentTimeMillis() - startTime;
42          logger.info(invocation.getDescriptor().getName() + " took " + executionTime + "ms to process event ["
43                      + invocation.getEvent().getId() + "]");
44          return result;
45      }
46  }