|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface TaskContext
Provides a single channel of communication from a running task instance to the runtime system. Provided services include retrieving data elements, reporting progress, and logging checkpoints.
| Method Summary | |
|---|---|
DataBuffer |
createDataBuffer()
Create a data buffer for the task to use internally. |
DataBuffer |
createDataBuffer(boolean useDiskHint)
Similar to createDataBuffer(), but tends to
create a buffer stored either entirely on disk or entirely in
memory as specified by the supplied hint. |
DataBuffer |
getElement(java.net.URI uri)
Obtain a data element. |
java.io.File |
getTempDirectory()
Returns the path of a temporary directory for the task's use with read, write, delete and execute permissions on the directory and all of its files and subdirectories, recursively. |
void |
logCheckpoint(DataBuffer checkpoint)
Log a checkpoint which may be used to restart this task at a later time. |
void |
logCheckpoint(DataBuffer checkpoint,
boolean force)
Log a checkpoint which may be used to restart this task at a later time. |
void |
postIntermediateResultsData(DataBuffer intermediateResults)
Post intermediate results. |
void |
postIntermediateResultsData(double progress,
DataBuffer intermediateResults)
Post intermediate results and report progress simultaneously. |
void |
postIntermediateResultsObject(double progress,
java.io.Serializable intermediateResults)
Post intermediate results and report progress simultaneously. |
void |
postIntermediateResultsObject(java.io.Serializable intermediateResults)
Post intermediate results. |
void |
reportProgress(double progress)
Report progress, replacing all previous progress reports. |
boolean |
shouldLogCheckpoint()
Provides a hint as to whether a checkpoint should be logged. |
boolean |
shouldPostIntermediateResults()
Provides a hint as to whether intermediate results should be posted. |
boolean |
shouldStop()
Reports whether the task should stop immediately, throwing a TaskStoppedException from the Task.run method. |
| Method Detail |
|---|
DataBuffer getElement(java.net.URI uri)
DataBuffer, or null if an element which
was not marked as required for this task is requested. Any
attempt to modify the contents of this DataBuffer
will result in an UnsupportedOperationException.DataBuffer createDataBuffer()
postIntermediateResults and
logCheckpoint as well as being returned from
Task.run containing final results. The data
buffer's contents will be maintained until either
release is invoked on the buffer, the task
completes, or the task is restarted.
The runtime will decide whether to store this data buffer entirely on disk, entirely in memory, or a dynamic mixture of these.
createDataBuffer(boolean)DataBuffer createDataBuffer(boolean useDiskHint)
createDataBuffer(), but tends to
create a buffer stored either entirely on disk or entirely in
memory as specified by the supplied hint. Note that the hint may
not be used; this method's behaviour is not guaranteed to be any
different from that of createDataBuffer().
createDataBuffer()void reportProgress(double progress)
Progress is an optional hint to the runtime system as well as the initiating client, and can enhance scheduling performance as well as providing a human-understandable measure of a task's completion.. It is defined to be a monotonically nondecreasing positive function (that is, it never goes down); any other behaviour can result in reduced scheduling efficiency. If restarting from a checkpoint, the first progress reported (if any) must be equal to or greater than the last progress reported before that checkpoint was created (if any).
Many tasks report progress such that it varies linearly from 0 to 1; when practical, this behaviour is recommended. However, this is not desirable nor even possible for all tasks. It is suggested that tasks which do not (for whatever reason) employ this convention, then they should report progress values greater than 1.0 -- that is, the first progress reported should be greater than 1.0, and all subsequent progress reports greater still than that. This way, when generic applications or components are observing progress without any information about what type of progress values are reported by a given task, they can use a value between 0 and 1 as a hint that the progress will vary linearly through this range and hence can, for example, display graphical progress bars or percentages, and compute estimated completion times. Note that this is merely a convention, however, and need not be obeyed at the task developer's discretion.
boolean shouldPostIntermediateResults()
true if sufficient time has passed since the last
intermediate results to be worth sending new ones, determined based on
factors such as maximum intermediate results frequency.
void postIntermediateResultsData(DataBuffer intermediateResults)
intermediateResults - the intermediate results. Must be a
DataBuffer instance obtained by
the task during the current run (that is, since
the run method was invoked on
the current task instance, based on either
initial parameters or a checkpoint) via
createDataBuffer, or
getDataElement methods of
this TaskContext, or as a
parameter to the task's own run
method. This task retains ownership of the
DataBuffer and can freely modify
it after this method returns without affecting
the contents of the reported intermediate
results.createDataBuffer()
void postIntermediateResultsData(double progress,
DataBuffer intermediateResults)
reportProgress(progress);
postIntermediateResultsData(intermediateResults);
reportProgress(double),
postIntermediateResultsData(DataBuffer)void postIntermediateResultsObject(java.io.Serializable intermediateResults)
intermediateResults - the intermediate results. Must be a valid
Serializable object instance.
void postIntermediateResultsObject(double progress,
java.io.Serializable intermediateResults)
reportProgress(progress);
postIntermediateResultsObject(intermediateResults);
reportProgress(double),
postIntermediateResultsObject(Serializable)boolean shouldLogCheckpoint()
true if sufficient time has passed since the last checkpoint
to be worth creating a new checkpoint, determined based on factors such as
how long previous checkpoints have taken to be saved.
void logCheckpoint(DataBuffer checkpoint)
run method with a DataBuffer containing
the contents of a checkpoint instead of the initial parameters
of a task. The checkpoint may or may not be reported back to
the server or the client, and may or may not be saved
locally on the provider. Reporting checkpoints ensures that
interrupted tasks can be restarted from the last reported
checkpoint rather than the initial state; in extreme cases, tasks
which do not report checkpoints (or report them too infrequently)
may never complete because of interruptions.
This method will tend to return immediately without logging a checkpoint
if shouldLogCheckpoint returns false.
Equivalent to logCheckpoint(checkpoint, false).
checkpoint - a buffer containing all state necessary to define
task. This task retains ownership of the
DataBuffer and can freely modify it after
this method returns without affecting the substance of
the checkpoint.shouldLogCheckpoint(),
logCheckpoint(DataBuffer, boolean)
void logCheckpoint(DataBuffer checkpoint,
boolean force)
DataBuffer
containing the contents of a checkpoint instead of the initial parameters
of a task. The checkpoint may or may not be reported back to the server or
the client, and may or may not be saved locally on the provider. Reporting
checkpoints ensures that interrupted tasks can be restarted from the last
reported checkpoint rather than the initial state; in extreme cases, tasks
which do not report checkpoints (or report them too infrequently) may never
complete because of interruptions.
If force is true, this routine will tend to
log a checkpoint even if shouldLogCheckpoint is false. This
functionality is useful when, for instance, the task is only able to
generate checkpoints at certain infrequent points, and another checkpoint
may not be available for a while; in this case, the task's knowledge is
more important than the system's checkpoint-logging efficiency heuristics.
Note, however, that the system may decide not to save or transmit a
checkpoint even when force is true. When
force is false, this method is equivalent to
logCheckpoint(checkpoint).
checkpoint - a buffer containing all state necessary to define task. This task
retains ownership of the DataBuffer and can freely
modify it after this method returns without affecting the
substance of the checkpoint.force - true if the method should attempt to save a
checkpoint even though shouldLogCheckpoint returns
false. This flag is only a hint, however, and the system may
override it.shouldLogCheckpoint(),
logCheckpoint(DataBuffer)
java.io.File getTempDirectory()
throws java.lang.SecurityException
java.lang.SecurityException - if no temporary directory can be made availableboolean shouldStop()
Task.run method.
A task may call this method instead of (or in addition to) implementing
the Task.stop method; both mechanisms provide a means for
a task to stop gracefully, optionally logging a final checkpoint, etc
before exiting. If shouldStop returns true,
then Task.stop has already been or will soon be called as
well, and vice-versa.
Task.stop()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||