|
GridGain 2.1.0
Java API Specification |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.gridgain.grid.GridJobAdapter<G>
G - Type of the optional job argument.public abstract class GridJobAdapter<G extends Serializable>
Convenience adapter for GridJob implementations. It provides the
following functionality:
GridJob.cancel() method and ability
to check whether cancellation occurred.
GridJobAdapter.setArgument(Serializable)
and GridJobAdapter.getArgument() methods.
GridJobAdapter.addArgument(Serializable)
and GridJobAdapter.getArgument() methods.
Serializable.
public class TestGridTask extends GridTaskSplitAdapter<String, Integer> {
// Used to imitate some logic for the
// sake of this example
private int multiplier = 3;
@Override
protected Collection<? extends GridJob> split(int gridSize, final String arg) throws GridException {
List<GridJobAdapter<String>> jobs = new ArrayList<GridJobAdapter<String>>(gridSize);
for (int i = 0; i < gridSize; i++) {
jobs.add(new GridJobAdapter<String>() {
// Job execution logic.
public Serializable execute() throws GridException {
return multiplier * arg.length();
}
});
}
return jobs;
}
// Aggregate multiple job results into
// one task result.
public Integer reduce(List<GridJobResult> results) throws GridException {
int sum = 0;
// For the sake of this example, let's sum all results.
for (GridJobResult res : results) {
sum += (Integer)res.getData();
}
return sum;
}
}
Documentation
Email Support
Online Forums
Issue Tracking
Author: 2005-2008 Copyright © GridGain Systems. All Rights Reserved. ver. 2.1.0
![]() |
![]() |
| Constructor Summary | |
|---|---|
protected |
GridJobAdapter()
No-arg constructor. |
protected |
GridJobAdapter(G... args)
Creates job with specified arguments. |
| Method Summary | |
|---|---|
void |
addArgument(G arg)
Adds an optional job argument. |
void |
cancel()
This method is called when when system detects that completion of this job can no longer alter the overall outcome (for example, when parent task has already reduced the results). |
List<G> |
getAllArguments()
Gets ordered list of all job arguments set so far. |
G |
getArgument()
Gets job argument at position 0 or null if no argument was previously set. |
G |
getArgument(int pos)
Gets argument at specified position. |
protected boolean |
isCancelled()
This method tests whether or not this job was cancelled. |
void |
setArgument(G arg)
Sets an optional job argument at position 0. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.gridgain.grid.GridJob |
|---|
execute |
| Constructor Detail |
|---|
protected GridJobAdapter()
Note: the job argument will be null which usually is not the intended behavior.
You can use GridJobAdapter.setArgument(Serializable) to set job argument.
protected GridJobAdapter(G... args)
args - Job arguments.| Method Detail |
|---|
public void cancel()
GridTaskFuture.cancel() is called.
Note that job cancellation is only a hint, and just like with
Thread.interrupt() method, it is really upto the actual job
instance to gracefully finish execution and exit.
cancel in interface GridJobprotected final boolean isCancelled()
This method can be periodically called in GridJob.execute() method
implementation to check whether or not this job cancelled. Note that system
calls GridJobAdapter.cancel() method only as a hint and this is a responsibility of
the implementation of the job to properly cancel its execution.
public void setArgument(G arg)
arg - Executable argument.public void addArgument(G arg)
arg - Job argument.public G getArgument()
public G getArgument(int pos)
pos - Position of the argument.
public List<G> getAllArguments()
|
GridGain 2.1.0
Java API Specification |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
|
GridGain - Grid Computing Made Simple, ver. 2.1.0.19122008
2005-2008 Copyright © GridGain Systems. All Rights Reserved. |
|
|