Java Reference
In-Depth Information
salutations.put(Locale.ENGLISH.getLanguage().toLowerCase(),
"hello %s!");
}
@Gridify
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=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xmlns:util=" http://www.springframework.org/schema/util"
xmlns:aop=" http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/util/spring-aop-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
Search WWH ::




Custom Search