Java Reference
In-Depth Information
In this example, we'll build a modified version of the previous solution that takes an array of String
parameters. We intend for all entries in the array to be farmed out to the grid. Let's add the call from the
client, which is the Main class we used earlier:
System.out.println("Results:" + StringUtils.join(
salutationServiceImpl.saluteManyPeopleInRandomForeignLanguage(names), ","));
We add one method to the original service interface and implementation.
@Gridify( taskClass = MultipleSalutationTask.class )
public String[] saluteManyPeopleInRandomForeignLanguage(String[] recipients) {
return recipients;
As you can see, the method is simple. The only salient piece is the modified @Gridify annotation, which
in this case has a taskClass parameter pointing to a MultipleSalutationTask class.
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.gridgain.grid.GridException;
import org.gridgain.grid.GridJob;
import org.gridgain.grid.GridJobAdapter;
import org.gridgain.grid.GridJobResult;
import org.gridgain.grid.gridify.GridifyArgument;
import org.gridgain.grid.gridify.GridifyTaskSplitAdapter;
public class MultipleSalutationTask extends GridifyTaskSplitAdapter<String[]> {
private static final long serialVersionUID = 1L;
protected Collection<? extends GridJob> split(int i,
final GridifyArgument gridifyArgument) throws GridException {
Collection<GridJob> jobs = new ArrayList<GridJob>();
Object[] params = gridifyArgument.getMethodParameters();
String[] names = (String[]) params[0];
for (final String n : names)
jobs.add(new GridJobAdapter<String>(n) {
private static final long serialVersionUID = 1L;
public Serializable execute() throws GridException {
SalutationService service =
(SalutationService) gridifyArgument.getTarget();
return service.saluteSomeoneInForeignLanguage(n);
return jobs;
Search WWH ::

Custom Search