org.sape.carbon.services.threadpool
Class TaskInfoImpl

java.lang.Object
  |
  +--org.sape.carbon.services.threadpool.TaskInfoImpl
All Implemented Interfaces:
TaskInfo

public class TaskInfoImpl
extends Object
implements TaskInfo

Besides supplying the functionality described by the TaskInfo interface, this implementation also is responsible for making callbacks using the TaskCallback interface if a callback has been specified. Copyright 2003 Sapient

Since:
carbon 2.1
Version:
$Revision: 1.6 $($Author: dvoet $ / $Date: 2003/11/20 18:49:59 $)
Author:
Douglas Voet, Nov 20, 2003

Field Summary
private  TaskCallback callback
           
private  org.apache.commons.logging.Log log
           
private  TaskStatusEnum status
           
private  Runnable task
           
private  Throwable taskFailureCause
           
private  String taskName
           
private  String threadPoolName
           
 
Constructor Summary
protected TaskInfoImpl(Runnable task, String taskName, TaskCallback callback, String threadPoolName)
           
 
Method Summary
private  void callCallback(boolean success)
          helper method that calls the callback
 Throwable getFailureCause()
          Gets the cause of task failure.
 TaskStatusEnum getStatus()
          Gets the task's status.
 Runnable getTask()
          called by the DefaultThreadPoolImpl to get the task to execute
 String getTaskName()
          Gets the name of the task as it was passed in to the ThreadPool.execute method.
 void setExecuting()
          This method is called when a task begins execution.
 void setFailure(Throwable cause)
          This method is called when a task fails.
 void setSuccess()
          This method is called when a task succeeds.
 String toString()
           
 void waitUntilExecuted()
          Waits indefinitely for the task to complete.
 void waitUntilExecuted(long timeout)
          Waits a given amout of time for the task to complete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log

task

private Runnable task

status

private TaskStatusEnum status

taskFailureCause

private Throwable taskFailureCause

taskName

private String taskName

threadPoolName

private String threadPoolName

callback

private TaskCallback callback
Constructor Detail

TaskInfoImpl

protected TaskInfoImpl(Runnable task,
                       String taskName,
                       TaskCallback callback,
                       String threadPoolName)
Method Detail

getFailureCause

public Throwable getFailureCause()
Description copied from interface: TaskInfo
Gets the cause of task failure.

Specified by:
getFailureCause in interface TaskInfo
Returns:
the exception that caused the failure, or null if the task did not complete or completed successfully.

getStatus

public TaskStatusEnum getStatus()
Description copied from interface: TaskInfo
Gets the task's status. Note that if either the QueueFullPolicyEnum.DISCARD or QueueFullPolicyEnum.DISCARD_OLDEST policies are used, a task may never get out of the TaskStatusEnum.PENDING state.

Specified by:
getStatus in interface TaskInfo
Returns:
status

getTaskName

public String getTaskName()
Description copied from interface: TaskInfo
Gets the name of the task as it was passed in to the ThreadPool.execute method.

Specified by:
getTaskName in interface TaskInfo
Returns:
name

waitUntilExecuted

public void waitUntilExecuted()
                       throws InterruptedException
Description copied from interface: TaskInfo
Waits indefinitely for the task to complete. If the task has already completed, it returns.

Specified by:
waitUntilExecuted in interface TaskInfo
Throws:
InterruptedException

waitUntilExecuted

public void waitUntilExecuted(long timeout)
                       throws InterruptedException
Description copied from interface: TaskInfo
Waits a given amout of time for the task to complete. You can check the status of the task afterward to see if it actually completed or timed out. If the task has already completed, it returns.

Specified by:
waitUntilExecuted in interface TaskInfo
Parameters:
timeout - timout in miliseconds
Throws:
InterruptedException

setFailure

public void setFailure(Throwable cause)
This method is called when a task fails. The status is set to TaskStatusEnum.FAILED, all listeners are notified and the callback is called.

Parameters:
cause -

setSuccess

public void setSuccess()
This method is called when a task succeeds. The status is set to TaskStatusEnum.SUCCESS, all listeners are notified and the callback is called.


setExecuting

public void setExecuting()
This method is called when a task begins execution. The status is set to TaskStatusEnum.EXECUTING.


getTask

public Runnable getTask()
called by the DefaultThreadPoolImpl to get the task to execute


toString

public String toString()
Overrides:
toString in class Object

callCallback

private void callCallback(boolean success)
helper method that calls the callback



Copyright 1999-2003 Sapient Corporation. All Rights Reserved.