Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractMessageProcessorOwner |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | |
3 | * The software in this package is published under the terms of the CPAL v1.0 | |
4 | * license, a copy of which has been included with this distribution in the | |
5 | * LICENSE.txt file. | |
6 | */ | |
7 | package org.mule.processor; | |
8 | ||
9 | import org.mule.api.MuleContext; | |
10 | import org.mule.api.MuleException; | |
11 | import org.mule.api.construct.FlowConstruct; | |
12 | import org.mule.api.construct.FlowConstructAware; | |
13 | import org.mule.api.context.MuleContextAware; | |
14 | import org.mule.api.lifecycle.Disposable; | |
15 | import org.mule.api.lifecycle.Initialisable; | |
16 | import org.mule.api.lifecycle.InitialisationException; | |
17 | import org.mule.api.lifecycle.Lifecycle; | |
18 | import org.mule.api.lifecycle.Startable; | |
19 | import org.mule.api.lifecycle.Stoppable; | |
20 | import org.mule.api.processor.MessageProcessor; | |
21 | ||
22 | import java.util.List; | |
23 | ||
24 | /** | |
25 | * An object that owns message processors and delegates startup/shoutdown events to them | |
26 | */ | |
27 | 0 | public abstract class AbstractMessageProcessorOwner implements Lifecycle, MuleContextAware, FlowConstructAware |
28 | { | |
29 | protected MuleContext muleContext; | |
30 | protected FlowConstruct flowConstruct; | |
31 | ||
32 | public void setMuleContext(MuleContext context) | |
33 | { | |
34 | 0 | this.muleContext = context; |
35 | 0 | } |
36 | ||
37 | public void setFlowConstruct(FlowConstruct flowConstruct) | |
38 | { | |
39 | 0 | this.flowConstruct = flowConstruct; |
40 | 0 | } |
41 | ||
42 | public void initialise() throws InitialisationException | |
43 | { | |
44 | 0 | for (MessageProcessor processor : getOwnedMessageProcessors()) |
45 | { | |
46 | 0 | if (processor instanceof MuleContextAware) |
47 | { | |
48 | 0 | ((MuleContextAware) processor).setMuleContext(muleContext); |
49 | } | |
50 | 0 | if (processor instanceof FlowConstructAware) |
51 | { | |
52 | 0 | ((FlowConstructAware) processor).setFlowConstruct(flowConstruct); |
53 | } | |
54 | 0 | if (processor instanceof Initialisable) |
55 | { | |
56 | 0 | ((Initialisable) processor).initialise(); |
57 | } | |
58 | } | |
59 | 0 | } |
60 | ||
61 | public void dispose() | |
62 | { | |
63 | 0 | for (MessageProcessor processor : getOwnedMessageProcessors()) |
64 | { | |
65 | ||
66 | 0 | if (processor instanceof Disposable) |
67 | { | |
68 | 0 | ((Disposable) processor).dispose(); |
69 | } | |
70 | } | |
71 | 0 | } |
72 | ||
73 | ||
74 | public void start() throws MuleException | |
75 | { | |
76 | ||
77 | 0 | for (MessageProcessor processor : getOwnedMessageProcessors()) |
78 | { | |
79 | 0 | if (processor instanceof Startable) |
80 | { | |
81 | 0 | ((Startable) processor).start(); |
82 | } | |
83 | } | |
84 | 0 | } |
85 | ||
86 | ||
87 | public void stop() throws MuleException | |
88 | { | |
89 | ||
90 | 0 | for (MessageProcessor processor : getOwnedMessageProcessors()) |
91 | { | |
92 | 0 | if (processor instanceof Stoppable) |
93 | { | |
94 | 0 | ((Stoppable) processor).stop(); |
95 | } | |
96 | ||
97 | } | |
98 | 0 | } |
99 | ||
100 | protected abstract List<MessageProcessor> getOwnedMessageProcessors(); | |
101 | ||
102 | } | |
103 |