Package org.jboss.util.threadpool
Class BasicTaskWrapper
- java.lang.Object
-
- org.jboss.util.threadpool.BasicTaskWrapper
-
- All Implemented Interfaces:
java.lang.Runnable,TaskWrapper
public class BasicTaskWrapper extends java.lang.Object implements TaskWrapper
A wrapper for the task.- Version:
- $Revision$
-
-
Field Summary
Fields Modifier and Type Field Description private longcompletionTimeoutThe completion timeoutprivate static org.jboss.logging.LoggerlogThe logprivate intpriorityThe priorityprivate java.lang.ThreadrunThreadThe threadprivate longstartTimeThe start timeprivate longstartTimeoutThe start timeoutprivate intstateThe state of the taskprivate java.lang.ObjectstateLockThe state lockprivate TasktaskThe taskstatic intTASK_ACCEPTEDThe task has been acceptedstatic intTASK_COMPLETEDThe task has completedstatic intTASK_NOT_ACCEPTEDThe task has not been acceptedstatic intTASK_REJECTEDThe task was rejectedstatic intTASK_STARTEDThe task has been startedstatic intTASK_STOPPEDThe task has been stoppedprivate java.lang.StringtaskStringThe task as a stringprivate intwaitTypeThe wait type
-
Constructor Summary
Constructors Modifier Constructor Description protectedBasicTaskWrapper()Create a task wrapper without a taskBasicTaskWrapper(Task task)Create a new task wrapper
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacceptTask()The task has been acceptedprotected longgetElapsedTime()Calculate the elapsed time since the task was startedprotected java.lang.StringgetStateString()Get the state as a stringlonggetTaskCompletionTimeout()The time before the task must be completedintgetTaskPriority()The priority of the tasklonggetTaskStartTimeout()The time before the task must be acceptedintgetTaskWaitType()Get the type of waitbooleanisComplete()Is the task complete.voidrejectTask(java.lang.RuntimeException e)The task has been rejectedvoidrun()Called by the thread pool executorprotected voidsetTask(Task task)Set thetask for this wrappervoidstopTask()Invoked by the threadpool when it wants to stop the taskprotected booleantaskAccepted()Notify the task it has been acceptedprotected booleantaskCompleted(java.lang.Throwable throwable)Notify the task it has completedprotected booleantaskRejected(java.lang.RuntimeException e)Notify the task it has been rejectedprotected booleantaskStarted()Notify the task it has startedprotected booleantaskStop()Stop the taskvoidwaitForTask()Wait according the wait type
-
-
-
Field Detail
-
log
private static final org.jboss.logging.Logger log
The log
-
TASK_NOT_ACCEPTED
public static final int TASK_NOT_ACCEPTED
The task has not been accepted- See Also:
- Constant Field Values
-
TASK_ACCEPTED
public static final int TASK_ACCEPTED
The task has been accepted- See Also:
- Constant Field Values
-
TASK_STARTED
public static final int TASK_STARTED
The task has been started- See Also:
- Constant Field Values
-
TASK_COMPLETED
public static final int TASK_COMPLETED
The task has completed- See Also:
- Constant Field Values
-
TASK_REJECTED
public static final int TASK_REJECTED
The task was rejected- See Also:
- Constant Field Values
-
TASK_STOPPED
public static final int TASK_STOPPED
The task has been stopped- See Also:
- Constant Field Values
-
state
private int state
The state of the task
-
stateLock
private java.lang.Object stateLock
The state lock
-
task
private Task task
The task
-
taskString
private java.lang.String taskString
The task as a string
-
startTime
private long startTime
The start time
-
startTimeout
private long startTimeout
The start timeout
-
completionTimeout
private long completionTimeout
The completion timeout
-
priority
private int priority
The priority
-
waitType
private int waitType
The wait type
-
runThread
private java.lang.Thread runThread
The thread
-
-
Constructor Detail
-
BasicTaskWrapper
protected BasicTaskWrapper()
Create a task wrapper without a task
-
BasicTaskWrapper
public BasicTaskWrapper(Task task)
Create a new task wrapper- Parameters:
task- the task- Throws:
java.lang.IllegalArgumentException- for a null task
-
-
Method Detail
-
getTaskWaitType
public int getTaskWaitType()
Description copied from interface:TaskWrapperGet the type of wait- Specified by:
getTaskWaitTypein interfaceTaskWrapper- Returns:
- the wait type
-
getTaskPriority
public int getTaskPriority()
Description copied from interface:TaskWrapperThe priority of the task- Specified by:
getTaskPriorityin interfaceTaskWrapper- Returns:
- the task priority
-
getTaskStartTimeout
public long getTaskStartTimeout()
Description copied from interface:TaskWrapperThe time before the task must be accepted- Specified by:
getTaskStartTimeoutin interfaceTaskWrapper- Returns:
- the start timeout
-
getTaskCompletionTimeout
public long getTaskCompletionTimeout()
Description copied from interface:TaskWrapperThe time before the task must be completed- Specified by:
getTaskCompletionTimeoutin interfaceTaskWrapper- Returns:
- the completion timeout
-
acceptTask
public void acceptTask()
Description copied from interface:TaskWrapperThe task has been accepted- Specified by:
acceptTaskin interfaceTaskWrapper
-
rejectTask
public void rejectTask(java.lang.RuntimeException e)
Description copied from interface:TaskWrapperThe task has been rejected- Specified by:
rejectTaskin interfaceTaskWrapper- Parameters:
e- any error associated with the rejection
-
isComplete
public boolean isComplete()
Description copied from interface:TaskWrapperIs the task complete.- Specified by:
isCompletein interfaceTaskWrapper- Returns:
- true if compelet, false otherwise
-
stopTask
public void stopTask()
Description copied from interface:TaskWrapperInvoked by the threadpool when it wants to stop the task- Specified by:
stopTaskin interfaceTaskWrapper
-
waitForTask
public void waitForTask()
Description copied from interface:TaskWrapperWait according the wait type- Specified by:
waitForTaskin interfaceTaskWrapper
-
run
public void run()
Called by the thread pool executor- Specified by:
runin interfacejava.lang.Runnable
-
setTask
protected void setTask(Task task)
Set thetask for this wrapper- Parameters:
task- the task
-
taskAccepted
protected boolean taskAccepted()
Notify the task it has been accepted- Returns:
- true when the notification succeeds, false otherwise
-
taskRejected
protected boolean taskRejected(java.lang.RuntimeException e)
Notify the task it has been rejected- Parameters:
e- any error associated with the rejection- Returns:
- true when the notification succeeds, false otherwise
-
taskStarted
protected boolean taskStarted()
Notify the task it has started- Returns:
- true when the notification succeeds, false otherwise
-
taskCompleted
protected boolean taskCompleted(java.lang.Throwable throwable)
Notify the task it has completed- Parameters:
throwable- any throwable associated with the completion- Returns:
- true when the notification succeeds, false otherwise
-
taskStop
protected boolean taskStop()
Stop the task- Returns:
- true when the notification succeeds, false otherwise
-
getElapsedTime
protected long getElapsedTime()
Calculate the elapsed time since the task was started- Returns:
- the elapsed time in millis
-
getStateString
protected java.lang.String getStateString()
Get the state as a string- Returns:
- the state string
-
-