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