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