1
2
3
4
5
6
7
8
9
10
11 package org.mule.processor.strategy;
12
13 import org.mule.api.MuleContext;
14 import org.mule.api.config.MuleProperties;
15 import org.mule.api.config.ThreadingProfile;
16 import org.mule.api.store.ListableObjectStore;
17 import org.mule.config.QueueProfile;
18 import org.mule.management.stats.QueueStatistics;
19 import org.mule.management.stats.QueueStatisticsAware;
20 import org.mule.processor.AsyncInterceptingMessageProcessor;
21 import org.mule.processor.SedaStageInterceptingMessageProcessor;
22 import org.mule.util.concurrent.ThreadNameHelper;
23 import org.mule.util.queue.QueueManager;
24
25 import java.io.Serializable;
26
27 import javax.resource.spi.work.WorkManager;
28
29
30
31
32
33
34 public class QueuedAsynchronousProcessingStrategy extends AsynchronousProcessingStrategy
35 implements QueueStatisticsAware
36 {
37
38 protected Integer queueTimeout;
39 protected Integer maxQueueSize = 0;
40 protected ListableObjectStore<Serializable> queueStore = null;
41 protected QueueStatistics queueStatistics;
42
43 @Override
44 protected AsyncInterceptingMessageProcessor createAsyncMessageProcessor(StageNameSource nameSource,
45 MuleContext muleContext)
46 {
47 Integer timeout = queueTimeout != null ? queueTimeout : muleContext.getConfiguration()
48 .getDefaultQueueTimeout();
49
50 initQueueStore(muleContext);
51
52 QueueProfile queueProfile = new QueueProfile(maxQueueSize, queueStore);
53 ThreadingProfile threadingProfile = createThreadingProfile(muleContext);
54 String stageName = nameSource.getName();
55 return new SedaStageInterceptingMessageProcessor(ThreadNameHelper.flow(muleContext, stageName),
56 stageName, queueProfile, timeout, threadingProfile, queueStatistics, muleContext);
57 }
58
59 protected void initQueueStore(MuleContext muleContext)
60 {
61 queueStore = muleContext.getRegistry().lookupObject(
62 MuleProperties.OBJECT_STORE_DEFAULT_IN_MEMORY_NAME);
63 }
64
65 public Integer getQueueTimeout()
66 {
67 return queueTimeout;
68 }
69
70 public void setQueueTimeout(Integer queueTimeout)
71 {
72 this.queueTimeout = queueTimeout;
73 }
74
75 public Integer getMaxQueueSize()
76 {
77 return maxQueueSize;
78 }
79
80 public void setMaxQueueSize(Integer maxQueueSize)
81 {
82 this.maxQueueSize = maxQueueSize;
83 }
84
85 public ListableObjectStore<Serializable> getQueueStore()
86 {
87 return queueStore;
88 }
89
90 public void setQueueStore(ListableObjectStore<Serializable> queueStore)
91 {
92 this.queueStore = queueStore;
93 }
94
95 public QueueStatistics getQueueStatistics()
96 {
97 return queueStatistics;
98 }
99
100 @Override
101 public void setQueueStatistics(QueueStatistics queueStatistics)
102 {
103 this.queueStatistics = queueStatistics;
104 }
105 }