View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.api.processor.policy;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleException;
11  
12  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
14  
15  /**
16   *
17   */
18  public class TimingPolicy implements AroundPolicy
19  {
20  
21      protected final Log logger = LogFactory.getLog(getClass());
22  
23      public String getName()
24      {
25          return "simple timing policy";
26      }
27  
28      public MuleEvent invoke(PolicyInvocation invocation) throws MuleException
29      {
30          final MuleEvent invocationEvent = invocation.getEvent();
31          long startTime = System.currentTimeMillis();
32  
33          final MuleEvent result = invocation.proceed();
34  
35          long executionTime = System.currentTimeMillis() - startTime;
36          if (logger.isInfoEnabled())
37          {
38              logger.info(String.format("%s took %dms to process event [%s]",
39                                            invocationEvent.getFlowConstruct().getName(),
40                                            executionTime, invocationEvent.getId()));
41          }
42  
43          return result;
44      }
45  }