Package com.sun.identity.common
Class HeadTaskRunnable
- java.lang.Object
-
- com.sun.identity.common.HeadTaskRunnable
-
- All Implemented Interfaces:
TaskRunnable
,Runnable
public class HeadTaskRunnable extends Object implements TaskRunnable
HeadTaskRunnable is designed to be the head of the linked-list when TaskRunnable needs to be linked together. Whenever there is an insertion or deletion, HeadTaskRunnable must be locked to guarantee correct synchronization. Besides, when last element of the linked-list is removed (setNext(null)), HeadTaskRunnable should use Triggerable to remove or destroy the linked-list.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
acquireCount
protected boolean
expired
protected TaskRunnable
nextTask
protected Thread
owner
protected Triggerable
parent
protected TaskRunnable
tailTask
protected Date
time
protected boolean
timeout
protected int
waitCount
-
Constructor Summary
Constructors Constructor Description HeadTaskRunnable(Triggerable parent, TaskRunnable nextTask, Date time)
Constructor of HeadTaskRunnable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acquireValidLock()
Tries to acquire a valid (non-expired) lock.boolean
addElement(Object key)
Implements for TaskRunnable interface, always return false.void
cancel()
Implements for TaskRunnable interface.protected void
expire()
Sets the status of the HeadTask to expired.Thread
getCurrentOwner()
Returns the thread which currently holding this lock.HeadTaskRunnable
getHeadTask()
Implements for TaskRunnable interface, no actual use for HeadTaskRunnable.long
getRunPeriod()
Implements for TaskRunnable interface, HeadTaskRunnable doesn't have a run period.boolean
isEmpty()
Implements for TaskRunnable interface, always return false.boolean
isExpired()
Returns a boolean to indicate whether the HeadTask is expired already.boolean
isTimedOut()
Returns a boolean to indicate whether the HeadTask is timeout already.TaskRunnable
next()
Returns the TaskRunnable next to this TaskRunnable in the linked-list.TaskRunnable
previous()
Implements for TaskRunnable interface, there is no previous element for HeadTaskRunnable.void
releaseLockAndNotify()
Releases the currently holding lock.boolean
removeElement(Object key)
Implements for TaskRunnable interface, always return false.void
run()
Implements for TaskRunnable interface, just run the next TaskRunnable.long
scheduledExecutionTime()
Returns the time which this HeadTaskRunnable is scheduled.void
setHeadTask(HeadTaskRunnable headTask)
Implements for TaskRunnable interface, no actual use for HeadTaskRunnable.void
setNext(TaskRunnable task)
Sets the TaskRunnable next to this TaskRunnable in the linked-list.void
setPrevious(TaskRunnable task)
Implements for TaskRunnable interface, There is no previous element for HeadTaskRunnable.void
setTail(TaskRunnable task)
Sets the task which is the tail of the list.void
setTrigger(Triggerable parent)
Sets the Triggerable interface which will be run when the linked-list is empty.TaskRunnable
tail()
Returns the Task which is at the tail of the list.protected void
timeout()
Sets the status of the HeadTask to timeout.
-
-
-
Field Detail
-
time
protected Date time
-
nextTask
protected volatile TaskRunnable nextTask
-
tailTask
protected volatile TaskRunnable tailTask
-
expired
protected volatile boolean expired
-
timeout
protected volatile boolean timeout
-
waitCount
protected int waitCount
-
acquireCount
protected int acquireCount
-
owner
protected volatile Thread owner
-
parent
protected Triggerable parent
-
-
Constructor Detail
-
HeadTaskRunnable
public HeadTaskRunnable(Triggerable parent, TaskRunnable nextTask, Date time) throws IllegalArgumentException
Constructor of HeadTaskRunnable.- Parameters:
parent
- The Triggerable interface to be run when the linked-list is emptynextTask
- The TaskRunnable next to this TaskRunnabletime
- The time this TaskRunnable is scheduled- Throws:
IllegalArgumentException
-
-
Method Detail
-
expire
protected void expire() throws IllegalMonitorStateException
Sets the status of the HeadTask to expired.- Throws:
IllegalMonitorStateException
-
timeout
protected void timeout() throws IllegalMonitorStateException
Sets the status of the HeadTask to timeout.- Throws:
IllegalMonitorStateException
-
isTimedOut
public boolean isTimedOut()
Returns a boolean to indicate whether the HeadTask is timeout already.- Returns:
- a boolen to indicate whether the HeadTask is timeout.
-
isExpired
public boolean isExpired()
Returns a boolean to indicate whether the HeadTask is expired already.- Returns:
- a boolean to indicate whether the HeadTask is expired.
-
getCurrentOwner
public Thread getCurrentOwner()
Returns the thread which currently holding this lock.- Returns:
- the thread which currently own the lock or null.
-
acquireValidLock
public boolean acquireValidLock()
Tries to acquire a valid (non-expired) lock.- Returns:
- a boolean to indicate whether it is succeed to acquire the lock.
-
releaseLockAndNotify
public void releaseLockAndNotify() throws IllegalMonitorStateException
Releases the currently holding lock.- Throws:
IllegalMonitorStateException
-
setHeadTask
public void setHeadTask(HeadTaskRunnable headTask)
Implements for TaskRunnable interface, no actual use for HeadTaskRunnable.- Specified by:
setHeadTask
in interfaceTaskRunnable
- Parameters:
headTask
- The HeadTaskRunnable
-
getHeadTask
public HeadTaskRunnable getHeadTask()
Implements for TaskRunnable interface, no actual use for HeadTaskRunnable.- Specified by:
getHeadTask
in interfaceTaskRunnable
- Returns:
- The head task of this linkable TaskRunnable
-
addElement
public boolean addElement(Object key)
Implements for TaskRunnable interface, always return false.- Specified by:
addElement
in interfaceTaskRunnable
- Parameters:
key
- Element to be added to this TaskRunnable- Returns:
- false means nothing can be added to this TaskRunnable
-
removeElement
public boolean removeElement(Object key)
Implements for TaskRunnable interface, always return false.- Specified by:
removeElement
in interfaceTaskRunnable
- Parameters:
key
- Element to be removed from this TaskRunnable- Returns:
- false means nothing can be removed from this TaskRunnable
-
isEmpty
public boolean isEmpty()
Implements for TaskRunnable interface, always return false.- Specified by:
isEmpty
in interfaceTaskRunnable
- Returns:
- true means this TaskRunnable is always empty
-
setNext
public void setNext(TaskRunnable task)
Sets the TaskRunnable next to this TaskRunnable in the linked-list.- Specified by:
setNext
in interfaceTaskRunnable
- Parameters:
task
- The next TaskRunnable
-
setPrevious
public void setPrevious(TaskRunnable task)
Implements for TaskRunnable interface, There is no previous element for HeadTaskRunnable.- Specified by:
setPrevious
in interfaceTaskRunnable
- Parameters:
task
- The previous TaskRunnable
-
next
public TaskRunnable next()
Returns the TaskRunnable next to this TaskRunnable in the linked-list.- Specified by:
next
in interfaceTaskRunnable
- Returns:
- next TaskRunnable object or null if it is not set
-
previous
public TaskRunnable previous()
Implements for TaskRunnable interface, there is no previous element for HeadTaskRunnable.- Specified by:
previous
in interfaceTaskRunnable
- Returns:
- null means there is no previous element
-
getRunPeriod
public long getRunPeriod()
Implements for TaskRunnable interface, HeadTaskRunnable doesn't have a run period.- Specified by:
getRunPeriod
in interfaceTaskRunnable
- Returns:
- -1 means the task only will be run once
-
cancel
public void cancel()
Implements for TaskRunnable interface.- Specified by:
cancel
in interfaceTaskRunnable
-
setTrigger
public void setTrigger(Triggerable parent)
Sets the Triggerable interface which will be run when the linked-list is empty.- Parameters:
parent
- The Triggerable interface to be run when the linked-list is empty
-
setTail
public void setTail(TaskRunnable task)
Sets the task which is the tail of the list. It is for internal use only.- Parameters:
task
- The task which is at the tail of the list.
-
tail
public TaskRunnable tail()
Returns the Task which is at the tail of the list.- Returns:
- The task which is at the tail of the list.
-
scheduledExecutionTime
public long scheduledExecutionTime()
Returns the time which this HeadTaskRunnable is scheduled.- Specified by:
scheduledExecutionTime
in interfaceTaskRunnable
- Returns:
- The long value which represents the time this task is scheduled
-
-