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 intacquireCountprotected booleanexpiredprotected TaskRunnablenextTaskprotected Threadownerprotected Triggerableparentprotected TaskRunnabletailTaskprotected Datetimeprotected booleantimeoutprotected intwaitCount
-
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 booleanacquireValidLock()Tries to acquire a valid (non-expired) lock.booleanaddElement(Object key)Implements for TaskRunnable interface, always return false.voidcancel()Implements for TaskRunnable interface.protected voidexpire()Sets the status of the HeadTask to expired.ThreadgetCurrentOwner()Returns the thread which currently holding this lock.HeadTaskRunnablegetHeadTask()Implements for TaskRunnable interface, no actual use for HeadTaskRunnable.longgetRunPeriod()Implements for TaskRunnable interface, HeadTaskRunnable doesn't have a run period.booleanisEmpty()Implements for TaskRunnable interface, always return false.booleanisExpired()Returns a boolean to indicate whether the HeadTask is expired already.booleanisTimedOut()Returns a boolean to indicate whether the HeadTask is timeout already.TaskRunnablenext()Returns the TaskRunnable next to this TaskRunnable in the linked-list.TaskRunnableprevious()Implements for TaskRunnable interface, there is no previous element for HeadTaskRunnable.voidreleaseLockAndNotify()Releases the currently holding lock.booleanremoveElement(Object key)Implements for TaskRunnable interface, always return false.voidrun()Implements for TaskRunnable interface, just run the next TaskRunnable.longscheduledExecutionTime()Returns the time which this HeadTaskRunnable is scheduled.voidsetHeadTask(HeadTaskRunnable headTask)Implements for TaskRunnable interface, no actual use for HeadTaskRunnable.voidsetNext(TaskRunnable task)Sets the TaskRunnable next to this TaskRunnable in the linked-list.voidsetPrevious(TaskRunnable task)Implements for TaskRunnable interface, There is no previous element for HeadTaskRunnable.voidsetTail(TaskRunnable task)Sets the task which is the tail of the list.voidsetTrigger(Triggerable parent)Sets the Triggerable interface which will be run when the linked-list is empty.TaskRunnabletail()Returns the Task which is at the tail of the list.protected voidtimeout()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 IllegalMonitorStateExceptionSets the status of the HeadTask to expired.- Throws:
IllegalMonitorStateException
-
timeout
protected void timeout() throws IllegalMonitorStateExceptionSets 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 IllegalMonitorStateExceptionReleases the currently holding lock.- Throws:
IllegalMonitorStateException
-
setHeadTask
public void setHeadTask(HeadTaskRunnable headTask)
Implements for TaskRunnable interface, no actual use for HeadTaskRunnable.- Specified by:
setHeadTaskin interfaceTaskRunnable- Parameters:
headTask- The HeadTaskRunnable
-
getHeadTask
public HeadTaskRunnable getHeadTask()
Implements for TaskRunnable interface, no actual use for HeadTaskRunnable.- Specified by:
getHeadTaskin interfaceTaskRunnable- Returns:
- The head task of this linkable TaskRunnable
-
addElement
public boolean addElement(Object key)
Implements for TaskRunnable interface, always return false.- Specified by:
addElementin 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:
removeElementin 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:
isEmptyin 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:
setNextin 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:
setPreviousin interfaceTaskRunnable- Parameters:
task- The previous TaskRunnable
-
next
public TaskRunnable next()
Returns the TaskRunnable next to this TaskRunnable in the linked-list.- Specified by:
nextin 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:
previousin 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:
getRunPeriodin interfaceTaskRunnable- Returns:
- -1 means the task only will be run once
-
cancel
public void cancel()
Implements for TaskRunnable interface.- Specified by:
cancelin 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:
scheduledExecutionTimein interfaceTaskRunnable- Returns:
- The long value which represents the time this task is scheduled
-
-