View Javadoc

1   package org.csc.phynixx.watchdog.jmx;
2   
3   /*
4    * #%L
5    * phynixx-jmx
6    * %%
7    * Copyright (C) 2014 csc
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  
24  import org.csc.phynixx.watchdog.IWatchdog;
25  import org.csc.phynixx.watchdog.WatchdogInfo;
26  import org.csc.phynixx.watchdog.WatchdogRegistry;
27  
28  public class WatchdogManagement implements WatchdogManagementMBean {
29  
30      public int getCountWatchDogs() throws Exception {
31          return WatchdogRegistry.getTheRegistry().getCountWatchdogs();
32      }
33  
34      public void restart() throws Exception {
35  
36          WatchdogRegistry.getTheRegistry().restart();
37      }
38  
39      public void stop() throws Exception {
40          WatchdogRegistry.getTheRegistry().stop();
41      }
42  
43  
44      public String[] getWatchdogInfos() throws Exception {
45          WatchdogInfo[] infos = WatchdogRegistry.getTheRegistry().getWatchdogInfos();
46          String[] wds = new String[infos.length];
47          for (int j = 0; j < infos.length; j++) {
48              wds[j] = infos[j].getWatchdogInfo();
49          }
50          return wds;
51      }
52  
53  
54      public String[][] showWatchdogInfos() {
55          return WatchdogRegistry.getTheRegistry().showWatchdogInfos();
56      }
57  
58      public String[] showWatchdogInfo(long id) throws Exception {
59          IWatchdog wd = WatchdogRegistry.getTheRegistry().resolveWatchdogId(new Long(id));
60          if (wd == null) {
61              throw new IllegalArgumentException("ID=" + id + " could not be resolved -> no valid ID");
62          }
63          return new WatchdogInfo(wd).getWatchdogInfos();
64      }
65  
66  
67      public void restart(long id) throws Exception {
68  
69          IWatchdog wd = WatchdogRegistry.getTheRegistry().resolveWatchdogId(new Long(id));
70          if (wd == null) {
71              throw new IllegalArgumentException("ID=" + id + " could not be resolved -> no valid ID");
72          }
73          WatchdogRegistry.getTheRegistry().restart(wd.getId());
74  
75  
76      }
77  
78      public void stop(long id) throws Exception {
79  
80          IWatchdog wd = WatchdogRegistry.getTheRegistry().resolveWatchdogId(new Long(id));
81          if (wd == null) {
82              throw new IllegalArgumentException("ID=" + id + " could not be resolved -> no valid ID");
83          }
84  
85          WatchdogRegistry.getTheRegistry().stop(wd.getId());
86  
87      }
88  
89      public void shutdown(long id) throws Exception {
90  
91          IWatchdog wd = WatchdogRegistry.getTheRegistry().resolveWatchdogId(new Long(id));
92          if (wd == null) {
93              throw new IllegalArgumentException("ID=" + id + " could not be resolved -> no valid ID");
94          }
95  
96          WatchdogRegistry.getTheRegistry().shutdown(wd.getId());
97  
98      }
99  
100     public void activate(long id) throws Exception {
101 
102         IWatchdog wd = WatchdogRegistry.getTheRegistry().resolveWatchdogId(new Long(id));
103         if (wd == null) {
104             throw new IllegalArgumentException("ID=" + id + " could not be resolved -> no valid ID");
105         }
106 
107         WatchdogRegistry.getTheRegistry().activate(wd.getId());
108 
109     }
110 
111     public void deactivate(long id) throws Exception {
112 
113         IWatchdog wd = WatchdogRegistry.getTheRegistry().resolveWatchdogId(new Long(id));
114         if (wd == null) {
115             throw new IllegalArgumentException("ID=" + id + " could not be resolved -> no valid ID");
116         }
117 
118         WatchdogRegistry.getTheRegistry().deactivate(wd.getId());
119 
120     }
121 
122 
123 }