1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.model.seda; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.MuleException; |
11 | |
import org.mule.api.config.ThreadingProfile; |
12 | |
import org.mule.api.lifecycle.InitialisationException; |
13 | |
import org.mule.api.processor.MessageProcessor; |
14 | |
import org.mule.api.processor.MessageProcessorChainBuilder; |
15 | |
import org.mule.config.ChainedThreadingProfile; |
16 | |
import org.mule.config.QueueProfile; |
17 | |
import org.mule.config.i18n.CoreMessages; |
18 | |
import org.mule.config.i18n.MessageFactory; |
19 | |
import org.mule.interceptor.ProcessingTimeInterceptor; |
20 | |
import org.mule.lifecycle.processor.ProcessIfStartedWaitIfSyncPausedMessageProcessor; |
21 | |
import org.mule.management.stats.ServiceStatistics; |
22 | |
import org.mule.processor.SedaStageInterceptingMessageProcessor; |
23 | |
import org.mule.service.AbstractService; |
24 | |
import org.mule.service.processor.ServiceInternalMessageProcessor; |
25 | |
import org.mule.service.processor.ServiceLoggingMessageProcessor; |
26 | |
import org.mule.service.processor.ServiceOutboundMessageProcessor; |
27 | |
import org.mule.service.processor.ServiceOutboundStatisticsMessageProcessor; |
28 | |
import org.mule.service.processor.ServiceSetEventRequestContextMessageProcessor; |
29 | |
import org.mule.service.processor.ServiceStatisticsMessageProcessor; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class SedaService extends AbstractService |
37 | |
{ |
38 | |
|
39 | |
|
40 | |
|
41 | |
private static final long serialVersionUID = 7711976708670893015L; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
protected Integer queueTimeout; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
protected ThreadingProfile threadingProfile; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
protected QueueProfile queueProfile; |
59 | |
|
60 | |
protected SedaStageInterceptingMessageProcessor sedaStage; |
61 | |
|
62 | |
public SedaService(MuleContext muleContext) |
63 | |
{ |
64 | 0 | super(muleContext); |
65 | 0 | } |
66 | |
|
67 | |
@Override |
68 | |
protected MessageProcessor getServiceStartedAssertingMessageProcessor() |
69 | |
{ |
70 | 0 | return new ProcessIfStartedWaitIfSyncPausedMessageProcessor(this, lifecycleManager.getState()); |
71 | |
} |
72 | |
|
73 | |
protected void addMessageProcessors(MessageProcessorChainBuilder builder) |
74 | |
{ |
75 | 0 | builder.chain(new ProcessingTimeInterceptor(null, this)); |
76 | 0 | builder.chain(new ServiceLoggingMessageProcessor(this)); |
77 | 0 | builder.chain(new ServiceStatisticsMessageProcessor(this)); |
78 | 0 | builder.chain(new ServiceSetEventRequestContextMessageProcessor()); |
79 | 0 | if (getThreadingProfile().isDoThreading()) |
80 | |
{ |
81 | 0 | sedaStage = new SedaStageInterceptingMessageProcessor(getName(), queueProfile, queueTimeout, |
82 | |
threadingProfile, stats, muleContext); |
83 | 0 | builder.chain(sedaStage); |
84 | |
} |
85 | 0 | builder.chain(new ServiceInternalMessageProcessor(this)); |
86 | 0 | if (asyncReplyMessageSource.getEndpoints().size() > 0) |
87 | |
{ |
88 | 0 | builder.chain(createAsyncReplyProcessor()); |
89 | |
} |
90 | 0 | builder.chain(new ServiceOutboundMessageProcessor(this)); |
91 | 0 | builder.chain(new ServiceOutboundStatisticsMessageProcessor(this)); |
92 | 0 | builder.chain(outboundRouter); |
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
@Override |
103 | |
protected synchronized void doInitialise() throws InitialisationException |
104 | |
{ |
105 | 0 | if (threadingProfile == null) |
106 | |
{ |
107 | 0 | threadingProfile = muleContext.getDefaultServiceThreadingProfile(); |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | 0 | ChainedThreadingProfile threadingProfile = new ChainedThreadingProfile(this.threadingProfile); |
113 | 0 | threadingProfile.setMuleContext(muleContext); |
114 | 0 | threadingProfile.setMaxThreadsActive(threadingProfile.getMaxThreadsActive() + 1); |
115 | |
|
116 | |
|
117 | |
|
118 | 0 | if (queueProfile == null && model != null) |
119 | |
{ |
120 | 0 | queueProfile = ((SedaModel) model).getQueueProfile(); |
121 | |
} |
122 | 0 | if (queueTimeout == null && model != null) |
123 | |
{ |
124 | 0 | setQueueTimeout(((SedaModel) model).getQueueTimeout()); |
125 | |
} |
126 | |
|
127 | |
try |
128 | |
{ |
129 | 0 | if (name == null) |
130 | |
{ |
131 | 0 | throw new InitialisationException( |
132 | |
MessageFactory.createStaticMessage("Service has no name to identify it"), this); |
133 | |
} |
134 | |
} |
135 | 0 | catch (Throwable e) |
136 | |
{ |
137 | 0 | throw new InitialisationException(CoreMessages.objectFailedToInitialise("Service Queue"), e, this); |
138 | 0 | } |
139 | 0 | super.doInitialise(); |
140 | 0 | } |
141 | |
|
142 | |
@Override |
143 | |
protected ServiceStatistics createStatistics() |
144 | |
{ |
145 | 0 | return new ServiceStatistics(getName(), threadingProfile.getMaxThreadsActive()); |
146 | |
} |
147 | |
|
148 | |
public QueueProfile getQueueProfile() |
149 | |
{ |
150 | 0 | return queueProfile; |
151 | |
} |
152 | |
|
153 | |
public void setQueueProfile(QueueProfile queueProfile) |
154 | |
{ |
155 | 0 | this.queueProfile = queueProfile; |
156 | 0 | } |
157 | |
|
158 | |
public Integer getQueueTimeout() |
159 | |
{ |
160 | 0 | return queueTimeout; |
161 | |
} |
162 | |
|
163 | |
public void setQueueTimeout(Integer queueTimeout) |
164 | |
{ |
165 | 0 | this.queueTimeout = queueTimeout; |
166 | 0 | } |
167 | |
|
168 | |
public ThreadingProfile getThreadingProfile() |
169 | |
{ |
170 | 0 | return threadingProfile; |
171 | |
} |
172 | |
|
173 | |
public void setThreadingProfile(ThreadingProfile threadingProfile) |
174 | |
{ |
175 | 0 | this.threadingProfile = threadingProfile; |
176 | 0 | } |
177 | |
|
178 | |
@Override |
179 | |
protected void doPause() throws MuleException |
180 | |
{ |
181 | 0 | super.doPause(); |
182 | 0 | sedaStage.pause(); |
183 | 0 | } |
184 | |
|
185 | |
@Override |
186 | |
protected void doResume() throws MuleException |
187 | |
{ |
188 | 0 | sedaStage.resume(); |
189 | 0 | super.doResume(); |
190 | 0 | } |
191 | |
|
192 | |
} |