View Javadoc

1   package org.jmux.app.component;
2   
3   import org.jmux.app.App;
4   import org.jmux.app.LifecycleListener;
5   import org.jmux.app.component.config.Config;
6   import org.jmux.app.component.jmx.Access;
7   import org.jmux.app.component.jmx.JMX;
8   
9   import java.util.ArrayList;
10  import java.util.List;
11  
12  /******************************************************************************
13   jmux - Java Modules Using XML
14   Copyright © 2006 jmux.org
15  
16   This library is free software; you can redistribute it and/or
17   modify it under the terms of the GNU Lesser General Public
18   License as published by the Free Software Foundation; either
19   version 2.1 of the License, or (at your option) any later version.
20  
21   This library is distributed in the hope that it will be useful,
22   but WITHOUT ANY WARRANTY; without even the implied warranty of
23   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24   Lesser General Public License for more details.
25  
26   You should have received a copy of the GNU Lesser General Public
27   License along with this library; if not, write to the Free Software
28   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
29   *****************************************************************************/
30  
31  /***
32   * @author donaldw
33   */
34  public class ControlManager extends AbstractControl implements LifecycleListener {
35  
36      @JMX(Access.READ)
37      private final List<String> controls = new ArrayList<String>();
38  
39      private App app;
40  
41      public void configure(Config config, App app) {
42          super.configure(config, app);
43          this.app = app;
44  
45          List<Config> controlConfigs = config.getConfs("control");
46          for (Config controlConfig : controlConfigs) {
47              controls.add(controlConfig.getString(null));
48          }
49  
50          app.registerLifecycleListener(this);
51  
52          //JMXComponent.registerWebServer();
53      }
54  
55      @JMX
56      public void start() {
57          log("Start invoked");
58          for (String controlName : controls) {
59              log("Starting: " + controlName);
60              ((Control) (app.getComponent(controlName))).start();
61          }
62      }
63  
64      @JMX
65      public void stop() {
66          log("Stop invoked");
67          for (String controlName : controls) {
68              log("Stopping: " + controlName);
69              ((Control) (app.getComponent(controlName))).stop();
70          }
71      }
72  
73      public void startup() {
74          start();
75      }
76  
77      public void shutdown() {
78          stop();
79      }
80  }