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 long
completionTimeout
The completion timeoutprivate static org.jboss.logging.Logger
log
The logprivate int
priority
The priorityprivate java.lang.Thread
runThread
The threadprivate long
startTime
The start timeprivate long
startTimeout
The start timeoutprivate int
state
The state of the taskprivate java.lang.Object
stateLock
The state lockprivate Task
task
The taskstatic int
TASK_ACCEPTED
The task has been acceptedstatic int
TASK_COMPLETED
The task has completedstatic int
TASK_NOT_ACCEPTED
The task has not been acceptedstatic int
TASK_REJECTED
The task was rejectedstatic int
TASK_STARTED
The task has been startedstatic int
TASK_STOPPED
The task has been stoppedprivate java.lang.String
taskString
The task as a stringprivate int
waitType
The wait type
-
Constructor Summary
Constructors Modifier Constructor Description protected
BasicTaskWrapper()
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 void
acceptTask()
The task has been acceptedprotected long
getElapsedTime()
Calculate the elapsed time since the task was startedprotected java.lang.String
getStateString()
Get the state as a stringlong
getTaskCompletionTimeout()
The time before the task must be completedint
getTaskPriority()
The priority of the tasklong
getTaskStartTimeout()
The time before the task must be acceptedint
getTaskWaitType()
Get the type of waitboolean
isComplete()
Is the task complete.void
rejectTask(java.lang.RuntimeException e)
The task has been rejectedvoid
run()
Called by the thread pool executorprotected void
setTask(Task task)
Set thetask for this wrappervoid
stopTask()
Invoked by the threadpool when it wants to stop the taskprotected boolean
taskAccepted()
Notify the task it has been acceptedprotected boolean
taskCompleted(java.lang.Throwable throwable)
Notify the task it has completedprotected boolean
taskRejected(java.lang.RuntimeException e)
Notify the task it has been rejectedprotected boolean
taskStarted()
Notify the task it has startedprotected boolean
taskStop()
Stop the taskvoid
waitForTask()
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:TaskWrapper
Get the type of wait- Specified by:
getTaskWaitType
in interfaceTaskWrapper
- Returns:
- the wait type
-
getTaskPriority
public int getTaskPriority()
Description copied from interface:TaskWrapper
The priority of the task- Specified by:
getTaskPriority
in interfaceTaskWrapper
- Returns:
- the task priority
-
getTaskStartTimeout
public long getTaskStartTimeout()
Description copied from interface:TaskWrapper
The time before the task must be accepted- Specified by:
getTaskStartTimeout
in interfaceTaskWrapper
- Returns:
- the start timeout
-
getTaskCompletionTimeout
public long getTaskCompletionTimeout()
Description copied from interface:TaskWrapper
The time before the task must be completed- Specified by:
getTaskCompletionTimeout
in interfaceTaskWrapper
- Returns:
- the completion timeout
-
acceptTask
public void acceptTask()
Description copied from interface:TaskWrapper
The task has been accepted- Specified by:
acceptTask
in interfaceTaskWrapper
-
rejectTask
public void rejectTask(java.lang.RuntimeException e)
Description copied from interface:TaskWrapper
The task has been rejected- Specified by:
rejectTask
in interfaceTaskWrapper
- Parameters:
e
- any error associated with the rejection
-
isComplete
public boolean isComplete()
Description copied from interface:TaskWrapper
Is the task complete.- Specified by:
isComplete
in interfaceTaskWrapper
- Returns:
- true if compelet, false otherwise
-
stopTask
public void stopTask()
Description copied from interface:TaskWrapper
Invoked by the threadpool when it wants to stop the task- Specified by:
stopTask
in interfaceTaskWrapper
-
waitForTask
public void waitForTask()
Description copied from interface:TaskWrapper
Wait according the wait type- Specified by:
waitForTask
in interfaceTaskWrapper
-
run
public void run()
Called by the thread pool executor- Specified by:
run
in 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
-
-