View Javadoc

1   /*
2    * $Id: TimingPolicy.java 20320 2010-11-24 15:03:31Z dfeist $
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.api.processor.policy;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleException;
15  
16  import org.apache.commons.logging.Log;
17  import org.apache.commons.logging.LogFactory;
18  
19  /**
20   *
21   */
22  public class TimingPolicy implements AroundPolicy
23  {
24  
25      protected final Log logger = LogFactory.getLog(getClass());
26  
27      public String getName()
28      {
29          return "simple timing policy";
30      }
31  
32      public MuleEvent invoke(PolicyInvocation invocation) throws MuleException
33      {
34          final MuleEvent invocationEvent = invocation.getEvent();
35          long startTime = System.currentTimeMillis();
36  
37          final MuleEvent result = invocation.proceed();
38  
39          long executionTime = System.currentTimeMillis() - startTime;
40          if (logger.isInfoEnabled())
41          {
42              logger.info(String.format("%s took %dms to process event [%s]",
43                                            invocationEvent.getFlowConstruct().getName(),
44                                            executionTime, invocationEvent.getId()));
45          }
46  
47          return result;
48      }
49  }