com.sun.sgs.impl.service.task
Class PendingTask

java.lang.Object
  extended by com.sun.sgs.impl.service.task.PendingTask
All Implemented Interfaces:
ManagedObject, Serializable

 class PendingTask
extends Object
implements ManagedObject, Serializable

Utility, package-private class for managing durable implementations of Task that have been scheduled through the TaskService but have not yet run to completion or been dropped. This class maintains all of the meta-data associated with these pending tasks, and if needed, makes sure that the Task itself is persisted. This meta-data classs can be flagged as re-usable, so that a single instance can be persisted and then re-used as needed, although a given instance must always be re-used for tasks for the same Identity.


Constructor Summary
PendingTask(Identity identity)
          Creates an instance of PendingTask.
 
Method Summary
(package private)  String getBaseTaskType()
          Returns the type of the pending task.
(package private)  Identity getIdentity()
          Returns the identity that owns this task.
(package private)  long getLastStartTime()
          Returns the last time when this task actually started, or TaskServiceImpl.NEVER if the task has never been run.
(package private)  long getPeriod()
          Returns the periodicity of this task, or TaskServiceImpl.PERIOD_NONE if the task is not periodic.
(package private)  long getRunningNode()
          Returns the node where the associated task is running if the task is periodic, or -1 if the task is non-periodic or the node hasn't been assigned.
(package private)  long getStartTime()
          Returns the time when this task is supposed to start, or TaskServiceImpl.START_NOW if the task is not delayed.
(package private)  boolean isPeriodic()
          Checks if this is a periodic task.
(package private)  boolean isReusable()
          Returns whether this PendingTask is free to be re-used.
(package private)  boolean isTaskAvailable()
          Checks that the underlying task is available, which is only at question if the task was managed by the application and therefore could have been removed by the application.
(package private)  void resetValues(Task t, long s, long p)
          Re-sets this PendingTask with the given values, and marks it as unavailable.
(package private)  void run()
          This is a convenience method used to correctly resolve the pending task and run it, throwing any exceptions raised by the task.
(package private)  void setLastStartTime(long lastStartTime)
          Sets the last start time for this task.
(package private)  void setReusable()
          Re-sets the task state so that the task can be re-used.
(package private)  void setRunningNode(long nodeId)
          Sets the node where the associated task is running if the task is periodic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PendingTask

PendingTask(Identity identity)
Creates an instance of PendingTask.

Parameters:
identity - the Identity of the owner of the task
Method Detail

resetValues

void resetValues(Task t,
                 long s,
                 long p)
Re-sets this PendingTask with the given values, and marks it as unavailable. This can now be used to represent a durable task that needs to be run. As described on TaskManager, any Task may optionally implement ManagedObject and this affects how the task is handled by the system. PendingTask takes care of the task's durability, and how the task is eventually run, in both situations.

Parameters:
t - the Task that is pending
s - the starting time for the task, in milliseconds since January 1, 1970, or TaskServiceImpl.START_NOW
p - the period between recurrences, or TaskServiceImpl.PERIOD_NONE

isReusable

boolean isReusable()
Returns whether this PendingTask is free to be re-used.


setReusable

void setReusable()
Re-sets the task state so that the task can be re-used.


getBaseTaskType

String getBaseTaskType()
Returns the type of the pending task.


getStartTime

long getStartTime()
Returns the time when this task is supposed to start, or TaskServiceImpl.START_NOW if the task is not delayed.


getPeriod

long getPeriod()
Returns the periodicity of this task, or TaskServiceImpl.PERIOD_NONE if the task is not periodic.


getRunningNode

long getRunningNode()
Returns the node where the associated task is running if the task is periodic, or -1 if the task is non-periodic or the node hasn't been assigned.


getLastStartTime

long getLastStartTime()
Returns the last time when this task actually started, or TaskServiceImpl.NEVER if the task has never been run.


setRunningNode

void setRunningNode(long nodeId)
Sets the node where the associated task is running if the task is periodic. If the task is not periodic, IllegalStateException is thrown.


setLastStartTime

void setLastStartTime(long lastStartTime)
Sets the last start time for this task.

Parameters:
lastStartTime - the new start time

isPeriodic

boolean isPeriodic()
Checks if this is a periodic task.


getIdentity

Identity getIdentity()
Returns the identity that owns this task.


isTaskAvailable

boolean isTaskAvailable()
Checks that the underlying task is available, which is only at question if the task was managed by the application and therefore could have been removed by the application. Must be called in a transaction.


run

void run()
   throws Exception
This is a convenience method used to correctly resolve the pending task and run it, throwing any exceptions raised by the task. Note that if isTaskAvailable returns false then this method will simply return without running anything.

Throws:
Exception

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved