01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.rice.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
24: .getLogger(BaseCompositeLifecycle.class);
25:
26: private List<Lifecycle> lifecycles;
27:
28: protected abstract List<Lifecycle> loadLifecycles()
29: 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: "
47: + lifecycle.getClass().getName(), t);
48: }
49: }
50: super .stop();
51: }
52:
53: private List<Lifecycle> reverseLifecycles() {
54: LinkedList<Lifecycle> reversed = new LinkedList<Lifecycle>();
55: for (Lifecycle lifecycle : this.lifecycles) {
56: reversed.addFirst(lifecycle);
57: }
58: return reversed;
59: }
60:
61: }
|