1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.construct; |
11 | |
|
12 | |
import org.mule.api.MuleException; |
13 | |
import org.mule.api.construct.FlowConstruct; |
14 | |
import org.mule.api.lifecycle.Disposable; |
15 | |
import org.mule.api.lifecycle.Initialisable; |
16 | |
import org.mule.api.lifecycle.LifecycleCallback; |
17 | |
import org.mule.api.lifecycle.Startable; |
18 | |
import org.mule.api.lifecycle.Stoppable; |
19 | |
import org.mule.context.notification.FlowConstructNotification; |
20 | |
import org.mule.lifecycle.SimpleLifecycleManager; |
21 | |
import org.mule.service.Pausable; |
22 | |
import org.mule.service.Resumable; |
23 | |
|
24 | |
import org.apache.commons.logging.Log; |
25 | |
import org.apache.commons.logging.LogFactory; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class FlowConstructLifecycleManager extends SimpleLifecycleManager<FlowConstruct> |
32 | |
{ |
33 | |
|
34 | |
|
35 | |
|
36 | 0 | protected transient final Log logger = LogFactory.getLog(FlowConstructLifecycleManager.class); |
37 | |
|
38 | |
|
39 | |
public FlowConstructLifecycleManager(FlowConstruct flowConstruct) |
40 | |
{ |
41 | 0 | super(flowConstruct.getName(), flowConstruct); |
42 | 0 | } |
43 | |
|
44 | |
@Override |
45 | |
protected void registerTransitions() |
46 | |
{ |
47 | 0 | super.registerTransitions(); |
48 | |
|
49 | |
|
50 | 0 | addDirectTransition(Startable.PHASE_NAME, Pausable.PHASE_NAME); |
51 | |
|
52 | 0 | addDirectTransition(Pausable.PHASE_NAME, Resumable.PHASE_NAME); |
53 | 0 | addDirectTransition(Pausable.PHASE_NAME, Stoppable.PHASE_NAME); |
54 | 0 | } |
55 | |
|
56 | |
@Override |
57 | |
protected void notifyTransition(String currentPhase) |
58 | |
{ |
59 | 0 | if(currentPhase.equals(Resumable.PHASE_NAME)) |
60 | |
{ |
61 | |
|
62 | 0 | completedPhases.remove(Resumable.PHASE_NAME); |
63 | 0 | completedPhases.remove(Pausable.PHASE_NAME); |
64 | 0 | setCurrentPhase(Startable.PHASE_NAME); |
65 | |
} |
66 | 0 | } |
67 | |
|
68 | |
@Override |
69 | |
public void fireInitialisePhase(LifecycleCallback<FlowConstruct> callback) throws MuleException |
70 | |
{ |
71 | 0 | checkPhase(Initialisable.PHASE_NAME); |
72 | |
|
73 | 0 | if(logger.isInfoEnabled()) logger.info("Initialising flow: " + getLifecycleObject().getName()); |
74 | 0 | invokePhase(Initialisable.PHASE_NAME, getLifecycleObject(), callback); |
75 | 0 | fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_INITIALISED); |
76 | 0 | } |
77 | |
|
78 | |
|
79 | |
@Override |
80 | |
public void fireStartPhase(LifecycleCallback<FlowConstruct> callback) throws MuleException |
81 | |
{ |
82 | 0 | checkPhase(Startable.PHASE_NAME); |
83 | 0 | if(logger.isInfoEnabled()) logger.info("Starting flow: " + getLifecycleObject().getName()); |
84 | |
|
85 | 0 | invokePhase(Startable.PHASE_NAME, getLifecycleObject(), callback); |
86 | 0 | fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_STARTED); |
87 | 0 | } |
88 | |
|
89 | |
|
90 | |
public void firePausePhase(LifecycleCallback<FlowConstruct> callback) throws MuleException |
91 | |
{ |
92 | 0 | checkPhase(Pausable.PHASE_NAME); |
93 | 0 | if(logger.isInfoEnabled()) logger.info("Pausing flow: " + getLifecycleObject().getName()); |
94 | |
|
95 | |
|
96 | 0 | invokePhase(Pausable.PHASE_NAME, getLifecycleObject(), callback); |
97 | 0 | fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_PAUSED); |
98 | 0 | } |
99 | |
|
100 | |
public void fireResumePhase(LifecycleCallback<FlowConstruct> callback) throws MuleException |
101 | |
{ |
102 | 0 | checkPhase(Resumable.PHASE_NAME); |
103 | 0 | if(logger.isInfoEnabled()) logger.info("Resuming flow: " + getLifecycleObject().getName()); |
104 | |
|
105 | 0 | invokePhase(Resumable.PHASE_NAME, getLifecycleObject(), callback); |
106 | 0 | fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_RESUMED); |
107 | 0 | } |
108 | |
|
109 | |
@Override |
110 | |
public void fireStopPhase(LifecycleCallback<FlowConstruct> callback) throws MuleException |
111 | |
{ |
112 | 0 | checkPhase(Stoppable.PHASE_NAME); |
113 | 0 | if(logger.isInfoEnabled()) logger.info("Stopping flow: " + getLifecycleObject().getName()); |
114 | |
|
115 | 0 | invokePhase(Stoppable.PHASE_NAME, getLifecycleObject(), callback); |
116 | 0 | fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_STOPPED); |
117 | 0 | } |
118 | |
|
119 | |
@Override |
120 | |
public void fireDisposePhase(LifecycleCallback<FlowConstruct> callback) throws MuleException |
121 | |
{ |
122 | 0 | checkPhase(Disposable.PHASE_NAME); |
123 | 0 | if(logger.isInfoEnabled()) logger.info("Disposing flow: " + getLifecycleObject().getName()); |
124 | |
|
125 | 0 | invokePhase(Disposable.PHASE_NAME, getLifecycleObject(), callback); |
126 | 0 | fireNotification(FlowConstructNotification.FLOW_CONSTRUCT_DISPOSED); |
127 | 0 | } |
128 | |
|
129 | |
protected void fireNotification(int action) |
130 | |
{ |
131 | 0 | getLifecycleObject().getMuleContext().fireNotification(new FlowConstructNotification(getLifecycleObject(), action)); |
132 | 0 | } |
133 | |
} |