1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| package org.jboss.cache; |
24 |
| |
25 |
| import org.apache.commons.logging.Log; |
26 |
| import org.apache.commons.logging.LogFactory; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| public enum CacheStatus |
37 |
| { |
38 |
| |
39 |
| |
40 |
| |
41 |
| INSTANTIATED, |
42 |
| |
43 |
| |
44 |
| |
45 |
| CREATING, |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| CREATED, |
51 |
| |
52 |
| |
53 |
| |
54 |
| STARTING, |
55 |
| |
56 |
| |
57 |
| |
58 |
| STARTED, |
59 |
| |
60 |
| |
61 |
| |
62 |
| STOPPING, |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| STOPPED, |
68 |
| |
69 |
| |
70 |
| |
71 |
| DESTROYING, |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| DESTROYED, |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| FAILED; |
83 |
| |
84 |
| private static final Log log = LogFactory.getLog(CacheStatus.class); |
85 |
| |
86 |
2925
| public boolean createAllowed()
|
87 |
| { |
88 |
2925
| switch(this)
|
89 |
| { |
90 |
0
| case CREATING:
|
91 |
17
| case CREATED:
|
92 |
0
| case STARTING:
|
93 |
16
| case STARTED:
|
94 |
0
| case STOPPED:
|
95 |
33
| log.debug("Ignoring call to create() as current state is " + this);
|
96 |
| |
97 |
0
| case FAILED:
|
98 |
33
| return false;
|
99 |
0
| case STOPPING:
|
100 |
0
| case DESTROYING:
|
101 |
0
| log.warn("Ignoring call to create() while cache is " + this);
|
102 |
0
| return false;
|
103 |
2862
| case INSTANTIATED:
|
104 |
30
| case DESTROYED:
|
105 |
0
| default:
|
106 |
2892
| return true;
|
107 |
| } |
108 |
| } |
109 |
| |
110 |
1596
| public boolean needToDestroyFailedCache()
|
111 |
| { |
112 |
1596
| if (this == CacheStatus.FAILED)
|
113 |
| { |
114 |
3
| log.debug("need to call destroy() since current state is " +
|
115 |
| this); |
116 |
3
| return true;
|
117 |
| } |
118 |
| |
119 |
1593
| return false;
|
120 |
| } |
121 |
| |
122 |
2910
| public boolean startAllowed()
|
123 |
| { |
124 |
2910
| switch(this)
|
125 |
| { |
126 |
1517
| case INSTANTIATED:
|
127 |
17
| case DESTROYED:
|
128 |
0
| case STARTING:
|
129 |
26
| case STARTED:
|
130 |
1560
| log.debug("Ignoring call to start() as current state is " + this);
|
131 |
| |
132 |
3
| case FAILED:
|
133 |
1563
| return false;
|
134 |
0
| case STOPPING:
|
135 |
0
| case DESTROYING:
|
136 |
0
| log.warn("Ignoring call to start() as current state is " + this);
|
137 |
0
| return false;
|
138 |
1339
| case CREATED:
|
139 |
8
| case STOPPED:
|
140 |
0
| default:
|
141 |
1347
| return true;
|
142 |
| } |
143 |
| } |
144 |
| |
145 |
1563
| public boolean needCreateBeforeStart()
|
146 |
| { |
147 |
1563
| switch(this)
|
148 |
| { |
149 |
1517
| case INSTANTIATED:
|
150 |
20
| case DESTROYED:
|
151 |
1537
| log.debug("start() called while current state is " +
|
152 |
| this + " -- call create() first"); |
153 |
1537
| return true;
|
154 |
26
| default:
|
155 |
26
| return false;
|
156 |
| } |
157 |
| } |
158 |
| |
159 |
4626
| public boolean stopAllowed()
|
160 |
| { |
161 |
4845
| switch(this)
|
162 |
| { |
163 |
52
| case INSTANTIATED:
|
164 |
4
| case CREATED:
|
165 |
967
| case STOPPED:
|
166 |
968
| case DESTROYED:
|
167 |
1991
| log.debug("Ignoring call to stop() as current state is " + this);
|
168 |
1960
| return false;
|
169 |
0
| case CREATING:
|
170 |
0
| case STARTING:
|
171 |
0
| case STOPPING:
|
172 |
0
| case DESTROYING:
|
173 |
0
| log.warn("Ignoring call to stop() as current state is " + this);
|
174 |
0
| return false;
|
175 |
16
| case FAILED:
|
176 |
2838
| case STARTED:
|
177 |
0
| default:
|
178 |
2854
| return true;
|
179 |
| } |
180 |
| |
181 |
| } |
182 |
| |
183 |
1517
| public boolean destroyAllowed()
|
184 |
| { |
185 |
1517
| switch(this)
|
186 |
| { |
187 |
28
| case INSTANTIATED:
|
188 |
29
| case DESTROYED:
|
189 |
57
| log.debug("Ignoring call to destroy() as current state is " + this);
|
190 |
57
| return false;
|
191 |
0
| case CREATING:
|
192 |
0
| case STARTING:
|
193 |
0
| case STOPPING:
|
194 |
0
| case DESTROYING:
|
195 |
0
| log.warn("Ignoring call to destroy() as current state iswhile cache is " + this);
|
196 |
0
| return false;
|
197 |
10
| case STARTED:
|
198 |
| |
199 |
10
| return false;
|
200 |
9
| case CREATED:
|
201 |
1436
| case STOPPED:
|
202 |
5
| case FAILED:
|
203 |
0
| default:
|
204 |
1450
| return true;
|
205 |
| } |
206 |
| } |
207 |
| |
208 |
67
| public boolean needStopBeforeDestroy()
|
209 |
| { |
210 |
67
| if (this == CacheStatus.STARTED)
|
211 |
| { |
212 |
10
| log.warn("destroy() called while current state is " +
|
213 |
| this + " -- call stop() first"); |
214 |
10
| return true;
|
215 |
| } |
216 |
| |
217 |
57
| return false;
|
218 |
| } |
219 |
| } |