T
- Type of the task execution argument.R
- Type of the task result returning from ComputeTask.reduce(List)
method.public abstract class ComputeTaskSplitAdapter<T,R> extends ComputeTaskAdapter<T,R>
ComputeTask
. This adapter can be used
when jobs can be randomly assigned to available grid nodes. This adapter is sufficient
in most homogeneous environments where all nodes are equally suitable for executing grid
job. See split(int, Object)
method for more details.
Below is a coding example of how you would use ComputeTaskSplitAdapter
:
public class MyFooBarTask extends ComputeTaskSplitAdapter<Object, String> { @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { List<MyFooBarJob> jobs = new ArrayList<MyFooBarJob>(gridSize); for (int i = 0; i < gridSize; i++) { jobs.add(new MyFooBarJob(arg)); } // Node assignment via load balancer // happens automatically. 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(); } }
Constructor and Description |
---|
ComputeTaskSplitAdapter() |
Modifier and Type | Method and Description |
---|---|
@NotNull Map<? extends ComputeJob,ClusterNode> |
map(List<ClusterNode> subgrid,
T arg)
This method is called to map or split grid task into multiple grid jobs.
|
protected abstract Collection<? extends ComputeJob> |
split(int gridSize,
T arg)
This is a simplified version of
ComputeTask.map(List, Object) method. |
result
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
reduce
protected abstract Collection<? extends ComputeJob> split(int gridSize, T arg) throws IgniteException
ComputeTask.map(List, Object)
method.
This method basically takes given argument and splits it into a collection
of ComputeJob
using provided grid size as indication of how many node are
available. These jobs will be randomly mapped to available grid nodes. Note that
if number of jobs is greater than number of grid nodes (i.e, grid size), the grid
nodes will be reused and some jobs will end up on the same grid nodes.
gridSize
- Number of available grid nodes. Note that returned number of
jobs can be less, equal or greater than this grid size.arg
- Task execution argument. Can be null
.IgniteException
- Thrown in case of any errors.ComputeTask.map(List, Object)
@NotNull public final @NotNull Map<? extends ComputeJob,ClusterNode> map(List<ClusterNode> subgrid, T arg)
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.ComputeTaskContinuousMapper
is
injected into task, if null
or empty map is returned, exception will be thrown to the user.
GridGain In-Memory Computing Platform : ver. 8.9.15 Release Date : December 3 2024