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