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 public abstract class BaseCompositeLifecycle extends BaseLifecycle {
22
23 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 this.lifecycles = loadLifecycles();
32 for (Lifecycle lifecycle : this.lifecycles) {
33 lifecycle.start();
34 }
35 super.start();
36 }
37
38 @Override
39 public void stop() throws Exception {
40 for (Lifecycle lifecycle : reverseLifecycles()) {
41 try {
42 lifecycle.stop();
43 } catch (Throwable t) {
44 LOG.error("Failed to stop Lifecycle: " + lifecycle.getClass().getName(), t);
45 }
46 }
47 super.stop();
48 }
49
50 private List<Lifecycle> reverseLifecycles() {
51 LinkedList<Lifecycle> reversed = new LinkedList<Lifecycle>();
52 for (Lifecycle lifecycle : this.lifecycles) {
53 reversed.addFirst(lifecycle);
54 }
55 return reversed;
56 }
57
58 }