public abstract class ComputeJobContinuationAdapter extends ComputeJobAdapter implements ComputeJobContinuation
ComputeJob
implementations. It provides the
following functionality:
ComputeJob.cancel()
method and ability
to check whether cancellation occurred.
ComputeJobAdapter.setArguments(Object...)
and ComputeJobAdapter.argument(int)
methods.
ComputeJobAdapter
can be used from task logic
to create jobs. The example creates job adapter as anonymous class, but you
are free to create a separate class for it.
public class TestGridTask extends ComputeTaskSplitAdapter<String, Integer> { // Used to imitate some logic for the // sake of this example private int multiplier = 3; @Override protected Collection<? extends ComputeJob> split(int gridSize, final String arg) throws IgniteCheckedException { List<ComputeJobAdapter<String>> jobs = new ArrayList<ComputeJobAdapter<String>>(gridSize); for (int i = 0; i < gridSize; i++) { jobs.add(new ComputeJobAdapter() { // Job execution logic. public Object execute() throws IgniteCheckedException { return multiplier * arg.length(); } }); } return jobs; } // Aggregate multiple job results into // one task result. public Integer reduce(List<ComputeJobResult> results) throws IgniteCheckedException { int sum = 0; // For the sake of this example, let's sum all results. for (ComputeJobResult res : results) { sum += (Integer)res.getData(); } return sum; } }
Modifier | Constructor and Description |
---|---|
protected |
ComputeJobContinuationAdapter()
No-arg constructor.
|
protected |
ComputeJobContinuationAdapter(Object... args)
Creates job with specified arguments.
|
protected |
ComputeJobContinuationAdapter(@Nullable Object arg)
Creates job with one arguments.
|
Modifier and Type | Method and Description |
---|---|
void |
callcc()
Resumes job if it was held by
ComputeJobContinuation.holdcc() method. |
boolean |
heldcc()
Checks if job execution has been temporarily held (suspended).
|
<T> T |
holdcc()
Holds (suspends) a given job indefinitely until
ComputeJobContinuation.callcc() is called. |
<T> T |
holdcc(long timeout)
Holds (suspends) a given job for specified timeout or until
ComputeJobContinuation.callcc() is called. |
argument, arguments, call, cancel, isCancelled, setArguments
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
execute
protected ComputeJobContinuationAdapter()
protected ComputeJobContinuationAdapter(@Nullable @Nullable Object arg)
arg
- Job argument.protected ComputeJobContinuationAdapter(@Nullable Object... args)
args
- Optional job arguments.public boolean heldcc()
If job has completed its execution, then false
is always returned.
heldcc
in interface ComputeJobContinuation
True
if job has been held.public void callcc()
ComputeJobContinuation.holdcc()
method. Resuming job means that
ComputeJob.execute()
method will be called again. It is user's responsibility to check,
as needed, whether job is executing from scratch and has been resumed.
Note that the job is resumed with exactly the same state as of when it was 'held' via
the ComputeJobContinuation.holdcc()
method.
If job is not running, has not been suspended, or has completed its execution, then no-op.
The method is named after 'call-with-current-continuation'
design pattern, commonly
abbreviated as 'call/cc'
, which originated in Scheme programming language.
callcc
in interface ComputeJobContinuation
@Nullable public <T> T holdcc()
ComputeJobContinuation.callcc()
is called.
Job will remain in active queue, but its ComputeJobContinuation.heldcc()
method will
return true
. Implementations of CollisionSpi
should check
if jobs are held or not as needed.
All jobs should stop their execution and return right after calling
'holdcc(..)'
method. For convenience, this method always returns null
,
so you can hold and return in one line by calling 'return holdcc()'
method.
If job is not running or has completed its execution, then no-op.
The 'cc'
suffix stands for 'current-continuation'
which is a
pretty standard notation for this concept that originated from Scheme programming
language. Basically, the job is held to be continued later, hence the name of the method.
holdcc
in interface ComputeJobContinuation
null
for convenience to be used in code with return statement.@Nullable public <T> T holdcc(long timeout)
ComputeJobContinuation.callcc()
is called.
Holds (suspends) a given job for specified timeout or until ComputeJobContinuation.callcc()
is called.
Job will remain in active queue, but its ComputeJobContinuation.heldcc()
method will
return true
. Implementations of CollisionSpi
should check
if jobs are held or not as needed.
All jobs should stop their execution and return right after calling
'holdcc(..)'
method. For convenience, this method always returns null
,
so you can hold and return in one line by calling 'return holdcc()'
.
If job is not running or has completed its execution, then no-op.
The 'cc'
suffix stands for 'current-continuation'
which is a
fairly standard notation for this concept. Basically, the job is held to
be continued later, hence the name of the method.
holdcc
in interface ComputeJobContinuation
timeout
- Timeout in milliseconds after which job will be automatically resumed.null
for convenience to be used in code with return statement.
GridGain In-Memory Computing Platform : ver. 8.9.15 Release Date : December 3 2024