Java Reference
In-Depth Information
"hello %s!");
public String saluteSomeoneInForeignLanguage(String recipient) {
Locale[] locales = new Locale[]{
Locale.FRENCH, Locale.ENGLISH, Locale.ITALIAN};
Locale locale = locales[
(int) Math.floor(Math.random() * locales.length)];
String language = locale.getLanguage();
Set<String> languages = salutations.keySet();
if (!languages.contains(language))
throw new java.lang.RuntimeException(
String.format("this isn't supported! You need to choose " +
"from among the accepted languages: %s",
StringUtils.join(languages.iterator(), ",")));
String salutation = String.format(
salutations.get(language), recipient);
System.out.println(String.format("returning: %s" ,salutation));
return salutation;
@Gridify(taskClass = MultipleSalutationTask.class)
public String[] saluteManyPeopleInRandomForeignLanguage(
String[] recipients) {
return recipients;
private ApplicationContext applicationContext;
public void setApplicationContext(
ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
There are no tell-tale signs that this code is Grid-enabled except for the @Gridify annotation.
Otherwise, the functionality is self-evident, and infinitely testable. We use Spring to ensure that this
bean is given a chance to run. The configuration of the Spring file ( gridservice.xml ) side looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
Search WWH ::

Custom Search