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.processor;
12  
13  import org.mule.api.MessagingException;
14  import org.mule.api.MuleEvent;
15  import org.mule.api.config.ThreadingProfile;
16  import org.mule.api.context.WorkManagerSource;
17  
18  /**
19   * Implementation of {@link AsyncInterceptingMessageProcessor} which continues
20   * processing in the same thread if the inbound endpoint has an exchange pattern that
21   * has a response or if a transaction is present. Execution of the next message
22   * processor is only passed off to another thread if this is not the case.
23   */
24  public class OptionalAsyncInterceptingMessageProcessor extends AsyncInterceptingMessageProcessor
25  {
26      public OptionalAsyncInterceptingMessageProcessor(WorkManagerSource workManagerSource)
27      {
28          super(workManagerSource);
29      }
30  
31      @Deprecated
32      public OptionalAsyncInterceptingMessageProcessor(WorkManagerSource workManagerSource, boolean doThreading)
33      {
34          super(workManagerSource, doThreading);
35      }
36  
37      public OptionalAsyncInterceptingMessageProcessor(ThreadingProfile threadingProfile,
38                                                       String name,
39                                                       int shutdownTimeout)
40      {
41          super(threadingProfile, name, shutdownTimeout);
42      }
43  
44      protected boolean isProcessAsync(MuleEvent event) throws MessagingException
45      {
46          return doThreading && !event.getEndpoint().getExchangePattern().hasResponse()
47                 && !event.getEndpoint().getTransactionConfig().isTransacted();
48      }
49  
50  }