GridGain™ 3.6.0e
Enterprise Edition

org.gridgain.grid
Class GridTaskSplitAdapter<T,R>

java.lang.Object
  extended by org.gridgain.grid.lang.GridMetadataAwareAdapter
      extended by org.gridgain.grid.GridTaskAdapter<T,R>
          extended by org.gridgain.grid.GridTaskSplitAdapter<T,R>
Type Parameters:
T - Type of the task execution argument.
R - Type of the task result returning from GridTask.reduce(List) method.
All Implemented Interfaces:
Serializable, Cloneable, GridMetadataAware, GridPeerDeployAware, GridTask<T,R>
Direct Known Subclasses:
GridifyTaskSplitAdapter, GridTaskNoReduceSplitAdapter

public abstract class GridTaskSplitAdapter<T,R>
extends GridTaskAdapter<T,R>

This class defines simplified adapter for GridTask. 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 GridTaskSplitAdapter.split(int, Object) method for more details.

Below is a coding example of how you would use GridTaskSplitAdapter:

 public class MyFooBarTask extends GridTaskSplitAdapter<Object, String> {
     @Override
     protected Collection<? extends GridJob> split(int gridSize, Object arg) throws GridException {
         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<GridJobResult> results) throws GridException {
         // For the purpose of this example we simply
         // concatenate string representation of every
         // job result
         StringBuilder buf = new StringBuilder();

         for (GridJobResult res : results) {
             // Append string representation of result
             // returned by every job.
             buf.append(res.getData().string());
         }

         return buf.string();
     }
 }
 

Wiki & Forum:


Wiki
Forum

See Also:
Serialized Form
 

Constructor Summary
protected GridTaskSplitAdapter()
          Empty constructor.
protected GridTaskSplitAdapter(GridPeerDeployAware p)
          Constructor that receives deployment information for task.
 
Method Summary
 Map<? extends GridJob,GridNode> map(List<GridNode> subgrid, T arg)
          This method is called to map or split grid task into multiple grid jobs.
protected abstract  Collection<? extends GridJob> split(int gridSize, T arg)
          This is a simplified version of GridTask.map(List, Object) method.
 
Methods inherited from class org.gridgain.grid.GridTaskAdapter
classLoader, deployClass, result, setPeerDeployAware
 
Methods inherited from class org.gridgain.grid.lang.GridMetadataAwareAdapter
addMeta, addMetaIfAbsent, addMetaIfAbsent, allMeta, clone, copyMeta, copyMeta, hasMeta, hasMeta, meta, putMetaIfAbsent, putMetaIfAbsent, readExternalMeta, removeMeta, removeMeta, replaceMeta, writeExternalMeta
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.gridgain.grid.GridTask
reduce
 

Constructor Detail

GridTaskSplitAdapter

protected GridTaskSplitAdapter()
Empty constructor.


GridTaskSplitAdapter

protected GridTaskSplitAdapter(GridPeerDeployAware p)
Constructor that receives deployment information for task.

Parameters:
p - Deployment information.
Method Detail

split

protected abstract Collection<? extends GridJob> split(int gridSize,
                                                       T arg)
                                                throws GridException
This is a simplified version of GridTask.map(List, Object) method.

This method basically takes given argument and splits it into a collection of GridJob 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.

Throws:
GridException - Thrown in case of any errors.
Parameters:
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.
Returns:
Collection of grid jobs. 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.
See Also:
GridTask.map(List, Object)

map

public final Map<? extends GridJob,GridNode> map(List<GridNode> subgrid,
                                                 T arg)
                                          throws GridException
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.

Throws:
GridException - If mapping could not complete successfully. This exception will be thrown out of GridTaskFuture.get() method.
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. If null or empty map is returned, exception will be thrown.

GridGain™ 3.6.0e
Enterprise Edition

GridGain - Real Time Big Data
Enterprise Edition, ver. 3.6.0e.13012012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Follow GridGain on Facebook Join GridGain User Group Follow GridGain on Twitter Follow GridGain on YouTube