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