GridGain™ 2.0.3
Java API Specification

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

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

public abstract class GridTaskAdapter<T,R>
extends Object
implements GridTask<T,R>

Convenience adapter for GridTask interface. Here is an example of how GridTaskAdapter can be used:

 public class MyFooBarTask extends GridTaskAdapter<String, String> {
     // Inject load balancer.
     @GridLoadBalancerResource
     GridLoadBalancer balancer;

     // Map jobs to grid nodes.
     public Map<? extends GridJob, GridNode> map(List<GridNode> subgrid, String arg) throws GridException {
         Map<MyFooBarJob, GridNode> jobs = new HashMap<MyFooBarJob, GridNode>(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<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().toString());
         }

         return buf.toString();
     }
 }
 
For more information refer to GridTask documentation.

Migrating to GridGain 2.0

In GridGain 2.0 this interface API has been updated for better static type checking. Although the change is trivial and provides much better type safety during development - it introduced incompatibility with prior versions of GridGain. Follow this link for easy source code migration instructions.



See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

Author:   2005-2008 Copyright © GridGain Systems. All Rights Reserved. ver. 2.0.3

See Also:
Serialized Form
 

Constructor Summary
GridTaskAdapter()
           
 
Method Summary
 GridJobResultPolicy result(GridJobResult result, List<GridJobResult> received)
          Default implementation which will wait for all jobs to complete before calling GridTask.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.gridgain.grid.GridTask
map, reduce
 

Constructor Detail

GridTaskAdapter

public GridTaskAdapter()
Method Detail

result

public GridJobResultPolicy result(GridJobResult result,
                                  List<GridJobResult> received)
                           throws GridException
Default implementation which will wait for all jobs to complete before calling GridTask.reduce(List) method.

If remote job resulted in exception (GridJobResult.getException() is not null), then GridJobResultPolicy.FAILOVER policy will be returned if the exception is instance of GridTopologyException or GridExecutionRejectedException, 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 GridTask<T,R>
Throws:
GridException - If handling a job result caused an error effectively rejecting a failover. This exception will be thrown out of GridTaskFuture.get() method.
Parameters:
result - Received remote grid executable result.
received - All previously received results.
Returns:
Result policy that dictates how to process further upcoming job results.
See Also:
GridTask.result(GridJobResult, List)

GridGain™ 2.0.3
Java API Specification

GridGain™ - Grid Computing Made Simple, ver. 2.0.3.20052008
2005-2008 Copyright © GridGain Systems. All Rights Reserved.