Java Reference
In-Depth Information
public String[] reduce(List<GridJobResult> gridJobResults)
throws GridException {
Collection<String> res = new ArrayList<String>();
for (GridJobResult result : gridJobResults) {
String data = result.getData();
return res.toArray(new String[res.size()]);
This code is pretty easy to follow, but there is some “magic” going on that you need to be aware of.
When you call the method on the service with the @Gridify annotation pointing to this GridTask class, it
stops execution of method and loads an instance of this class. The parameters, as passed to the method
with the annotation, are passed to: split(int i, final GridifyArgument gridifyArgument) , which is
used to dole out GridJob instances, each one taking as their payload a name from the array. In this code,
we create the GridJob instances inline using GridJobAdapter , which is a template class. The work of each
GridJob instance is trivial; in this case, we actually just delegate to the first method on the service that we
created: saluteSomeoneInForeignLanguage . Note that the invocation of the service in this case does not
run the job on the grid again, as we're already on a node. The result is returned to the calling context,
which in this case is another virtual machine altogether.
All the results are collected and then passed to the reduce method on the Task class. This method is
responsible for doing something with the final results. In this case, the results are simply unwrapped and
returned as an array of Strings. Those results are then again sent to the calling context, which in this case
is our original method invocation on the service. The results returned from that invocation are the
results of all the processing. Thus, if you invoke saluteManyPeopleInRandomForeignLanguage with new
String[]{"Steve"}, you're likely to get "Bonjour Steve! " (or something like that), even though it
appears you're merely returning the input parameter.
10-6. On GridGain Deployment
There are several issues to be aware of when deploying applications using GridGain. How do you
configure nodes with specific properties that can be used for determining its eligibility for a certain job?
How do you inject Spring beans into a node? What is a .GAR ?
The issues you're likely to confront when using GridGaim stem mostly from the fact that what you
develop on one node can't always automatically work on another node with no additional configuration.
It becomes helpful to think about these deployment issues ahead of time, before you run into a wall in
Search WWH ::

Custom Search