org.apache.ignite.compute

## Class ComputeTaskAdapter<T,R>

- java.lang.Object
- - org.apache.ignite.compute.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, GridCacheQueryJdbcMetadataTask, GridCacheQueryJdbcTask, GridifyDefaultRangeTask, GridifyDefaultTask, GridifyTaskAdapter, GridPeerDeployAwareTaskAdapter, IgfsTask, IgniteRemoteMapTask

    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

### Constructor Summary

Constructors
Constructor and Description
`ComputeTaskAdapter()`

### Method Summary

Methods
`ComputeJobResultPolicy` `result(ComputeJobResult res, List<ComputeJobResult> rcvd)` Default implementation which will wait for all jobs to complete before calling `ComputeTask.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.apache.ignite.compute.ComputeTask

`map, reduce`

### Constructor Detail

#### ComputeTaskAdapter

    public ComputeTaskAdapter()

### Method Detail

#### result

    public ComputeJobResultPolicy result(ComputeJobResult res,
                                List<ComputeJobResult> rcvd)
                                  throws IgniteException

Default implementation which will wait for all jobs to complete before calling `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.

Specified by:
  `result` in interface `ComputeTask<T,R>`
Parameters:
  `res` - Received remote grid executable result.
  `rcvd` - All previously received results.
Returns:
  Result policy that dictates how to process further upcoming job results.
Throws:
  `IgniteException` - If handling a job result caused an error effectively rejecting a failover. This exception will be thrown out of `ComputeTaskFuture.get()` method.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.0.0
Release Date | : April 30 2017