1 package org.csc.phynixx.watchdog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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 }