1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.spring.factories; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.NamedObject; |
11 | |
import org.mule.api.config.MuleConfiguration; |
12 | |
import org.mule.api.config.ThreadingProfile; |
13 | |
import org.mule.api.context.MuleContextAware; |
14 | |
import org.mule.api.processor.MessageProcessor; |
15 | |
import org.mule.api.processor.MessageProcessorBuilder; |
16 | |
import org.mule.processor.AsyncDelegateMessageProcessor; |
17 | |
import org.mule.processor.chain.DefaultMessageProcessorChainBuilder; |
18 | |
import org.mule.util.concurrent.ThreadNameHelper; |
19 | |
|
20 | |
import java.util.List; |
21 | |
|
22 | |
import org.springframework.beans.factory.FactoryBean; |
23 | |
|
24 | 0 | public class AsyncMessageProcessorsFactoryBean implements FactoryBean, MuleContextAware, NamedObject |
25 | |
{ |
26 | |
|
27 | |
protected MuleContext muleContext; |
28 | |
|
29 | |
protected List messageProcessors; |
30 | |
protected ThreadingProfile threadingProfile; |
31 | |
protected String name; |
32 | |
|
33 | |
public Class getObjectType() |
34 | |
{ |
35 | 0 | return MessageProcessor.class; |
36 | |
} |
37 | |
|
38 | |
public void setThreadingProfile(ThreadingProfile threadingProfile) |
39 | |
{ |
40 | 0 | this.threadingProfile = threadingProfile; |
41 | 0 | } |
42 | |
|
43 | |
public void setMessageProcessors(List messageProcessors) |
44 | |
{ |
45 | 0 | this.messageProcessors = messageProcessors; |
46 | 0 | } |
47 | |
|
48 | |
public Object getObject() throws Exception |
49 | |
{ |
50 | 0 | if (threadingProfile == null) |
51 | |
{ |
52 | 0 | threadingProfile = muleContext.getDefaultThreadingProfile(); |
53 | |
} |
54 | |
|
55 | 0 | DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder(); |
56 | 0 | builder.setName("'async' child chain"); |
57 | 0 | final MuleConfiguration config = muleContext.getConfiguration(); |
58 | 0 | final String threadPrefix = ThreadNameHelper.asyncProcessor(muleContext, name); |
59 | |
|
60 | 0 | AsyncDelegateMessageProcessor asyncProcessor = new AsyncDelegateMessageProcessor(threadingProfile, |
61 | |
threadPrefix, |
62 | |
config.getShutdownTimeout()); |
63 | 0 | for (Object processor : messageProcessors) |
64 | |
{ |
65 | 0 | if (processor instanceof MessageProcessor) |
66 | |
{ |
67 | 0 | builder.chain((MessageProcessor) processor); |
68 | |
} |
69 | 0 | else if (processor instanceof MessageProcessorBuilder) |
70 | |
{ |
71 | 0 | builder.chain((MessageProcessorBuilder) processor); |
72 | |
} |
73 | |
else |
74 | |
{ |
75 | 0 | throw new IllegalArgumentException( |
76 | |
"MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured"); |
77 | |
} |
78 | |
} |
79 | 0 | asyncProcessor.setDelegate(builder.build()); |
80 | 0 | return asyncProcessor; |
81 | |
} |
82 | |
|
83 | |
public boolean isSingleton() |
84 | |
{ |
85 | 0 | return false; |
86 | |
} |
87 | |
|
88 | |
public void setMuleContext(MuleContext context) |
89 | |
{ |
90 | 0 | this.muleContext = context; |
91 | 0 | } |
92 | |
|
93 | |
public String getName() |
94 | |
{ |
95 | 0 | return name; |
96 | |
} |
97 | |
|
98 | |
public void setName(String name) |
99 | |
{ |
100 | 0 | this.name = name; |
101 | 0 | } |
102 | |
|
103 | |
} |