Class ComputeTaskAdapter<T,​R>

  • Type Parameters:
    T - Type of the task argument.
    R - Type of the task result returning from ComputeTask.reduce(List) method.
    All Implemented Interfaces:
    Serializable, ComputeTask<T,​R>
    Direct Known Subclasses:
    ComputeTaskSplitAdapter

    public abstract class ComputeTaskAdapter<T,​R>
    extends Object
    implements ComputeTask<T,​R>
    Convenience adapter for ComputeTask interface. Here is an example of how ComputeTaskAdapter can be used:
     public class MyFooBarTask extends ComputeTaskAdapter<String, String> {
         // Inject load balancer.
         @LoadBalancerResource
         ComputeLoadBalancer balancer;
    
         // Map jobs to grid nodes.
         public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, String arg) throws IgniteCheckedException {
             Map<MyFooBarJob, ClusterNode> jobs = new HashMap<MyFooBarJob, ClusterNode>(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.
    See Also:
    Serialized Form