View Javadoc

1   /*
2    * $Id: FlowConstructStatisticsMessageProcessor.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.construct.processor;
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.construct.FlowConstructAware;
17  import org.mule.api.processor.MessageProcessor;
18  import org.mule.util.ObjectUtils;
19  
20  public class FlowConstructStatisticsMessageProcessor implements MessageProcessor, FlowConstructAware
21  {
22      protected FlowConstruct flowConstruct;
23  
24      public MuleEvent process(MuleEvent event) throws MuleException
25      {
26          if (flowConstruct.getStatistics().isEnabled())
27          {
28              if (event.getEndpoint().getExchangePattern().hasResponse())
29              {
30                  flowConstruct.getStatistics().incReceivedEventSync();
31              }
32              else
33              {
34                  flowConstruct.getStatistics().incReceivedEventASync();
35              }
36          }
37  
38          return event;
39      }
40  
41      public void setFlowConstruct(FlowConstruct flowConstruct)
42      {
43          this.flowConstruct = flowConstruct;
44      }
45  
46      @Override
47      public String toString()
48      {
49          return ObjectUtils.toString(this);
50      }
51  }