KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > interceptors > TimerInterceptor


1 /*
2  * $Id: TimerInterceptor.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.umo.Invocation;
16 import org.mule.umo.UMOException;
17 import org.mule.umo.UMOInterceptor;
18 import org.mule.umo.UMOMessage;
19
20 /**
21  * <code>TimerInterceptor</code> simply times and displays the time taken to
22  * process an event.
23  *
24  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
25  * @version $Revision: 3798 $
26  */

27 public class TimerInterceptor implements UMOInterceptor
28 {
29     /**
30      * logger used by this class
31      */

32     private static Log logger = LogFactory.getLog(TimerInterceptor.class);
33
34     /*
35      * (non-Javadoc)
36      *
37      * @see org.mule.umo.UMOInterceptor#intercept(org.mule.umo.UMOEvent)
38      */

39     public UMOMessage intercept(Invocation invocation) throws UMOException
40     {
41         long startTime = System.currentTimeMillis();
42         UMOMessage result = invocation.execute();
43         long executionTime = System.currentTimeMillis() - startTime;
44         logger.info(invocation.getDescriptor().getName() + " took " + executionTime + "ms to process event ["
45                     + invocation.getEvent().getId() + "]");
46         return result;
47     }
48 }
49
Popular Tags