1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.lifecycle; |
17 | |
|
18 | |
import java.util.LinkedList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.kuali.rice.core.lifecycle.Lifecycle; |
22 | |
|
23 | 0 | public abstract class BaseCompositeLifecycle extends BaseLifecycle { |
24 | |
|
25 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BaseCompositeLifecycle.class); |
26 | |
|
27 | |
private List<Lifecycle> lifecycles; |
28 | |
|
29 | |
protected abstract List<Lifecycle> loadLifecycles() throws Exception; |
30 | |
|
31 | |
@Override |
32 | |
public void start() throws Exception { |
33 | 0 | this.lifecycles = loadLifecycles(); |
34 | 0 | for (Lifecycle lifecycle : this.lifecycles) { |
35 | 0 | lifecycle.start(); |
36 | |
} |
37 | 0 | super.start(); |
38 | 0 | } |
39 | |
|
40 | |
@Override |
41 | |
public void stop() throws Exception { |
42 | 0 | for (Lifecycle lifecycle : reverseLifecycles()) { |
43 | |
try { |
44 | 0 | lifecycle.stop(); |
45 | 0 | } catch (Throwable t) { |
46 | 0 | LOG.error("Failed to stop Lifecycle: " + lifecycle.getClass().getName(), t); |
47 | 0 | } |
48 | |
} |
49 | 0 | super.stop(); |
50 | 0 | } |
51 | |
|
52 | |
private List<Lifecycle> reverseLifecycles() { |
53 | 0 | LinkedList<Lifecycle> reversed = new LinkedList<Lifecycle>(); |
54 | 0 | for (Lifecycle lifecycle : this.lifecycles) { |
55 | 0 | reversed.addFirst(lifecycle); |
56 | |
} |
57 | 0 | return reversed; |
58 | |
} |
59 | |
|
60 | |
} |