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