org.apache.ignite.internal.processors.streamer.task

## Class GridStreamerQueryTask<R>

- java.lang.Object
- - org.apache.ignite.compute.ComputeTaskAdapter<T,R>
  - - org.apache.ignite.internal.processors.closure.GridPeerDeployAwareTaskAdapter<Void,Collection<R>>
    - - org.apache.ignite.internal.processors.streamer.task.GridStreamerQueryTask<R>

All Implemented Interfaces:
  Serializable, ComputeTask<Void,Collection<R>>, GridPeerDeployAware

    public class GridStreamerQueryTask<R>
    extends GridPeerDeployAwareTaskAdapter<Void,Collection<R>>

Streamer query task.

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`GridStreamerQueryTask(IgniteClosure<StreamerContext,R> qryClos, String streamer)`

### Method Summary

Methods
`Map<? extends ComputeJob,ClusterNode>` `map(List<ClusterNode> subgrid, Void arg)` This method is called to map or split grid task into multiple grid jobs.
`Collection<R>` `reduce(List<ComputeJobResult> results)` Reduces (or aggregates) results received so far into one compound result to be returned to caller via `ComputeTaskFuture.get()` method.
`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 org.apache.ignite.internal.processors.closure.GridPeerDeployAwareTaskAdapter

`classLoader, deployClass`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### GridStreamerQueryTask

    public GridStreamerQueryTask(IgniteClosure<StreamerContext,R> qryClos,
                         @Nullable
                         String streamer)

Parameters:
  `qryClos` - Query closure.
  `streamer` - Streamer.

### Method Detail

#### map

    public Map<? extends ComputeJob,ClusterNode> map(List<ClusterNode> subgrid,
                                            @Nullable
                                            Void arg)

This method is called to map or split grid task into multiple grid jobs. This is the first method that gets called when task execution starts.

Parameters:
  `subgrid` - Nodes available for this task execution. Note that order of nodes is guaranteed to be randomized by container. This ensures that every time you simply iterate through grid nodes, the order of nodes will be random which over time should result into all nodes being used equally.
  `arg` - Task execution argument. Can be `null`. This is the same argument as the one passed into `Grid#execute(...)` methods.
Returns:
  Map of grid jobs assigned to subgrid node. Unless `ComputeTaskContinuousMapper` is injected into task, if `null` or empty map is returned, exception will be thrown.

#### reduce

    public Collection<R> reduce(List<ComputeJobResult> results)

Reduces (or aggregates) results received so far into one compound result to be returned to caller via `ComputeTaskFuture.get()` method.

Note, that if some jobs did not succeed and could not be failed over then the list of results passed into this method will include the failed results. Otherwise, failed results will not be in the list.

Parameters:
  `results` - Received results of broadcasted remote executions. Note that if task class has `ComputeTaskNoResultCache` annotation, then this list will be empty.
Returns:
  Grid job result constructed from results of remote executions.

#### result

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

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<Void,Collection<R>>`
Overrides:
  `result` in class `ComputeTaskAdapter<Void,Collection<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.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015