From ac65a02a362648eddd5f232d775cdafa12c1c2ae Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Fri, 21 Jan 2005 17:37:28 +0000 Subject: [PATCH] javadoc git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277424 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/util/Watchdog.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/org/apache/tools/ant/util/Watchdog.java b/src/main/org/apache/tools/ant/util/Watchdog.java index 1c344ce88..ded57673d 100644 --- a/src/main/org/apache/tools/ant/util/Watchdog.java +++ b/src/main/org/apache/tools/ant/util/Watchdog.java @@ -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"); * 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 boolean stopped = false; + /** + * Constructor for Watchdog. + * @param timeout the timeout to use in milliseconds (must be >= 1). + */ public Watchdog(long timeout) { if (timeout < 1) { throw new IllegalArgumentException("timeout less than 1."); @@ -41,14 +45,25 @@ public class Watchdog implements Runnable { this.timeout = timeout; } + /** + * Add a timeout observer. + * @param to the timeout observer to add. + */ public void addTimeoutObserver(TimeoutObserver to) { observers.addElement(to); } + /** + * Remove a timeout observer. + * @param to the timeout observer to remove. + */ public void removeTimeoutObserver(TimeoutObserver to) { observers.removeElement(to); } + /** + * Inform the observers that a timeout has occured. + */ protected final void fireTimeoutOccured() { Enumeration e = observers.elements(); while (e.hasMoreElements()) { @@ -56,6 +71,9 @@ public class Watchdog implements Runnable { } } + /** + * Start the watch dog. + */ public synchronized void start() { stopped = false; Thread t = new Thread(this, "WATCHDOG"); @@ -63,11 +81,20 @@ public class Watchdog implements Runnable { t.start(); } + /** + * Stop the watch dog. + */ public synchronized void stop() { stopped = true; 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() { final long until = System.currentTimeMillis() + timeout; long now; @@ -75,6 +102,7 @@ public class Watchdog implements Runnable { try { wait(until - now); } catch (InterruptedException e) { + // Ignore exception } } if (!stopped) {