View Javadoc

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