Browse Source

javadoc

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277424 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 20 years ago
parent
commit
ac65a02a36
1 changed files with 29 additions and 1 deletions
  1. +29
    -1
      src/main/org/apache/tools/ant/util/Watchdog.java

+ 29
- 1
src/main/org/apache/tools/ant/util/Watchdog.java View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2004 The Apache Software Foundation
* Copyright 2002-2005 The Apache Software Foundation
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -34,6 +34,10 @@ public class Watchdog implements Runnable {
private long timeout = -1; private long timeout = -1;
private boolean stopped = false; private boolean stopped = false;


/**
* Constructor for Watchdog.
* @param timeout the timeout to use in milliseconds (must be >= 1).
*/
public Watchdog(long timeout) { public Watchdog(long timeout) {
if (timeout < 1) { if (timeout < 1) {
throw new IllegalArgumentException("timeout less than 1."); throw new IllegalArgumentException("timeout less than 1.");
@@ -41,14 +45,25 @@ public class Watchdog implements Runnable {
this.timeout = timeout; this.timeout = timeout;
} }


/**
* Add a timeout observer.
* @param to the timeout observer to add.
*/
public void addTimeoutObserver(TimeoutObserver to) { public void addTimeoutObserver(TimeoutObserver to) {
observers.addElement(to); observers.addElement(to);
} }


/**
* Remove a timeout observer.
* @param to the timeout observer to remove.
*/
public void removeTimeoutObserver(TimeoutObserver to) { public void removeTimeoutObserver(TimeoutObserver to) {
observers.removeElement(to); observers.removeElement(to);
} }


/**
* Inform the observers that a timeout has occured.
*/
protected final void fireTimeoutOccured() { protected final void fireTimeoutOccured() {
Enumeration e = observers.elements(); Enumeration e = observers.elements();
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
@@ -56,6 +71,9 @@ public class Watchdog implements Runnable {
} }
} }


/**
* Start the watch dog.
*/
public synchronized void start() { public synchronized void start() {
stopped = false; stopped = false;
Thread t = new Thread(this, "WATCHDOG"); Thread t = new Thread(this, "WATCHDOG");
@@ -63,11 +81,20 @@ public class Watchdog implements Runnable {
t.start(); t.start();
} }


/**
* Stop the watch dog.
*/
public synchronized void stop() { public synchronized void stop() {
stopped = true; stopped = true;
notifyAll(); notifyAll();
} }


/**
* 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.
*/
public synchronized void run() { public synchronized void run() {
final long until = System.currentTimeMillis() + timeout; final long until = System.currentTimeMillis() + timeout;
long now; long now;
@@ -75,6 +102,7 @@ public class Watchdog implements Runnable {
try { try {
wait(until - now); wait(until - now);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Ignore exception
} }
} }
if (!stopped) { if (!stopped) {


Loading…
Cancel
Save