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;
12  
13  import org.mule.api.MuleException;
14  import org.mule.api.processor.MessageProcessor;
15  import org.mule.api.routing.Aggregator;
16  import org.mule.management.stats.RouterStatistics;
17  import org.mule.processor.builder.InterceptingChainMessageProcessorBuilder;
18  import org.mule.routing.AbstractAggregator;
19  import org.mule.source.StartableCompositeMessageSource;
20  
21  /**
22   * Extension of {@link StartableCompositeMessageSource} which adds message processors between the composite
23   * source and the target listener
24   */
25  public class ServiceAsyncReplyCompositeMessageSource extends ServiceCompositeMessageSource
26  {
27      protected Long timeout;
28      protected boolean failOnTimeout = true;
29  
30      public ServiceAsyncReplyCompositeMessageSource()
31      {
32          statistics = new RouterStatistics(RouterStatistics.TYPE_RESPONSE);
33      }
34  
35      protected void createMessageProcessorChain() throws MuleException
36      {
37          InterceptingChainMessageProcessorBuilder builder = new InterceptingChainMessageProcessorBuilder(flowConstruct);
38          builder.chain(processors);
39          builder.chain(listener);
40          listener = builder.build();
41      }
42  
43      public Long getTimeout()
44      {
45          return timeout;
46      }
47  
48      public void setTimeout(Long timeout)
49      {
50          this.timeout = timeout;
51      }
52  
53      public boolean isFailOnTimeout()
54      {
55          return failOnTimeout;
56      }
57  
58      public void setFailOnTimeout(boolean failOnTimeout)
59      {
60          this.failOnTimeout = failOnTimeout;
61      }
62  
63      public void expireAggregation(String groupId)
64      {
65          for (MessageProcessor processor : processors)
66          {
67              if (processor instanceof Aggregator)
68              {
69                  ((AbstractAggregator) processor).expireAggregation(groupId);
70              }
71          }
72      }
73  
74  }