Interface IComputeTask<TArg, TJobRes, TRes>
Ignite task interface defines a task that can be executed on the grid. Ignite task is responsible for splitting business logic into multiple Ignite jobs, receiving results from individual Ignite jobs executing on remote nodes, and reducing (aggregating) received jobs' results into final Ignite task result.
Upon request to execute a task, the system will do the following:
- Inject annotated resources into task instance.
- Apply Map(IList<IClusterNode>, TArg). This method is responsible for splitting business logic into multiple jobs (units of execution) and mapping them to Ignite nodes.
- System will send mapped Ignite jobs to their respective nodes.
- Once job execution results become available, OnResult(IComputeJobResult<TJobRes>, IList<IComputeJobResult<TJobRes>>) method
will be called for ech received job result. The policy returned by this method will
determine the way task reacts to every job result.
If Wait is returned, task will continue to wait for other job results. If this result is the last job result, then reduce phase will be started.
If Reduce is returned, reduce phase will be started right away without waiting for other jobs completion (all remaining jobs will receive cancel request).
If Failover is returned, job will be failed over to another node for execution. Note that if you use ComputeTaskAdapter<TArg, TJobRes, TTaskRes>, it will automatically fail jobs to another node for 2 well-known failure cases: 1) job has failed to due to node crash (in this case Exception will return ClusterTopologyException); 2) job execution was rejected, i.e. remote node has cancelled job before it got a chance to execute, while it still was on the waiting list. (in this case Exception will return ComputeExecutionRejectedException).
- Once all results are received or OnResult(IComputeJobResult<TJobRes>, IList<IComputeJobResult<TJobRes>>) method returned Reduce policy, method Reduce(IList<IComputeJobResult<TJobRes>>) is called to aggregate received results into one final result. Once this method is finished the execution of the Ignite task is complete. This result will be returned to the user through future.
public interface IComputeTask<in TArg, TJobRes, out TRes>
Type of job result.
Type of final task result after reduce.
This method is called to map or split Ignite task into multiple Ignite jobs. This is the first method that gets called when task execution starts.
IDictionary<IComputeJob<TJobRes>, IClusterNode> Map(IList<IClusterNode> subgrid, TArg arg)
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 Ignite nodes, the order of nodes will be random which over time should result into all nodes being used equally.
Task execution argument. Can be
Map of Ignite jobs assigned to subgrid node. If
Asynchronous callback invoked every time a result from remote execution is received. It is ultimately upto this method to return a policy based on which the system will either wait for more results, reduce results received so far, or failover this job to another node. See ComputeJobResultPolicy for more information.
ComputeJobResultPolicy OnResult(IComputeJobResult<TJobRes> res, IList<IComputeJobResult<TJobRes>> rcvd)
Received remote Ignite executable result.
All previously received results. Note that if task class has ComputeTaskNoResultCacheAttribute attribute, then this list will be empty.
Result policy that dictates how to process further upcoming job results.
Reduces (or aggregates) results received so far into one compound result to be returned to caller via future.
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.
TRes Reduce(IList<IComputeJobResult<TJobRes>> results)
Received job results. Note that if task class has ComputeTaskNoResultCacheAttribute attribute, then this list will be empty.
Task result constructed from results of remote executions.