1 /**
2  * Logback: the reliable, generic, fast and flexible logging framework.
3  * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4  *
5  * This program and the accompanying materials are dual-licensed under
6  * either the terms of the Eclipse Public License v1.0 as published by
7  * the Eclipse Foundation
8  *
9  *   or (per the licensee's choosing)
10  *
11  * under the terms of the GNU Lesser General Public License version 2.1
12  * as published by the Free Software Foundation.
13  */

14 package ch.qos.logback.core;
15
16 import java.util.HashSet;
17 import java.util.Set;
18
19 import ch.qos.logback.core.spi.LifeCycle;
20
21 /**
22  * An object that manages a collection of components that implement the
23  * {@link LifeCycle} interface.  Each component that is added to the manager
24  * will be stopped and removed from the manager when the manager is reset.
25  *
26  * @author Carl Harris
27  */

28 public class LifeCycleManager {
29
30     private final Set<LifeCycle> components = new HashSet<LifeCycle>();
31
32     /**
33      * Registers a component with this manager.  
34      * <p>
35      * @param component the component whose life cycle is to be managed
36      */

37     public void register(LifeCycle component) {
38         components.add(component);
39     }
40
41     /**
42      * Resets this manager.
43      * <p>
44      * All registered components are stopped and removed from the manager.
45      */

46     public void reset() {
47         for (LifeCycle component : components) {
48             if (component.isStarted()) {
49                 component.stop();
50             }
51         }
52         components.clear();
53     }
54
55 }
56