Task Split

The ComputeTaskSplitAdapter offers more flexibility over the ComputeTaskAdapter to reduce boilerplate code. This class defines a simplified adapter for ComputeTask where it implements the job mapping to available cluster nodes. We need to consider splitting tasks and returning a list of ComputeJobs. This section implements the ComputeTaskSplitAdapter:

  1. Create a class, ClubExpenseTaskSplitAdapter, and extend it from ComputeTaskSplitAdapter. You need to implement the Collection<? extends ComputeJob> split(int gridSize, T arg) and reduce(List<ComputeJobResult> results) methods. The reduce logic remains the same, the split logic loops through the list of clubs and for each club creates a ClubExpenseCalculatorJob instance, adds it to a list, and finally returns the list of jobs:
        public class ClubExpenseTaskSplitAdapter extends 
ComputeTaskSplitAdapter<String[], Double> {
private static final long serialVersionUID = 1L;
@Override
//Same as before
public Double reduce(List<ComputeJobResult> results) throws
IgniteException {....}
@Override
protected Collection<? extends ComputeJob> split(int gridSize,
String[] clubs) throws IgniteException {
List<ComputeJob> jobs = new ArrayList<>();
for (String club : clubs) {
jobs.add(new ClubExpenseCalculatorJob(club));
}
return jobs;
}
}

  1. The call to the execute method needs to be changed. We will call the execute with the ClubExpenseTaskSplitAdapter class and clubNames. The remaining code remains unchanged:
      double totalCalculatedExpense = 
compute.execute(ClubExpenseTaskSplitAdapter.class, clubNames);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.31.125