1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.service; |
12 | |
|
13 | |
import org.mule.DefaultMuleMessage; |
14 | |
import org.mule.OptimizedRequestContext; |
15 | |
import org.mule.api.MessagingException; |
16 | |
import org.mule.api.MuleContext; |
17 | |
import org.mule.api.MuleEvent; |
18 | |
import org.mule.api.MuleException; |
19 | |
import org.mule.api.MuleMessage; |
20 | |
import org.mule.api.component.Component; |
21 | |
import org.mule.api.config.MuleProperties; |
22 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
23 | |
import org.mule.api.endpoint.InboundEndpoint; |
24 | |
import org.mule.api.endpoint.OutboundEndpoint; |
25 | |
import org.mule.api.lifecycle.InitialisationException; |
26 | |
import org.mule.api.model.Model; |
27 | |
import org.mule.api.model.ModelException; |
28 | |
import org.mule.api.routing.InboundRouterCollection; |
29 | |
import org.mule.api.routing.NestedRouterCollection; |
30 | |
import org.mule.api.routing.OutboundRouterCollection; |
31 | |
import org.mule.api.routing.ResponseRouterCollection; |
32 | |
import org.mule.api.service.Service; |
33 | |
import org.mule.api.service.ServiceException; |
34 | |
import org.mule.api.transport.DispatchException; |
35 | |
import org.mule.api.transport.MessageReceiver; |
36 | |
import org.mule.api.transport.ReplyToHandler; |
37 | |
import org.mule.component.simple.PassThroughComponent; |
38 | |
import org.mule.config.i18n.CoreMessages; |
39 | |
import org.mule.config.i18n.MessageFactory; |
40 | |
import org.mule.context.notification.ServiceNotification; |
41 | |
import org.mule.management.stats.ServiceStatistics; |
42 | |
import org.mule.routing.inbound.DefaultInboundRouterCollection; |
43 | |
import org.mule.routing.inbound.InboundPassThroughRouter; |
44 | |
import org.mule.routing.nested.DefaultNestedRouterCollection; |
45 | |
import org.mule.routing.outbound.DefaultOutboundRouterCollection; |
46 | |
import org.mule.routing.outbound.OutboundPassThroughRouter; |
47 | |
import org.mule.routing.response.DefaultResponseRouterCollection; |
48 | |
import org.mule.transport.AbstractConnector; |
49 | |
import org.mule.util.concurrent.WaitableBoolean; |
50 | |
|
51 | |
import java.beans.ExceptionListener; |
52 | |
import java.util.ArrayList; |
53 | |
import java.util.Iterator; |
54 | |
import java.util.List; |
55 | |
|
56 | |
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; |
57 | |
|
58 | |
import org.apache.commons.logging.Log; |
59 | |
import org.apache.commons.logging.LogFactory; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public abstract class AbstractService implements Service |
65 | |
{ |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 410 | protected transient Log logger = LogFactory.getLog(getClass()); |
71 | |
|
72 | 410 | protected ServiceStatistics stats = null; |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | 410 | protected AtomicBoolean stopped = new AtomicBoolean(true); |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | 410 | protected WaitableBoolean stopping = new WaitableBoolean(false); |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | 410 | protected AtomicBoolean initialised = new AtomicBoolean(false); |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
protected Model model; |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | 410 | protected WaitableBoolean paused = new WaitableBoolean(false); |
98 | |
|
99 | |
protected MuleContext muleContext; |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public static final String INITIAL_STATE_STOPPED = "stopped"; |
105 | |
public static final String INITIAL_STATE_STARTED = "started"; |
106 | |
public static final String INITIAL_STATE_PAUSED = "paused"; |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
protected ExceptionListener exceptionListener; |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
protected String name; |
117 | |
|
118 | 410 | protected InboundRouterCollection inboundRouter = new DefaultInboundRouterCollection(); |
119 | |
|
120 | 410 | protected OutboundRouterCollection outboundRouter = new DefaultOutboundRouterCollection(); |
121 | |
|
122 | 410 | protected NestedRouterCollection nestedRouter = new DefaultNestedRouterCollection(); |
123 | |
|
124 | 410 | protected ResponseRouterCollection responseRouter = new DefaultResponseRouterCollection(); |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | 410 | protected String initialState = INITIAL_STATE_STARTED; |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | 410 | private AtomicBoolean beyondInitialState = new AtomicBoolean(false); |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | 410 | protected Component component = new PassThroughComponent(); |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
public AbstractService() |
150 | 410 | { |
151 | |
|
152 | 410 | } |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public final synchronized void initialise() throws InitialisationException |
164 | |
{ |
165 | 400 | if (initialised.get()) |
166 | |
{ |
167 | 2 | throw new InitialisationException(CoreMessages.objectAlreadyInitialised("Service '" + name + "'"), this); |
168 | |
} |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | 398 | component.setService(this); |
174 | 398 | component.initialise(); |
175 | |
|
176 | 398 | if (inboundRouter == null) |
177 | |
{ |
178 | |
|
179 | |
|
180 | 0 | inboundRouter = new DefaultInboundRouterCollection(); |
181 | |
|
182 | 0 | inboundRouter.addRouter(new InboundPassThroughRouter()); |
183 | |
} |
184 | 398 | if (outboundRouter == null) |
185 | |
{ |
186 | 0 | outboundRouter = new DefaultOutboundRouterCollection(); |
187 | |
|
188 | 0 | outboundRouter.addRouter(new OutboundPassThroughRouter()); |
189 | |
} |
190 | 398 | if (responseRouter == null) |
191 | |
{ |
192 | 0 | responseRouter = new DefaultResponseRouterCollection(); |
193 | |
} |
194 | |
|
195 | 398 | if (exceptionListener == null) |
196 | |
{ |
197 | |
|
198 | 398 | exceptionListener = getModel().getExceptionListener(); |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
} |
204 | |
|
205 | 398 | doInitialise(); |
206 | |
|
207 | |
|
208 | 398 | stats = createStatistics(); |
209 | |
|
210 | 398 | stats.setEnabled(muleContext.getStatistics().isEnabled()); |
211 | 398 | muleContext.getStatistics().add(stats); |
212 | 398 | stats.setOutboundRouterStat(outboundRouter.getStatistics()); |
213 | 398 | stats.setInboundRouterStat(inboundRouter.getStatistics()); |
214 | 398 | stats.setComponentStat(component.getStatistics()); |
215 | |
|
216 | 398 | initialised.set(true); |
217 | 398 | fireServiceNotification(ServiceNotification.SERVICE_INITIALISED); |
218 | 398 | } |
219 | |
|
220 | |
protected ServiceStatistics createStatistics() |
221 | |
{ |
222 | 8 | return new ServiceStatistics(name); |
223 | |
} |
224 | |
|
225 | |
protected void fireServiceNotification(int action) |
226 | |
{ |
227 | 488 | muleContext.fireNotification(new ServiceNotification(this, action)); |
228 | 488 | } |
229 | |
|
230 | |
public void forceStop() throws MuleException |
231 | |
{ |
232 | 0 | if (!stopped.get()) |
233 | |
{ |
234 | 0 | logger.debug("Stopping Service"); |
235 | 0 | stopping.set(true); |
236 | 0 | fireServiceNotification(ServiceNotification.SERVICE_STOPPING); |
237 | 0 | doForceStop(); |
238 | 0 | stopped.set(true); |
239 | 0 | stopping.set(false); |
240 | 0 | fireServiceNotification(ServiceNotification.SERVICE_STOPPED); |
241 | |
} |
242 | 0 | } |
243 | |
|
244 | |
public void stop() throws MuleException |
245 | |
{ |
246 | 24 | if (!stopped.get()) |
247 | |
{ |
248 | 20 | logger.debug("Stopping Service"); |
249 | 20 | stopping.set(true); |
250 | 20 | fireServiceNotification(ServiceNotification.SERVICE_STOPPING); |
251 | |
|
252 | |
|
253 | 20 | unregisterListeners(); |
254 | |
|
255 | 20 | component.stop(); |
256 | |
|
257 | 20 | doStop(); |
258 | 20 | stopped.set(true); |
259 | 20 | fireServiceNotification(ServiceNotification.SERVICE_STOPPED); |
260 | 20 | logger.info("Mule Service " + name + " has been stopped successfully"); |
261 | |
} |
262 | 24 | } |
263 | |
|
264 | |
public void start() throws MuleException |
265 | |
{ |
266 | |
|
267 | |
|
268 | 22 | if (!initialised.get()) |
269 | |
{ |
270 | 2 | throw new IllegalStateException("Cannot start an unitialised service."); |
271 | |
} |
272 | 20 | if (isStarted()) |
273 | |
{ |
274 | 0 | logger.info("Service is already started: " + name); |
275 | |
} |
276 | |
else |
277 | |
{ |
278 | 20 | if (initialState.equals(AbstractService.INITIAL_STATE_STOPPED)) |
279 | |
{ |
280 | 0 | logger.info("stopped"); |
281 | |
} |
282 | 20 | if (!beyondInitialState.get() && initialState.equals(AbstractService.INITIAL_STATE_STOPPED)) |
283 | |
{ |
284 | 0 | logger.info("Service " + name + " has not been started (initial state = 'stopped')"); |
285 | |
} |
286 | 20 | else if (!beyondInitialState.get() && initialState.equals(AbstractService.INITIAL_STATE_PAUSED)) |
287 | |
{ |
288 | 0 | start(true); |
289 | 0 | logger.info("Service " + name + " has been started and paused (initial state = 'paused')"); |
290 | |
} |
291 | |
else |
292 | |
{ |
293 | 20 | start(false); |
294 | 20 | logger.info("Service " + name + " has been started successfully"); |
295 | |
} |
296 | 20 | beyondInitialState.set(true); |
297 | |
} |
298 | 20 | } |
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
protected void start(boolean startPaused) throws MuleException |
307 | |
{ |
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | 20 | component.start(); |
314 | |
|
315 | |
|
316 | 20 | registerListeners(); |
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | 20 | connectListeners(); |
325 | |
|
326 | |
|
327 | 20 | if (stopped.get()) |
328 | |
{ |
329 | 20 | stopped.set(false); |
330 | 20 | paused.set(false); |
331 | 20 | doStart(); |
332 | |
} |
333 | 20 | fireServiceNotification(ServiceNotification.SERVICE_STARTED); |
334 | 20 | if (startPaused) |
335 | |
{ |
336 | 0 | pause(); |
337 | |
} |
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | 20 | startListeners(); |
344 | 20 | } |
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
public final void pause() throws MuleException |
352 | |
{ |
353 | 6 | doPause(); |
354 | 6 | paused.set(true); |
355 | 6 | fireServiceNotification(ServiceNotification.SERVICE_PAUSED); |
356 | 6 | logger.info("Mule Service " + name + " has been paused successfully"); |
357 | 6 | } |
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
public final void resume() throws MuleException |
364 | |
{ |
365 | 10 | doResume(); |
366 | 10 | paused.set(false); |
367 | 10 | fireServiceNotification(ServiceNotification.SERVICE_RESUMED); |
368 | 10 | logger.info("Mule Service " + name + " has been resumed successfully"); |
369 | 10 | } |
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
public boolean isPaused() |
377 | |
{ |
378 | 30 | return paused.get(); |
379 | |
} |
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
protected void doPause() throws MuleException |
389 | |
{ |
390 | |
|
391 | 6 | } |
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
protected void doResume() throws MuleException |
401 | |
{ |
402 | |
|
403 | 10 | } |
404 | |
|
405 | |
public final void dispose() |
406 | |
{ |
407 | |
try |
408 | |
{ |
409 | 14 | if (!stopped.get()) |
410 | |
{ |
411 | 8 | stop(); |
412 | |
} |
413 | |
} |
414 | 0 | catch (MuleException e) |
415 | |
{ |
416 | |
|
417 | 0 | logger.error("Failed to stop service: " + name, e); |
418 | 14 | } |
419 | 14 | doDispose(); |
420 | 14 | component.dispose(); |
421 | 14 | initialised.set(false); |
422 | 14 | fireServiceNotification(ServiceNotification.SERVICE_DISPOSED); |
423 | 14 | muleContext.getStatistics().remove(stats); |
424 | 14 | } |
425 | |
|
426 | |
public ServiceStatistics getStatistics() |
427 | |
{ |
428 | 0 | return stats; |
429 | |
} |
430 | |
|
431 | |
public void dispatchEvent(MuleEvent event) throws MuleException |
432 | |
{ |
433 | 0 | if (stopping.get() || stopped.get()) |
434 | |
{ |
435 | 0 | throw new ServiceException( |
436 | |
CoreMessages.componentIsStopped(name), |
437 | |
event.getMessage(), this); |
438 | |
} |
439 | |
|
440 | |
try |
441 | |
{ |
442 | 0 | waitIfPaused(event); |
443 | |
} |
444 | 0 | catch (InterruptedException e) |
445 | |
{ |
446 | 0 | throw new ServiceException(event.getMessage(), this, e); |
447 | 0 | } |
448 | |
|
449 | |
|
450 | |
|
451 | 0 | ImmutableEndpoint endpoint = event.getEndpoint(); |
452 | |
|
453 | 0 | if (endpoint instanceof OutboundEndpoint) |
454 | |
{ |
455 | |
try |
456 | |
{ |
457 | 0 | ((OutboundEndpoint) endpoint).dispatch(event); |
458 | |
} |
459 | 0 | catch (Exception e) |
460 | |
{ |
461 | 0 | throw new DispatchException(event.getMessage(), event.getEndpoint(), e); |
462 | 0 | } |
463 | |
|
464 | 0 | return; |
465 | |
} |
466 | |
|
467 | |
|
468 | 0 | if (stats.isEnabled()) |
469 | |
{ |
470 | 0 | stats.incReceivedEventASync(); |
471 | |
} |
472 | |
|
473 | 0 | if (logger.isDebugEnabled()) |
474 | |
{ |
475 | 0 | logger.debug("Service: " + name + " has received asynchronous event on: " |
476 | |
+ event.getEndpoint().getEndpointURI()); |
477 | |
} |
478 | |
|
479 | 0 | doDispatch(event); |
480 | 0 | } |
481 | |
|
482 | |
public MuleMessage sendEvent(MuleEvent event) throws MuleException |
483 | |
{ |
484 | 0 | if (stopping.get() || stopped.get()) |
485 | |
{ |
486 | 0 | throw new ServiceException( |
487 | |
CoreMessages.componentIsStopped(name), |
488 | |
event.getMessage(), this); |
489 | |
} |
490 | |
|
491 | |
try |
492 | |
{ |
493 | 0 | waitIfPaused(event); |
494 | |
} |
495 | 0 | catch (InterruptedException e) |
496 | |
{ |
497 | 0 | throw new ServiceException(event.getMessage(), this, e); |
498 | 0 | } |
499 | |
|
500 | 0 | if (stats.isEnabled()) |
501 | |
{ |
502 | 0 | stats.incReceivedEventSync(); |
503 | |
} |
504 | 0 | if (logger.isDebugEnabled()) |
505 | |
{ |
506 | 0 | logger.debug("Service: " + name + " has received synchronous event on: " |
507 | |
+ event.getEndpoint().getEndpointURI()); |
508 | |
} |
509 | 0 | event = OptimizedRequestContext.unsafeSetEvent(event); |
510 | 0 | return doSend(event); |
511 | |
} |
512 | |
|
513 | |
|
514 | |
|
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
|
520 | |
|
521 | |
protected void waitIfPaused(MuleEvent event) throws InterruptedException |
522 | |
{ |
523 | 0 | if (logger.isDebugEnabled() && paused.get()) |
524 | |
{ |
525 | 0 | logger.debug("Service: " + name |
526 | |
+ " is paused. Blocking call until resume is called"); |
527 | |
} |
528 | 0 | paused.whenFalse(null); |
529 | 0 | } |
530 | |
|
531 | |
|
532 | |
|
533 | |
|
534 | |
public String getName() |
535 | |
{ |
536 | 3014 | return name; |
537 | |
} |
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
|
544 | |
public String toString() |
545 | |
{ |
546 | 1264 | return getName(); |
547 | |
} |
548 | |
|
549 | |
public boolean isStopped() |
550 | |
{ |
551 | 9 | return stopped.get(); |
552 | |
} |
553 | |
|
554 | |
public boolean isStopping() |
555 | |
{ |
556 | 9 | return stopping.get(); |
557 | |
} |
558 | |
|
559 | |
protected void handleException(Exception e) |
560 | |
{ |
561 | 0 | exceptionListener.exceptionThrown(e); |
562 | 0 | } |
563 | |
|
564 | |
protected void doForceStop() throws MuleException |
565 | |
{ |
566 | |
|
567 | 0 | } |
568 | |
|
569 | |
protected void doStop() throws MuleException |
570 | |
{ |
571 | |
|
572 | 6 | } |
573 | |
|
574 | |
protected void doStart() throws MuleException |
575 | |
{ |
576 | |
|
577 | 6 | } |
578 | |
|
579 | |
protected void doDispose() |
580 | |
{ |
581 | |
|
582 | 12 | } |
583 | |
|
584 | |
protected void doInitialise() throws InitialisationException |
585 | |
{ |
586 | |
|
587 | 8 | } |
588 | |
|
589 | |
public boolean isStarted() |
590 | |
{ |
591 | 38 | return !stopped.get(); |
592 | |
} |
593 | |
|
594 | |
protected abstract MuleMessage doSend(MuleEvent event) throws MuleException; |
595 | |
|
596 | |
protected abstract void doDispatch(MuleEvent event) throws MuleException; |
597 | |
|
598 | |
protected void registerListeners() throws MuleException |
599 | |
{ |
600 | |
InboundEndpoint endpoint; |
601 | 20 | List endpoints = getIncomingEndpoints(); |
602 | |
|
603 | 20 | for (Iterator it = endpoints.iterator(); it.hasNext();) |
604 | |
{ |
605 | 8 | endpoint = (InboundEndpoint) it.next(); |
606 | |
try |
607 | |
{ |
608 | 8 | endpoint.getConnector().registerListener(this, endpoint); |
609 | |
} |
610 | 0 | catch (MuleException e) |
611 | |
{ |
612 | 0 | throw e; |
613 | |
} |
614 | 0 | catch (Exception e) |
615 | |
{ |
616 | 0 | throw new ModelException( |
617 | |
CoreMessages.failedtoRegisterOnEndpoint(name, endpoint.getEndpointURI()), e); |
618 | 8 | } |
619 | |
} |
620 | 20 | } |
621 | |
|
622 | |
protected void unregisterListeners() throws MuleException |
623 | |
{ |
624 | |
InboundEndpoint endpoint; |
625 | 20 | List endpoints = getIncomingEndpoints(); |
626 | |
|
627 | 20 | for (Iterator it = endpoints.iterator(); it.hasNext();) |
628 | |
{ |
629 | 8 | endpoint = (InboundEndpoint) it.next(); |
630 | |
try |
631 | |
{ |
632 | 8 | endpoint.getConnector().unregisterListener(this, endpoint); |
633 | |
} |
634 | 0 | catch (MuleException e) |
635 | |
{ |
636 | 0 | throw e; |
637 | |
} |
638 | 0 | catch (Exception e) |
639 | |
{ |
640 | 0 | throw new ModelException( |
641 | |
CoreMessages.failedToUnregister(name, endpoint.getEndpointURI()), e); |
642 | 8 | } |
643 | |
} |
644 | 20 | } |
645 | |
|
646 | |
protected void startListeners() throws MuleException |
647 | |
{ |
648 | |
InboundEndpoint endpoint; |
649 | 20 | List endpoints = getIncomingEndpoints(); |
650 | |
|
651 | 20 | for (Iterator it = endpoints.iterator(); it.hasNext();) |
652 | |
{ |
653 | 8 | endpoint = (InboundEndpoint) it.next(); |
654 | 8 | MessageReceiver receiver = ((AbstractConnector) endpoint.getConnector()).getReceiver(this, |
655 | |
endpoint); |
656 | 8 | if (receiver != null && endpoint.getConnector().isStarted() |
657 | |
&& endpoint.getInitialState().equals(ImmutableEndpoint.INITIAL_STATE_STARTED)) |
658 | |
{ |
659 | 8 | receiver.start(); |
660 | |
} |
661 | 8 | } |
662 | 20 | } |
663 | |
|
664 | |
|
665 | |
protected void stopListeners() throws MuleException |
666 | |
{ |
667 | |
InboundEndpoint endpoint; |
668 | 0 | List endpoints = getIncomingEndpoints(); |
669 | |
|
670 | 0 | for (Iterator it = endpoints.iterator(); it.hasNext();) |
671 | |
{ |
672 | 0 | endpoint = (InboundEndpoint) it.next(); |
673 | 0 | MessageReceiver receiver = ((AbstractConnector) endpoint.getConnector()).getReceiver(this, |
674 | |
endpoint); |
675 | 0 | if (receiver != null) |
676 | |
{ |
677 | 0 | receiver.stop(); |
678 | |
} |
679 | 0 | } |
680 | 0 | } |
681 | |
|
682 | |
protected void connectListeners() throws MuleException |
683 | |
{ |
684 | |
InboundEndpoint endpoint; |
685 | 20 | List endpoints = getIncomingEndpoints(); |
686 | |
|
687 | 20 | for (Iterator it = endpoints.iterator(); it.hasNext();) |
688 | |
{ |
689 | 8 | endpoint = (InboundEndpoint) it.next(); |
690 | 8 | MessageReceiver receiver = ((AbstractConnector) endpoint.getConnector()).getReceiver(this, |
691 | |
endpoint); |
692 | 8 | if (receiver != null) |
693 | |
{ |
694 | |
try |
695 | |
{ |
696 | 8 | receiver.connect(); |
697 | |
} |
698 | 0 | catch (Exception e) |
699 | |
{ |
700 | 0 | throw new ModelException( |
701 | |
MessageFactory.createStaticMessage("Failed to connect listener " |
702 | |
+ receiver + " for endpoint " + endpoint.getName()), |
703 | |
e); |
704 | 8 | } |
705 | |
} |
706 | 8 | } |
707 | 20 | } |
708 | |
|
709 | |
protected void disconnectListeners() throws MuleException |
710 | |
{ |
711 | |
InboundEndpoint endpoint; |
712 | 0 | List endpoints = getIncomingEndpoints(); |
713 | |
|
714 | 0 | for (Iterator it = endpoints.iterator(); it.hasNext();) |
715 | |
{ |
716 | 0 | endpoint = (InboundEndpoint) it.next(); |
717 | 0 | MessageReceiver receiver = ((AbstractConnector) endpoint.getConnector()).getReceiver(this, |
718 | |
endpoint); |
719 | 0 | if (receiver != null) |
720 | |
{ |
721 | |
try |
722 | |
{ |
723 | 0 | receiver.disconnect(); |
724 | |
} |
725 | 0 | catch (Exception e) |
726 | |
{ |
727 | 0 | throw new ModelException( |
728 | |
MessageFactory.createStaticMessage("Failed to disconnect listener " |
729 | |
+ receiver + " for endpoint " + endpoint.getName()), |
730 | |
e); |
731 | 0 | } |
732 | |
} |
733 | 0 | } |
734 | 0 | } |
735 | |
|
736 | |
|
737 | |
|
738 | |
|
739 | |
protected List getIncomingEndpoints() |
740 | |
{ |
741 | 80 | List endpoints = new ArrayList(); |
742 | |
|
743 | |
|
744 | 80 | endpoints.addAll(inboundRouter.getEndpoints()); |
745 | |
|
746 | |
|
747 | 80 | if (responseRouter != null |
748 | |
&& responseRouter.getEndpoints() != null) |
749 | |
{ |
750 | 80 | endpoints.addAll(responseRouter.getEndpoints()); |
751 | |
} |
752 | 80 | return endpoints; |
753 | |
} |
754 | |
|
755 | |
public void setMuleContext(MuleContext context) |
756 | |
{ |
757 | 400 | this.muleContext = context; |
758 | 400 | } |
759 | |
|
760 | |
|
761 | |
|
762 | |
|
763 | |
|
764 | |
public Model getModel() |
765 | |
{ |
766 | 526 | return model; |
767 | |
} |
768 | |
|
769 | |
public void setModel(Model model) |
770 | |
{ |
771 | 402 | this.model = model; |
772 | 402 | } |
773 | |
|
774 | |
public ExceptionListener getExceptionListener() |
775 | |
{ |
776 | 102 | return exceptionListener; |
777 | |
} |
778 | |
|
779 | |
public void setExceptionListener(ExceptionListener exceptionListener) |
780 | |
{ |
781 | 2 | this.exceptionListener = exceptionListener; |
782 | 2 | } |
783 | |
|
784 | |
public InboundRouterCollection getInboundRouter() |
785 | |
{ |
786 | 10 | return inboundRouter; |
787 | |
} |
788 | |
|
789 | |
public void setInboundRouter(InboundRouterCollection inboundRouter) |
790 | |
{ |
791 | 0 | this.inboundRouter = inboundRouter; |
792 | 0 | } |
793 | |
|
794 | |
public OutboundRouterCollection getOutboundRouter() |
795 | |
{ |
796 | 386 | return outboundRouter; |
797 | |
} |
798 | |
|
799 | |
public void setOutboundRouter(OutboundRouterCollection outboundRouter) |
800 | |
{ |
801 | 0 | this.outboundRouter = outboundRouter; |
802 | 0 | } |
803 | |
|
804 | |
public ResponseRouterCollection getResponseRouter() |
805 | |
{ |
806 | 16 | return responseRouter; |
807 | |
} |
808 | |
|
809 | |
public void setResponseRouter(ResponseRouterCollection responseRouter) |
810 | |
{ |
811 | 0 | this.responseRouter = responseRouter; |
812 | 0 | } |
813 | |
|
814 | |
public String getInitialState() |
815 | |
{ |
816 | 0 | return initialState; |
817 | |
} |
818 | |
|
819 | |
public void setInitialState(String initialState) |
820 | |
{ |
821 | 0 | this.initialState = initialState; |
822 | 0 | } |
823 | |
|
824 | |
public void setName(String name) |
825 | |
{ |
826 | 402 | this.name = name; |
827 | 402 | } |
828 | |
|
829 | |
public Component getComponent() |
830 | |
{ |
831 | 4 | return component; |
832 | |
} |
833 | |
|
834 | |
public void setComponent(Component component) |
835 | |
{ |
836 | 398 | this.component = component; |
837 | 398 | this.component.setService(this); |
838 | 398 | } |
839 | |
|
840 | |
protected void processReplyTo(MuleEvent event, MuleMessage result, ReplyToHandler replyToHandler, Object replyTo) |
841 | |
throws MuleException |
842 | |
{ |
843 | 0 | if (result != null && replyToHandler != null) |
844 | |
{ |
845 | 0 | String requestor = (String) result.getProperty(MuleProperties.MULE_REPLY_TO_REQUESTOR_PROPERTY); |
846 | 0 | if ((requestor != null && !requestor.equals(getName())) || requestor == null) |
847 | |
{ |
848 | 0 | replyToHandler.processReplyTo(event, result, replyTo); |
849 | |
} |
850 | |
} |
851 | 0 | } |
852 | |
|
853 | |
protected ReplyToHandler getReplyToHandler(MuleMessage message, InboundEndpoint endpoint) |
854 | |
{ |
855 | 0 | Object replyTo = message.getReplyTo(); |
856 | 0 | ReplyToHandler replyToHandler = null; |
857 | 0 | if (replyTo != null) |
858 | |
{ |
859 | 0 | replyToHandler = ((AbstractConnector) endpoint.getConnector()).getReplyToHandler(); |
860 | |
|
861 | 0 | if (endpoint.getResponseTransformers() != null) |
862 | |
{ |
863 | 0 | replyToHandler.setTransformers(endpoint.getResponseTransformers()); |
864 | |
} |
865 | |
} |
866 | 0 | return replyToHandler; |
867 | |
} |
868 | |
|
869 | |
|
870 | |
|
871 | |
|
872 | |
protected void dispatchToOutboundRouter(MuleEvent event, MuleMessage result) throws MessagingException |
873 | |
{ |
874 | 0 | if (event.isStopFurtherProcessing()) |
875 | |
{ |
876 | 0 | logger.debug("MuleEvent stop further processing has been set, no outbound routing will be performed."); |
877 | |
} |
878 | 0 | if (result != null && !event.isStopFurtherProcessing()) |
879 | |
{ |
880 | 0 | if (getOutboundRouter().hasEndpoints()) |
881 | |
{ |
882 | |
|
883 | 0 | getOutboundRouter().route(result, event.getSession(), event.isSynchronous()); |
884 | |
} |
885 | |
} |
886 | 0 | } |
887 | |
|
888 | |
|
889 | |
|
890 | |
|
891 | |
protected MuleMessage sendToOutboundRouter(MuleEvent event, MuleMessage result) throws MessagingException |
892 | |
{ |
893 | 0 | if (event.isStopFurtherProcessing()) |
894 | |
{ |
895 | 0 | logger.debug("MuleEvent stop further processing has been set, no outbound routing will be performed."); |
896 | |
} |
897 | 0 | if (result != null && !event.isStopFurtherProcessing()) |
898 | |
{ |
899 | 0 | if (getOutboundRouter().hasEndpoints()) |
900 | |
{ |
901 | |
|
902 | |
|
903 | |
|
904 | 0 | MuleMessage outboundReturnMessage = getOutboundRouter().route(new DefaultMuleMessage(result), event.getSession(), |
905 | |
event.isSynchronous()); |
906 | 0 | if (outboundReturnMessage != null) |
907 | |
{ |
908 | 0 | result = outboundReturnMessage; |
909 | |
} |
910 | 0 | } |
911 | |
else |
912 | |
{ |
913 | 0 | logger.debug("Outbound router on service '" + getName() + "' doesn't have any endpoints configured."); |
914 | |
} |
915 | |
} |
916 | 0 | return result; |
917 | |
} |
918 | |
|
919 | |
protected MuleMessage processAsyncReplyRouter(MuleMessage result) throws MuleException |
920 | |
{ |
921 | 0 | if (result != null && getResponseRouter() != null) |
922 | |
{ |
923 | 0 | logger.debug("Waiting for response router message"); |
924 | 0 | result = getResponseRouter().getResponse(result); |
925 | |
} |
926 | 0 | return result; |
927 | |
} |
928 | |
|
929 | |
public MuleContext getMuleContext() |
930 | |
{ |
931 | 54 | return muleContext; |
932 | |
} |
933 | |
|
934 | |
} |