it.sauronsoftware.cron4j
Class TaskExecutor

java.lang.Object
  extended by it.sauronsoftware.cron4j.TaskExecutor

public class TaskExecutor
extends java.lang.Object

Represents a task executor, which is something similar to threads.

Each time a task is launched, a new executor is spawned, executing and watching the task

Alive task executors can be retrieved with the Scheduler.getExecutingTasks() method, and they expose method to control the ongoing execution.

Since:
2.0
Author:
Carlo Pelliccia
See Also:
Scheduler.getExecutingTasks()

Method Summary
 void addTaskExecutorListener(TaskExecutorListener listener)
          Adds a listener to the executor.
 boolean canBePaused()
          Checks whether this executor supports pausing.
 boolean canBeStopped()
          Checks whether this executor supports stopping.
 double getCompleteness()
          Returns the current completeness value, which is a value between 0 and 1.
 java.lang.String getGuid()
          Returns a GUID for this executor.
 Scheduler getScheduler()
          Returns the Scheduler instance whose this executor belongs to.
 long getStartTime()
          Returns a time stamp reporting the start time of this executor, or a value less than 0 if this executor has not been yet started.
 java.lang.String getStatusMessage()
          Returns the current status message.
 Task getTask()
          Returns the representation of the executed task.
 TaskExecutorListener[] getTaskExecutorListeners()
          Returns an array containing any TaskExecutorListener previously registered with the addTaskExecutorListener(TaskExecutorListener) method.
 boolean isAlive()
          Tests if this executor is alive.
 boolean isPaused()
          Tests whether this executor has been paused.
 boolean isStopped()
          Tests whether this executor has been stopped.
 void join()
          Waits for this executor to die.
 void pause()
          Pauses the ongoing execution.
 void removeTaskExecutorListener(TaskExecutorListener listener)
          Removes a listener from the executor.
 void resume()
          Resumes the execution after it has been paused.
 void stop()
          Stops the ongoing execution.
 boolean supportsCompletenessTracking()
          Checks whether this executor provides completeness tracking informations.
 boolean supportsStatusTracking()
          Checks whether this executor provides status tracking messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addTaskExecutorListener

public void addTaskExecutorListener(TaskExecutorListener listener)
Adds a listener to the executor.

Parameters:
listener - The listener.

removeTaskExecutorListener

public void removeTaskExecutorListener(TaskExecutorListener listener)
Removes a listener from the executor.

Parameters:
listener - The listener.

getTaskExecutorListeners

public TaskExecutorListener[] getTaskExecutorListeners()
Returns an array containing any TaskExecutorListener previously registered with the addTaskExecutorListener(TaskExecutorListener) method.

Returns:
An array containing any TaskExecutorListener previously registered with the addTaskExecutorListener(TaskExecutorListener) method.

getGuid

public java.lang.String getGuid()
Returns a GUID for this executor.

Returns:
A GUID for this executor.

getScheduler

public Scheduler getScheduler()
Returns the Scheduler instance whose this executor belongs to.

Returns:
The scheduler.

getTask

public Task getTask()
Returns the representation of the executed task.

Returns:
The executing/executed task.

getStartTime

public long getStartTime()
Returns a time stamp reporting the start time of this executor, or a value less than 0 if this executor has not been yet started.

Returns:
A time stamp reporting the start time of this executor, or a value less than 0 if this executor has not been yet started.

canBePaused

public boolean canBePaused()
Checks whether this executor supports pausing.

Returns:
true if this executor supports pausing.

canBeStopped

public boolean canBeStopped()
Checks whether this executor supports stopping.

Returns:
true if this executor supports stopping.

supportsCompletenessTracking

public boolean supportsCompletenessTracking()
Checks whether this executor provides completeness tracking informations.

Returns:
true if this executor provides completeness tracking informations.

supportsStatusTracking

public boolean supportsStatusTracking()
Checks whether this executor provides status tracking messages.

Returns:
true if this executor provides status tracking messages.

pause

public void pause()
           throws java.lang.UnsupportedOperationException
Pauses the ongoing execution.

Throws:
java.lang.UnsupportedOperationException - The operation is not supported if canBePaused() returns false.

resume

public void resume()
Resumes the execution after it has been paused.


stop

public void stop()
          throws java.lang.UnsupportedOperationException
Stops the ongoing execution.

Throws:
java.lang.UnsupportedOperationException - The operation is not supported if canBeStopped() returns false.

join

public void join()
          throws java.lang.InterruptedException
Waits for this executor to die.

Throws:
java.lang.InterruptedException - If any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

isAlive

public boolean isAlive()
Tests if this executor is alive. An executor is alive if it has been started and has not yet died.

Returns:
true if this executor is alive; false otherwise.

getStatusMessage

public java.lang.String getStatusMessage()
                                  throws java.lang.UnsupportedOperationException
Returns the current status message.

Returns:
The current status message.
Throws:
java.lang.UnsupportedOperationException - The operation is not supported if supportsStatusTracking() returns false.

getCompleteness

public double getCompleteness()
                       throws java.lang.UnsupportedOperationException
Returns the current completeness value, which is a value between 0 and 1.

Returns:
The current completeness value, which is a value between 0 and 1.
Throws:
java.lang.UnsupportedOperationException - The operation is not supported if supportsCompletenessTracking() returns false.

isPaused

public boolean isPaused()
Tests whether this executor has been paused.

Returns:
true if this executor is paused; false otherwise.

isStopped

public boolean isStopped()
Tests whether this executor has been stopped.

Returns:
true if this executor is stopped; false otherwise.