View Javadoc

1   /*
2    * $Id$
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.routing.OutboundRouterCollection;
15  import org.mule.api.service.Service;
16  import org.mule.management.stats.ServiceStatistics;
17  import org.mule.processor.AbstractMessageObserver;
18  
19  public class ServiceOutboundStatisticsObserver extends AbstractMessageObserver
20  {
21  
22      protected Service service;
23  
24      public ServiceOutboundStatisticsObserver(Service service)
25      {
26          this.service = service;
27      }
28  
29      @Override
30      public void observe(MuleEvent event)
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.getEndpoint().getExchangePattern().hasResponse())
39                  {
40                      stats.incSentEventSync();
41                  }
42                  else
43                  {
44                      stats.incSentEventASync();
45                  }
46              }
47          }
48      }
49  }