1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.routing; |
12 | |
|
13 | |
import org.apache.commons.lang.Validate; |
14 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
15 | |
import org.apache.commons.lang.builder.ToStringStyle; |
16 | |
import org.mule.api.MuleException; |
17 | |
import org.mule.api.construct.FlowConstruct; |
18 | |
import org.mule.api.construct.FlowConstructAware; |
19 | |
import org.mule.api.lifecycle.Disposable; |
20 | |
import org.mule.api.lifecycle.Initialisable; |
21 | |
import org.mule.api.lifecycle.InitialisationException; |
22 | |
import org.mule.api.lifecycle.Lifecycle; |
23 | |
import org.mule.api.lifecycle.Startable; |
24 | |
import org.mule.api.lifecycle.Stoppable; |
25 | |
import org.mule.api.processor.MessageProcessor; |
26 | |
import org.mule.api.routing.filter.Filter; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class MessageProcessorFilterPair implements FlowConstructAware, Lifecycle |
32 | |
{ |
33 | |
private final MessageProcessor messageProcessor; |
34 | |
private final Filter filter; |
35 | |
|
36 | |
public MessageProcessorFilterPair(MessageProcessor messageProcessor, Filter filter) |
37 | 0 | { |
38 | 0 | Validate.notNull(messageProcessor, "messageProcessor can't be null"); |
39 | 0 | Validate.notNull(filter, "filter can't be null"); |
40 | 0 | this.messageProcessor = messageProcessor; |
41 | 0 | this.filter = filter; |
42 | 0 | } |
43 | |
|
44 | |
public MessageProcessor getMessageProcessor() |
45 | |
{ |
46 | 0 | return messageProcessor; |
47 | |
} |
48 | |
|
49 | |
public Filter getFilter() |
50 | |
{ |
51 | 0 | return filter; |
52 | |
} |
53 | |
|
54 | |
@Override |
55 | |
public String toString() |
56 | |
{ |
57 | 0 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
58 | |
} |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public void setFlowConstruct(FlowConstruct flowConstruct) |
64 | |
{ |
65 | 0 | if (messageProcessor instanceof FlowConstructAware) |
66 | |
{ |
67 | 0 | ((FlowConstructAware) messageProcessor).setFlowConstruct(flowConstruct); |
68 | |
} |
69 | 0 | if (filter instanceof FlowConstructAware) |
70 | |
{ |
71 | 0 | ((FlowConstructAware) filter).setFlowConstruct(flowConstruct); |
72 | |
} |
73 | 0 | } |
74 | |
|
75 | |
public void initialise() throws InitialisationException |
76 | |
{ |
77 | 0 | if (messageProcessor instanceof Initialisable) |
78 | |
{ |
79 | 0 | ((Initialisable) messageProcessor).initialise(); |
80 | |
} |
81 | 0 | if (filter instanceof Initialisable) |
82 | |
{ |
83 | 0 | ((Initialisable) filter).initialise(); |
84 | |
} |
85 | 0 | } |
86 | |
|
87 | |
public void start() throws MuleException |
88 | |
{ |
89 | 0 | if (messageProcessor instanceof Startable) |
90 | |
{ |
91 | 0 | ((Startable) messageProcessor).start(); |
92 | |
} |
93 | 0 | if (filter instanceof Startable) |
94 | |
{ |
95 | 0 | ((Startable) filter).start(); |
96 | |
} |
97 | 0 | } |
98 | |
|
99 | |
public void stop() throws MuleException |
100 | |
{ |
101 | 0 | if (messageProcessor instanceof Stoppable) |
102 | |
{ |
103 | 0 | ((Stoppable) messageProcessor).stop(); |
104 | |
} |
105 | 0 | if (filter instanceof Stoppable) |
106 | |
{ |
107 | 0 | ((Stoppable) filter).stop(); |
108 | |
} |
109 | 0 | } |
110 | |
|
111 | |
public void dispose() |
112 | |
{ |
113 | 0 | if (messageProcessor instanceof Disposable) |
114 | |
{ |
115 | 0 | ((Disposable) messageProcessor).dispose(); |
116 | |
} |
117 | 0 | if (filter instanceof Disposable) |
118 | |
{ |
119 | 0 | ((Disposable) filter).dispose(); |
120 | |
} |
121 | 0 | } |
122 | |
} |