|
GridGain 2.0.3
Java API Specification |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.gridgain.grid.GridTaskAdapter<T,R>
T - Type of the task argument.R - Type of the task result returning from GridTask.reduce(List) method.public abstract class GridTaskAdapter<T,R>
Convenience adapter for GridTask interface. Here is an example of
how GridTaskAdapter can be used:
public class MyFooBarTask extends GridTaskAdapter<String, String> {
// Inject load balancer.
@GridLoadBalancerResource
GridLoadBalancer balancer;
// Map jobs to grid nodes.
public Map<? extends GridJob, GridNode> map(List<GridNode> subgrid, String arg) throws GridException {
Map<MyFooBarJob, GridNode> jobs = new HashMap<MyFooBarJob, GridNode>(subgrid.size());
// In more complex cases, you can actually do
// more complicated assignments of jobs to nodes.
for (int i = 0; i < subgrid.size(); i++) {
// Pick the next best balanced node for the job.
jobs.put(new MyFooBarJob(arg), balancer.getBalancedNode())
}
return jobs;
}
// Aggregate results into one compound result.
public String reduce(List<GridJobResult> results) throws GridException {
// For the purpose of this example we simply
// concatenate string representation of every
// job result
StringBuilder buf = new StringBuilder();
for (GridJobResult res : results) {
// Append string representation of result
// returned by every job.
buf.append(res.getData().toString());
}
return buf.toString();
}
}
For more information refer to GridTask documentation.

Documentation
Email Support
Online Forums
Issue Tracking
Author: 2005-2008 Copyright © GridGain Systems. All Rights Reserved. ver. 2.0.3
![]() |
![]() |
| Constructor Summary | |
|---|---|
GridTaskAdapter()
|
|
| Method Summary | |
|---|---|
GridJobResultPolicy |
result(GridJobResult result,
List<GridJobResult> received)
Default implementation which will wait for all jobs to complete before calling GridTask.reduce(List) method. |
| 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.GridTask |
|---|
map, reduce |
| Constructor Detail |
|---|
public GridTaskAdapter()
| Method Detail |
|---|
public GridJobResultPolicy result(GridJobResult result,
List<GridJobResult> received)
throws GridException
GridTask.reduce(List) method.
If remote job resulted in exception (GridJobResult.getException() is not null),
then GridJobResultPolicy.FAILOVER policy will be returned if the exception is instance
of GridTopologyException or GridExecutionRejectedException, which means that
remote node either failed or job execution was rejected before it got a chance to start. In all
other cases the exception will be rethrown which will ultimately cause task to fail.
result in interface GridTask<T,R>GridException - If handling a job result caused an error effectively rejecting
a failover. This exception will be thrown out of GridTaskFuture.get() method.result - Received remote grid executable result.received - All previously received results.
GridTask.result(GridJobResult, List)
|
GridGain 2.0.3
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.0.3.20052008
2005-2008 Copyright © GridGain Systems. All Rights Reserved. |
|