1   /*
2    * $Id: TimingInterceptor.java 11130 2008-02-29 15:14:53Z acooke $
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 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.config.spring;
12  
13  import org.mule.api.interceptor.Interceptor;
14  import org.mule.api.interceptor.Invocation;
15  import org.mule.api.MuleMessage;
16  import org.mule.api.MuleException;
17  
18  public class TimingInterceptor implements Interceptor
19  {
20  
21      public static final long UNCALLED = -1L;
22      private long interval = UNCALLED;
23  
24      public MuleMessage intercept(Invocation invocation) throws MuleException
25      {
26          long start = System.currentTimeMillis();
27          try
28          {
29              // call the component
30              invocation.execute();
31              // let the framework construct the correct message
32              return null;
33          }
34          finally
35          {
36              interval = System.currentTimeMillis() - start;
37          }
38      }
39  
40      public long getInterval()
41      {
42          return interval;
43      }
44  
45  }