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.service.processor;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleException;
11  import org.mule.api.processor.MessageProcessor;
12  import org.mule.api.routing.OutboundRouterCollection;
13  import org.mule.api.service.Service;
14  import org.mule.management.stats.ServiceStatistics;
15  
16  public class ServiceOutboundStatisticsMessageProcessor implements MessageProcessor
17  {
18  
19      protected Service service;
20  
21      public ServiceOutboundStatisticsMessageProcessor(Service service)
22      {
23          this.service = service;
24      }
25  
26      public MuleEvent process(MuleEvent event) throws MuleException
27      {
28          ServiceStatistics stats = service.getStatistics();
29          if (stats.isEnabled())
30          {
31              if (!(service.getOutboundMessageProcessor() instanceof OutboundRouterCollection)
32                  || (service.getOutboundMessageProcessor() instanceof OutboundRouterCollection && ((OutboundRouterCollection) service.getOutboundMessageProcessor()).hasEndpoints()))
33              {
34                  if (event.getEndpoint().getExchangePattern().hasResponse())
35                  {
36                      stats.incSentEventSync();
37                  }
38                  else
39                  {
40                      stats.incSentEventASync();
41                  }
42              }
43          }
44  
45          return event;
46      }
47  }