View Javadoc

1   /*
2    * $Id: ProcessingStrategyUtils.java 22597 2011-08-05 20:40:24Z dfeist $
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.config.spring.util;
12  
13  import org.mule.construct.flow.DefaultFlowProcessingStrategy;
14  import org.mule.processor.strategy.AsynchronousProcessingStrategy;
15  import org.mule.processor.strategy.QueuedAsynchronousProcessingStrategy;
16  import org.mule.processor.strategy.QueuedThreadPerProcessorProcessingStrategy;
17  import org.mule.processor.strategy.SynchronousProcessingStrategy;
18  import org.mule.processor.strategy.ThreadPerProcessorProcessingStrategy;
19  
20  import org.springframework.beans.factory.config.RuntimeBeanReference;
21  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
22  import org.w3c.dom.Element;
23  
24  public class ProcessingStrategyUtils
25  {
26  
27      private static String PROCESSING_STRATEGY_ATTRIBUTE_NAME = "processingStrategy";
28  
29      public static String DEFAULT_PROCESSING_STRATEGY = "default";
30      public static String SYNC_PROCESSING_STRATEGY = "synchronous";
31      public static String ASYNC_PROCESSING_STRATEGY = "asynchronous";
32      public static String QUEUED_ASYNC_PROCESSING_STRATEGY = "queued-asynchronous";
33      public static String THREAD_PER_PROCESSOR_PROCESSING_STRATEGY = "thread-per-processor";
34      public static String QUEUED_THREAD_PER_PROCESSOR_PROCESSING_STRATEGY = "queued-thread-per-processor";
35  
36      public static void configureProcessingStrategy(Element element,
37                                                     BeanDefinitionBuilder builder,
38                                                     String defaultStrategy)
39      {
40          String processingStrategy = element.getAttribute(PROCESSING_STRATEGY_ATTRIBUTE_NAME);
41          if (DEFAULT_PROCESSING_STRATEGY.equals(processingStrategy))
42          {
43              builder.addPropertyValue(PROCESSING_STRATEGY_ATTRIBUTE_NAME, new DefaultFlowProcessingStrategy());
44          }
45          else if (SYNC_PROCESSING_STRATEGY.equals(processingStrategy))
46          {
47              builder.addPropertyValue(PROCESSING_STRATEGY_ATTRIBUTE_NAME, new SynchronousProcessingStrategy());
48          }
49          else if (ASYNC_PROCESSING_STRATEGY.equals(processingStrategy))
50          {
51              builder.addPropertyValue(PROCESSING_STRATEGY_ATTRIBUTE_NAME, new AsynchronousProcessingStrategy());
52          }
53          else if (QUEUED_ASYNC_PROCESSING_STRATEGY.equals(processingStrategy))
54          {
55              builder.addPropertyValue(PROCESSING_STRATEGY_ATTRIBUTE_NAME,
56                  new QueuedAsynchronousProcessingStrategy());
57          }
58          else if (THREAD_PER_PROCESSOR_PROCESSING_STRATEGY.equals(processingStrategy))
59          {
60              builder.addPropertyValue(PROCESSING_STRATEGY_ATTRIBUTE_NAME,
61                  new ThreadPerProcessorProcessingStrategy());
62          }
63          else if (QUEUED_THREAD_PER_PROCESSOR_PROCESSING_STRATEGY.equals(processingStrategy))
64          {
65              builder.addPropertyValue(PROCESSING_STRATEGY_ATTRIBUTE_NAME,
66                  new QueuedThreadPerProcessorProcessingStrategy());
67          }
68          else if (null != processingStrategy && !processingStrategy.isEmpty())
69          {
70              builder.addPropertyValue(PROCESSING_STRATEGY_ATTRIBUTE_NAME, new RuntimeBeanReference(
71                  processingStrategy));
72          }
73      }
74  
75  }