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.ArrayList;
25  import java.util.Iterator;
26  import java.util.List;
27  
28  public class NotificationCondition implements IWatchedCondition {
29  
30  
31      public static interface IConditionNotifier {
32  
33          void notifyCondition(IWatchedCondition cond);
34      }
35  
36      private List notifiers = new ArrayList();
37  
38      private boolean active = false;
39  
40      private boolean useless = false;
41  
42      public synchronized boolean isActive() {
43          return active;
44      }
45  
46      public synchronized void setActive(boolean active) {
47          this.active = active;
48      }
49  
50      public boolean checkCondition() {
51          return true;
52      }
53  
54      public void conditionViolated() {
55      }
56  
57  
58      public void addNotifier(IConditionNotifier notifier) {
59          if (!this.notifiers.contains(notifier)) {
60              this.notifiers.add(notifier);
61          }
62      }
63  
64  
65      protected void notifyCondition() {
66  
67          for (Iterator iterator = notifiers.iterator(); iterator.hasNext(); ) {
68              IConditionNotifier notifier = (IConditionNotifier) iterator.next();
69              notifier.notifyCondition(this);
70          }
71      }
72  
73  
74      public String toString() {
75          return "NotificationCondition ; has " + this.notifiers.size() + " notifier (active=" + this.isActive() + ")";
76      }
77  
78      protected void finalize() throws Throwable {
79          System.out.println("Condition " + this.toString() + " is finalized");
80          super.finalize();
81      }
82  
83      public synchronized boolean isUseless() {
84          return this.useless;
85      }
86  
87      public synchronized void setUseless(boolean mode) {
88          this.useless = mode;
89      }
90  
91  
92  }