View Javadoc

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