Java Reference
In-Depth Information
You can use GridGain's @Gridify annotation along with some Spring AOP configuration to let GridGain
know that it can parallelize the execution of the method across the grid.
The first use case you're likely to have is to simply be able to farm out functionality in a bean to other
nodes, as a load-balancing precaution, for example. GridGain provides load balancing as well as fault
tolerance and routing out of the box, which you get for free by adding this annotation. Let's take a look at
a simple service bean with a single method that we want to farm out to the grid. The interface contract
looks like the following:
package com.apress.springenterpriserecipes.distributedspring.gridgain;
public interface SalutationService {
String saluteSomeoneInForeignLanguage( String recipient);
The only salient requirement here is the saluteSomeoneInForeignLanguage method. Naturally, this is
also the method we want to be run on the grid when possible. The implementation looks like this:
package com.apress.springenterpriserecipes.distributedspring.gridgain;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.gridgain.grid.gridify.Gridify;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
* Admittedly trivial example of saying 'hello' in a few languages
public class SalutationServiceImpl implements SalutationService, Serializable,
ApplicationContextAware {
private static final long serialVersionUID = 1L;
private Map<String, String> salutations;
public SalutationServiceImpl() {
salutations = new HashMap<String, String>();
"bonjour %s!");
"buongiorno %s!");
Search WWH ::

Custom Search