Methods Summary |
---|
public void | addTimeoutObserver(TimeoutObserver to)Add a timeout observer.
//no need to synchronize, as Vector is always synchronized
observers.addElement(to);
|
protected final void | fireTimeoutOccured()Inform the observers that a timeout has occurred.
This happens in the watchdog thread.
Enumeration e = observers.elements();
while (e.hasMoreElements()) {
((TimeoutObserver) e.nextElement()).timeoutOccured(this);
}
|
public void | removeTimeoutObserver(TimeoutObserver to)Remove a timeout observer.
//no need to synchronize, as Vector is always synchronized
observers.removeElement(to);
|
public synchronized void | run()The run method of the watch dog thread.
This simply does a wait for the timeout time, and
if the stop flag has not been set when the wait has returned or
has been interrupted, the watch dog listeners are informed.
final long until = System.currentTimeMillis() + timeout;
long now;
while (!stopped && until > (now = System.currentTimeMillis())) {
try {
wait(until - now);
} catch (InterruptedException e) {
// Ignore exception
}
}
if (!stopped) {
fireTimeoutOccured();
}
|
public synchronized void | start()Start the watch dog.
stopped = false;
Thread t = new Thread(this, "WATCHDOG");
t.setDaemon(true);
t.start();
|
public synchronized void | stop()Stop the watch dog.
stopped = true;
notifyAll();
|