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