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