T - Type of the task argument.R - Type of the task result returning from GridComputeTask.reduce(List) method.public abstract class GridComputeTaskAdapter<T,R> extends Object implements GridComputeTask<T,R>
GridComputeTask interface. Here is an example of
how GridComputeTaskAdapter can be used:
public class MyFooBarTask extends GridComputeTaskAdapter<String, String> {
// Inject load balancer.
@GridLoadBalancerResource
GridComputeLoadBalancer balancer;
// Map jobs to grid nodes.
public Map<? extends GridComputeJob, 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<GridComputeJobResult> results) throws GridException {
// For the purpose of this example we simply
// concatenate string representation of every
// job result
StringBuilder buf = new StringBuilder();
for (GridComputeJobResult res : results) {
// Append string representation of result
// returned by every job.
buf.append(res.getData().string());
}
return buf.string();
}
}
For more information refer to GridComputeTask documentation.| Constructor and Description |
|---|
GridComputeTaskAdapter() |
| Modifier and Type | Method and Description |
|---|---|
GridComputeJobResultPolicy |
result(GridComputeJobResult res,
List<GridComputeJobResult> rcvd)
Default implementation which will wait for all jobs to complete before
calling
GridComputeTask.reduce(List) method. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitmap, reducepublic GridComputeJobResultPolicy result(GridComputeJobResult res, List<GridComputeJobResult> rcvd) throws GridException
GridComputeTask.reduce(List) method.
If remote job resulted in exception (GridComputeJobResult.getException() is not null),
then GridComputeJobResultPolicy.FAILOVER policy will be returned if the exception is instance
of GridTopologyException or GridComputeExecutionRejectedException, 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 GridComputeTask<T,R>res - Received remote grid executable result.rcvd - All previously received results.GridException - If handling a job result caused an error effectively rejecting
a failover. This exception will be thrown out of GridComputeTaskFuture.get() method.Copyright © 2014. All rights reserved.