net.sourceforge.acelogger.execution.task
Class MonitorableTask

java.lang.Object
  extended by net.sourceforge.acelogger.execution.task.MonitorableTask
All Implemented Interfaces:
Runnable

public class MonitorableTask
extends Object
implements Runnable

A Runnable implementation and a wrapper that supports monitoring of the execution status and a utility methods to await the task completion or a given timeout, what occurs first.

Since:
1.0.0
Version:
1.0.0
Author:
Zardi (https://sourceforge.net/users/daniel_zardi)

Field Summary
static int DEFAULT_MAXIMUM_STEP
          The default value (in ms) for the maximum step used in termination waiting methods.
 
Constructor Summary
MonitorableTask(Runnable task)
          Constructs a new MonitorableTask for the given Runnable.
 
Method Summary
 boolean awaitTermination(long duration)
          Waits for task completion or waiting timeout, what occurs first.
 boolean awaitTermination(long duration, long maximumStep)
          Waits for task completion or waiting timeout, what occurs first.
 boolean isDone()
          Signals the termination of this task execution.
 void run()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAXIMUM_STEP

public static final int DEFAULT_MAXIMUM_STEP
The default value (in ms) for the maximum step used in termination waiting methods.

See Also:
Constant Field Values
Constructor Detail

MonitorableTask

public MonitorableTask(Runnable task)
Constructs a new MonitorableTask for the given Runnable.

Parameters:
task - The Runnable that will be monitored.
Since:
1.0.0
Method Detail

run

public void run()

Specified by:
run in interface Runnable

isDone

public boolean isDone()
Signals the termination of this task execution.

Returns:
True if the task has already run; False otherwise.

awaitTermination

public boolean awaitTermination(long duration)
                         throws InterruptedException
Waits for task completion or waiting timeout, what occurs first. This method will use a default step defined in DEFAULT_MAXIMUM_STEP.

Parameters:
duration - The maximum duration of the waiting process, in milliseconds.
Returns:
True if the task was done; False otherwise (timeout occurred).
Throws:
InterruptedException - If the execution thread was interrupted during the waiting process.
Since:
1.0.0
See Also:
awaitTermination(long, long)

awaitTermination

public boolean awaitTermination(long duration,
                                long maximumStep)
                         throws InterruptedException
Waits for task completion or waiting timeout, what occurs first. The waiting process will be "sliced" using the supplied maximum step value.

Parameters:
duration - The maximum duration of the waiting process, in milliseconds.
maximumStep - The maximum step during the waiting process, in milliseconds.
Returns:
True if the task was done; False otherwise (timeout occurred).
Throws:
InterruptedException - If the execution thread was interrupted during the waiting process.
Since:
1.0.0


Copyright © 2007-2010 The AceLogger Team. All Rights Reserved.