1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.lifecycle.processor; |
12 | |
|
13 | |
import org.mule.api.MuleEvent; |
14 | |
import org.mule.api.NamedObject; |
15 | |
import org.mule.api.lifecycle.LifecycleException; |
16 | |
import org.mule.api.lifecycle.LifecycleState; |
17 | |
import org.mule.api.lifecycle.Startable; |
18 | |
import org.mule.config.i18n.CoreMessages; |
19 | |
import org.mule.processor.AbstractFilteringMessageProcessor; |
20 | |
|
21 | |
public class ProcessIfStartedMessageProcessor extends AbstractFilteringMessageProcessor |
22 | |
{ |
23 | |
|
24 | |
protected Startable startable; |
25 | |
protected LifecycleState lifecycleState; |
26 | |
|
27 | |
public ProcessIfStartedMessageProcessor(Startable startable, LifecycleState lifecycleState) |
28 | 0 | { |
29 | 0 | this.startable = startable; |
30 | 0 | this.lifecycleState = lifecycleState; |
31 | 0 | } |
32 | |
|
33 | |
@Override |
34 | |
protected boolean accept(MuleEvent event) |
35 | |
{ |
36 | 0 | return lifecycleState.isStarted(); |
37 | |
} |
38 | |
|
39 | |
@Override |
40 | |
protected MuleEvent handleUnaccepted(MuleEvent event) throws LifecycleException |
41 | |
{ |
42 | 0 | throw new LifecycleException(CoreMessages.isStopped(getStartableName(startable)), event.getMessage()); |
43 | |
} |
44 | |
|
45 | |
protected String getStartableName(Startable startableObject) |
46 | |
{ |
47 | 0 | if (startableObject instanceof NamedObject) |
48 | |
{ |
49 | 0 | return ((NamedObject) startableObject).getName(); |
50 | |
} |
51 | |
else |
52 | |
{ |
53 | 0 | return startableObject.toString(); |
54 | |
} |
55 | |
} |
56 | |
|
57 | |
} |