View Javadoc

1   package org.csc.phynixx.watchdog;
2   
3   /*
4    * #%L
5    * phynixx-watchdog
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 java.util.Set;
25  
26  /**
27   *
28   * references a Watchdog by the ID identifing the Watchdog in the watchdog's registry
29   *
30   */
31  public class WatchdogReference implements IWatchdog {
32  
33      private Long id = null;
34  
35      public WatchdogReference(Long id) {
36          super();
37          this.id = id;
38      }
39  
40  
41      public WatchdogReference(IWatchdog wd) {
42          this(wd.getId());
43      }
44  
45      public Long getId() {
46          return id;
47      }
48  
49  
50      Watchdog getWatchdog() {
51          Watchdog wd =
52                  WatchdogRegistry.getTheRegistry().findWatchdog(id);
53          if (wd == null) {
54              throw new IllegalStateException("Watchdog is stale and does not exist any longer");
55          }
56          return wd;
57      }
58  
59      public boolean isStale() {
60          return WatchdogRegistry.getTheRegistry().findWatchdog(id) == null;
61      }
62  
63  
64      public void activate() {
65          this.getWatchdog().activate();
66      }
67  
68  
69      public void deactivate() {
70          this.getWatchdog().deactivate();
71  
72      }
73  
74  
75      public Set<IWatchedCondition> getAliveConditions() {
76          return this.getWatchdog().getAliveConditions();
77      }
78  
79  
80      public long getCheckInterval() {
81          return this.getWatchdog().getCheckInterval();
82      }
83  
84  
85      public String[] getConditionInfos() {
86          return this.getWatchdog().getConditionInfos();
87      }
88  
89  
90      public int getCountRegisteredConditions() {
91          return this.getWatchdog().getCountRegisteredConditions();
92      }
93  
94  
95      public String getWatchdogInfo() {
96          return this.getWatchdog().getWatchdogInfo();
97      }
98  
99  
100     public boolean isAlive() {
101         return this.getWatchdog().isAlive();
102     }
103 
104 
105     public boolean isKilled() {
106         return this.getWatchdog().isKilled();
107     }
108 
109 
110     public boolean isUseless() {
111         return this.getWatchdog().isUseless();
112     }
113 
114 
115     public void registerCondition(IWatchedCondition cond) {
116         this.getWatchdog().registerCondition(cond);
117 
118     }
119 
120 
121     public void unregisterCondition(IWatchedCondition cond) {
122         this.getWatchdog().unregisterCondition(cond);
123     }
124 
125 }