|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.sgs.impl.kernel.ScheduledTaskImpl
final class ScheduledTaskImpl
Package-private implementation of ScheduledTask that is used to
maintain state about tasks accepted by TransactionScheduler and
passed on its backing SchedulerQueue.
This class implements some of the Future interface so that the
associated task can be cancelled or waited on to finish. The resulting
value provided by a call to get is null if the task
completed successfully, or the Throwable that caused the task
to fail permanently in the case of failure. See the documentation on
the associated methods for more details on how interruption is handled.
Note: This class is located in the com.sun.sgs.impl.kernel package
instead of the com.sun.sgs.impl.kernel.schedule package because
it needs to be a package-private implementation for use by the schedulers.
| Nested Class Summary | |
|---|---|
(package private) static class |
ScheduledTaskImpl.Builder
We use the builder pattern here to avoid constructor explosion. |
| Field Summary |
|---|
| Fields inherited from interface com.sun.sgs.kernel.schedule.ScheduledTask |
|---|
NON_RECURRING, UNBOUNDED |
| Method Summary | |
|---|---|
boolean |
cancel(boolean block)
Cancel this ScheduledTask. |
(package private) Throwable |
get()
Returns null if the task completed successfully, or the
Throwable that caused the task to fail permanently. |
Throwable |
getLastFailure()
Returns the Throwable that was the last failure of this task
or null if it has never been run or never failed. |
Identity |
getOwner()
Returns the owner. |
long |
getPeriod()
Returns the period for the task if it's recurring, or NON_RECURRING if this is not a recurring task. |
Priority |
getPriority()
Returns the priority. |
RecurringTaskHandle |
getRecurringTaskHandle()
Returns the RecurringTaskHandle associated with this task if
this task is recurring, or null if this is not recurring. |
long |
getStartTime()
Returns the time at which this task is scheduled to start. |
KernelRunnable |
getTask()
Returns the task. |
(package private) TaskQueue |
getTaskQueue()
Returns the TaskQueue associated with this task or null
if no queue was set. |
long |
getTimeout()
Returns the transaction timeout. |
int |
getTryCount()
Returns the try count (the number of times that this task has been attempted). |
(package private) void |
incrementTryCount()
Increments the try count (the number of times that this task has been attempted). |
boolean |
isCancelled()
Returns whether this task has been cancelled. |
(package private) boolean |
isDone()
Returns whether the task has finished. |
boolean |
isRecurring()
Returns whether this is a recurring task. |
(package private) boolean |
isRunning()
Returns whether this task is currently running. |
(package private) void |
resetStartTime()
Re-sets the starting time to the now. |
(package private) void |
setDone(Throwable result)
Sets the state of this task to done, with the result of the task being the provided Throwable which may be null to indicate
that the task completed successfully. |
(package private) boolean |
setInterrupted()
Similar to calling setRunning(false) except that no waiters
are notified of the state change. |
(package private) void |
setLastFailure(Throwable lastFailure)
Sets the Throwable that caused the last failure of this task. |
void |
setPriority(Priority priority)
Sets the priority for this task. |
(package private) void |
setRecurringTaskHandle(RecurringTaskHandle handle)
Sets this task's handle or throws IllegalStateException if
the task is not recurring. |
(package private) boolean |
setRunning(boolean running)
Sets the state of this task to running, returning false
if the task has already been cancelled or has completed, or if the
state is not being changed. |
(package private) void |
setTaskQueue(TaskQueue queue)
Sets the TaskQueue associated with this task. |
void |
setTimeout(long timeout)
Sets the transaction timeout for this task. |
String |
toString()
Provides some diagnostic detail about this task. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public KernelRunnable getTask()
getTask in interface ScheduledTaskKernelRunnable to runpublic Identity getOwner()
getOwner in interface ScheduledTaskIdentity that owns the taskpublic Priority getPriority()
getPriority in interface ScheduledTaskPrioritypublic long getStartTime()
getStartTime in interface ScheduledTaskpublic long getPeriod()
NON_RECURRING if this is not a recurring task.
getPeriod in interface ScheduledTaskpublic int getTryCount()
getTryCount in interface ScheduledTaskpublic long getTimeout()
getTimeout in interface ScheduledTaskpublic Throwable getLastFailure()
Throwable that was the last failure of this task
or null if it has never been run or never failed.
getLastFailure in interface ScheduledTaskThrowable that was the cause of the last failurepublic void setPriority(Priority priority)
setPriority in interface ScheduledTaskpriority - the new priority for this taskpublic boolean isRecurring()
getPeriod should always return NON_RECURRING.
isRecurring in interface ScheduledTasktrue if this task is a recurring task,
false otherwise.public RecurringTaskHandle getRecurringTaskHandle()
RecurringTaskHandle associated with this task if
this task is recurring, or null if this is not recurring.
getRecurringTaskHandle in interface ScheduledTaskRecurringTaskHandle or nullpublic boolean isCancelled()
isCancelled in interface ScheduledTasktrue if this ScheduledTask has been cancelled,
false otherwisepublic boolean cancel(boolean block)
ScheduledTask. Note that if the task is already
running then calling this method may not have any affect. Also note
that this method should never be called with a value of true
for the block parameter if the calling thread is also currently
running this ScheduledTask.
cancel in interface ScheduledTaskblock - if true, this call will block until the task is
cancelled or has completed, if false, it will not
block
true if the task was cancelled by this call,
false otherwisepublic void setTimeout(long timeout)
setTimeout in interface ScheduledTasktimeout - the new transaction timeout for this task
Throwable get()
throws InterruptedException
null if the task completed successfully, or the
Throwable that caused the task to fail permanently. If the
task has not yet completed then this will block until the result
is known or the caller is interrupted. An InterruptedException
is thrown either if the calling thread is interrupted before a result
is known or if the task is cancelled meaning that no result is known.
InterruptedExceptionvoid resetStartTime()
boolean isDone()
boolean setRunning(boolean running)
running, returning false
if the task has already been cancelled or has completed, or if the
state is not being changed.
boolean setInterrupted()
setRunning(false) except that no waiters
are notified of the state change. This is used when the task's thread
is interrupted and we don't know if the task is going to be re-runnable
in a new thread or has to be dropped.
boolean isRunning()
void setDone(Throwable result)
Throwable which may be null to indicate
that the task completed successfully. If the task is not currently
running or was not previously interrupted then this method has no effect.
Otherwise, the result is set and the task is marked as completed.
void setRecurringTaskHandle(RecurringTaskHandle handle)
IllegalStateException if
the task is not recurring.
void incrementTryCount()
void setLastFailure(Throwable lastFailure)
Throwable that caused the last failure of this task.
lastFailure - the last failurevoid setTaskQueue(TaskQueue queue)
TaskQueue associated with this task. Typically this
is used to track dependency, so that when this task is completed,
the next task can be fetched from the queue.
TaskQueue getTaskQueue()
TaskQueue associated with this task or null
if no queue was set. This is typically the source of dependent tasks
where this task was submitted.
public String toString()
toString in class ObjectString representation of the task.
|
RedDwarf, Version 0.10.1 2010-03-14 10:56:12 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||