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.interceptor;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleException;
11  import org.mule.api.construct.FlowConstruct;
12  import org.mule.api.processor.MessageProcessor;
13  import org.mule.management.stats.ProcessingTime;
14  
15  /**
16   * Calculate and record the processing time for a message processing chain
17   */
18  public class ProcessingTimeInterceptor extends AbstractEnvelopeInterceptor
19  {
20      public ProcessingTimeInterceptor()
21      {
22          super();
23      }
24  
25      public ProcessingTimeInterceptor(MessageProcessor next, FlowConstruct fc)
26      {
27          setListener(next);
28          setFlowConstruct(fc);
29      }
30  
31      @Override
32      public MuleEvent before(MuleEvent event) throws MuleException
33      {
34          return event;
35      }
36  
37      @Override
38      public MuleEvent after(MuleEvent event) throws MuleException
39      {
40          return event;
41      }
42  
43  
44      @Override
45      public MuleEvent last(MuleEvent event, ProcessingTime time, long startTime, boolean exceptionWasThrown) throws MuleException
46      {
47          if (time != null)
48          {
49              time.addFlowExecutionBranchTime(startTime);
50          }
51          return event;
52      }
53  }