T - Type of the task argument.R - Type of the task result returning from ComputeTask.reduce(List) method.public abstract class ComputeTaskAdapter<T,R> extends Object implements ComputeTask<T,R>
ComputeTask interface. Here is an example of
how GridComputeTaskAdapter can be used:
public class MyFooBarTask extends GridComputeTaskAdapter<String, String> {
// Inject load balancer.
@LoadBalancerResource
ComputeLoadBalancer balancer;
// Map jobs to grid nodes.
public Map<? extends ComputeJob, GridNode> map(List<GridNode> subgrid, String arg) throws IgniteCheckedException {
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<ComputeJobResult> results) throws IgniteCheckedException {
// For the purpose of this example we simply
// concatenate string representation of every
// job result
StringBuilder buf = new StringBuilder();
for (ComputeJobResult res : results) {
// Append string representation of result
// returned by every job.
buf.append(res.getData().string());
}
return buf.string();
}
}
For more information refer to ComputeTask documentation.| Constructor and Description |
|---|
ComputeTaskAdapter() |
| Modifier and Type | Method and Description |
|---|---|
ComputeJobResultPolicy |
result(ComputeJobResult res,
List<ComputeJobResult> rcvd)
Default implementation which will wait for all jobs to complete before
calling
ComputeTask.reduce(List) method. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitmap, reducepublic ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteException
ComputeTask.reduce(List) method.
If remote job resulted in exception (ComputeJobResult.getException() is not null),
then ComputeJobResultPolicy.FAILOVER policy will be returned if the exception is instance
of ClusterTopologyException or ComputeExecutionRejectedException, 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 ComputeTask<T,R>res - Received remote grid executable result.rcvd - All previously received results.IgniteException - If handling a job result caused an error effectively rejecting
a failover. This exception will be thrown out of ComputeTaskFuture.get() method.
Follow @ApacheIgnite
Ignite Fabric : ver. 1.5.11 Release Date : April 8 2016