1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.registry.impl; |
12 | |
|
13 | |
import org.mule.registry.Assembly; |
14 | |
import org.mule.registry.Registry; |
15 | |
import org.mule.registry.RegistryComponent; |
16 | |
import org.mule.registry.RegistryException; |
17 | |
import org.mule.registry.Unit; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
public abstract class AbstractUnit extends AbstractEntry implements Unit |
23 | |
{ |
24 | |
|
25 | |
private String assembly; |
26 | |
|
27 | |
protected AbstractUnit(Registry registry) |
28 | |
{ |
29 | 0 | super(registry); |
30 | 0 | } |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public Assembly getAssembly() |
38 | |
{ |
39 | 0 | return getRegistry().getAssembly(this.assembly); |
40 | |
} |
41 | |
|
42 | |
public void setAssembly(Assembly assembly) |
43 | |
{ |
44 | 0 | this.assembly = assembly.getName(); |
45 | 0 | } |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public final synchronized String deploy() throws RegistryException |
53 | |
{ |
54 | 0 | if (!getCurrentState().equals(UNKNOWN)) |
55 | |
{ |
56 | 0 | throw new RegistryException("Illegal status: " + getCurrentState()); |
57 | |
} |
58 | 0 | String result = null; |
59 | |
try |
60 | |
{ |
61 | 0 | result = doDeploy(); |
62 | |
} |
63 | 0 | catch (Exception e) |
64 | |
{ |
65 | 0 | throw new RegistryException(e); |
66 | 0 | } |
67 | |
|
68 | 0 | getRegistryComponent().addUnit(this); |
69 | 0 | ((AbstractAssembly)getAssembly()).addUnit(this); |
70 | 0 | setCurrentState(STOPPED); |
71 | 0 | return result; |
72 | |
} |
73 | |
|
74 | |
public abstract String doDeploy() throws Exception; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public final synchronized void init() throws RegistryException |
82 | |
{ |
83 | 0 | if (!getCurrentState().equals(UNKNOWN)) |
84 | |
{ |
85 | 0 | throw new RegistryException("Illegal status: " + getCurrentState()); |
86 | |
} |
87 | |
try |
88 | |
{ |
89 | 0 | doInit(); |
90 | |
} |
91 | 0 | catch (Exception e) |
92 | |
{ |
93 | 0 | throw new RegistryException(e); |
94 | 0 | } |
95 | 0 | setCurrentState(STOPPED); |
96 | 0 | } |
97 | |
|
98 | |
protected abstract void doInit() throws Exception; |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public final synchronized void start() throws RegistryException |
106 | |
{ |
107 | 0 | if (getCurrentState().equals(UNKNOWN)) |
108 | |
{ |
109 | 0 | throw new RegistryException("Illegal status: " + getCurrentState()); |
110 | |
} |
111 | 0 | if (!getCurrentState().equals(RUNNING)) |
112 | |
{ |
113 | |
try |
114 | |
{ |
115 | 0 | doStart(); |
116 | |
} |
117 | 0 | catch (Exception e) |
118 | |
{ |
119 | 0 | throw new RegistryException(e); |
120 | 0 | } |
121 | 0 | setCurrentState(RUNNING); |
122 | |
} |
123 | 0 | } |
124 | |
|
125 | |
protected abstract void doStart() throws Exception; |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
public final synchronized void stop() throws RegistryException |
133 | |
{ |
134 | 0 | if (getCurrentState().equals(UNKNOWN) || getCurrentState().equals(SHUTDOWN)) |
135 | |
{ |
136 | 0 | throw new RegistryException("Illegal status: " + getCurrentState()); |
137 | |
} |
138 | 0 | if (!getCurrentState().equals(STOPPED)) |
139 | |
{ |
140 | |
try |
141 | |
{ |
142 | 0 | doStop(); |
143 | |
} |
144 | 0 | catch (Exception e) |
145 | |
{ |
146 | 0 | throw new RegistryException(e); |
147 | 0 | } |
148 | 0 | setCurrentState(STOPPED); |
149 | |
} |
150 | 0 | } |
151 | |
|
152 | |
protected abstract void doStop() throws Exception; |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public final synchronized void shutDown() throws RegistryException |
160 | |
{ |
161 | 0 | if (getCurrentState().equals(UNKNOWN)) |
162 | |
{ |
163 | 0 | throw new RegistryException("Illegal status: " + getCurrentState()); |
164 | |
} |
165 | 0 | if (!getCurrentState().equals(SHUTDOWN)) |
166 | |
{ |
167 | 0 | stop(); |
168 | |
try |
169 | |
{ |
170 | 0 | doShutDown(); |
171 | |
} |
172 | 0 | catch (Exception e) |
173 | |
{ |
174 | 0 | throw new RegistryException(e); |
175 | 0 | } |
176 | 0 | setCurrentState(SHUTDOWN); |
177 | |
} |
178 | 0 | } |
179 | |
|
180 | |
protected abstract void doShutDown() throws Exception; |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
public synchronized String undeploy() throws RegistryException |
188 | |
{ |
189 | 0 | if (!getCurrentState().equals(SHUTDOWN)) |
190 | |
{ |
191 | 0 | throw new RegistryException("Illegal status: " + getCurrentState()); |
192 | |
} |
193 | 0 | String result = null; |
194 | |
try |
195 | |
{ |
196 | 0 | result = doUndeploy(); |
197 | |
} |
198 | 0 | catch (Exception e) |
199 | |
{ |
200 | 0 | throw new RegistryException(e); |
201 | 0 | } |
202 | |
|
203 | 0 | getRegistryComponent().removeUnit(this); |
204 | 0 | ((AbstractAssembly)getAssembly()).removeUnit(this); |
205 | 0 | setCurrentState(UNKNOWN); |
206 | 0 | return result; |
207 | |
} |
208 | |
|
209 | |
protected abstract String doUndeploy() throws Exception; |
210 | |
|
211 | |
public void setRegistryComponent(RegistryComponent component) |
212 | |
{ |
213 | |
|
214 | 0 | } |
215 | |
|
216 | |
} |