public abstract class GridComputeJobContinuationAdapter extends GridComputeJobAdapter implements GridComputeJobContinuation
GridComputeJob implementations. It provides the
following functionality:
GridComputeJob.cancel() method and ability
to check whether cancellation occurred.
GridComputeJobAdapter.setArguments(Object...)
and GridComputeJobAdapter.argument(int) methods.
GridComputeJobAdapter 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 GridComputeTaskSplitAdapter<String, Integer> {
// Used to imitate some logic for the
// sake of this example
private int multiplier = 3;
@Override
protected Collection<? extends GridComputeJob> split(int gridSize, final String arg) throws GridException {
List<GridComputeJobAdapter<String>> jobs = new ArrayList<GridComputeJobAdapter<String>>(gridSize);
for (int i = 0; i < gridSize; i++) {
jobs.add(new GridComputeJobAdapter() {
// Job execution logic.
public Object execute() throws GridException {
return multiplier * arg.length();
}
});
}
return jobs;
}
// Aggregate multiple job results into
// one task result.
public Integer reduce(List<GridComputeJobResult> results) throws GridException {
int sum = 0;
// For the sake of this example, let's sum all results.
for (GridComputeJobResult res : results) {
sum += (Integer)res.getData();
}
return sum;
}
}
| Modifier | Constructor and Description |
|---|---|
protected |
GridComputeJobContinuationAdapter()
No-arg constructor.
|
protected |
GridComputeJobContinuationAdapter(Object... args)
Creates job with specified arguments.
|
protected |
GridComputeJobContinuationAdapter(Object arg)
Creates job with one arguments.
|
| Modifier and Type | Method and Description |
|---|---|
void |
callcc()
Resumes job if it was held by
GridComputeJobContinuation.holdcc() method. |
boolean |
heldcc()
Checks if job execution has been temporarily held (suspended).
|
<T> T |
holdcc()
Holds (suspends) a given job indefinitely until
GridComputeJobContinuation.callcc() is called. |
<T> T |
holdcc(long timeout)
Holds (suspends) a given job for specified timeout or until
GridComputeJobContinuation.callcc() is called. |
argument, call, cancel, isCancelled, setArgumentsclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexecuteprotected GridComputeJobContinuationAdapter()
protected GridComputeJobContinuationAdapter(@Nullable Object arg)
arg - Job argument.public boolean heldcc()
If job has completed its execution, then false is always returned.
heldcc in interface GridComputeJobContinuationTrue if job has been held.public void callcc()
GridComputeJobContinuation.holdcc() method. Resuming job means that
GridComputeJob.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 GridComputeJobContinuation.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 GridComputeJobContinuation@Nullable public <T> T holdcc()
GridComputeJobContinuation.callcc() is called.
Job will remain in active queue, but its GridComputeJobContinuation.heldcc() method will
return true. Implementations of GridCollisionSpi 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 GridComputeJobContinuationnull for convenience to be used in code with return statement.@Nullable public <T> T holdcc(long timeout)
GridComputeJobContinuation.callcc() is called.
Holds (suspends) a given job for specified timeout or until GridComputeJobContinuation.callcc() is called.
Job will remain in active queue, but its GridComputeJobContinuation.heldcc() method will
return true. Implementations of GridCollisionSpi 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 GridComputeJobContinuationtimeout - Timeout in milliseconds after which job will be automatically resumed.null for convenience to be used in code with return statement.Copyright © 2014. All rights reserved.