View Javadoc

1   /*
2    * $Id: ServiceOutboundStatisticsMessageProcessor.java 22177 2011-06-15 01:38:58Z 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.service.processor;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleException;
15  import org.mule.api.processor.MessageProcessor;
16  import org.mule.api.routing.OutboundRouterCollection;
17  import org.mule.api.service.Service;
18  import org.mule.management.stats.ServiceStatistics;
19  
20  public class ServiceOutboundStatisticsMessageProcessor implements MessageProcessor
21  {
22  
23      protected Service service;
24  
25      public ServiceOutboundStatisticsMessageProcessor(Service service)
26      {
27          this.service = service;
28      }
29  
30      public MuleEvent process(MuleEvent event) throws MuleException
31      {
32          ServiceStatistics stats = service.getStatistics();
33          if (stats.isEnabled())
34          {
35              if (!(service.getOutboundMessageProcessor() instanceof OutboundRouterCollection)
36                  || (service.getOutboundMessageProcessor() instanceof OutboundRouterCollection && ((OutboundRouterCollection) service.getOutboundMessageProcessor()).hasEndpoints()))
37              {
38                  if (event.getExchangePattern().hasResponse())
39                  {
40                      stats.incSentEventSync();
41                  }
42                  else
43                  {
44                      stats.incSentEventASync();
45                  }
46              }
47          }
48  
49          return event;
50      }
51  }