Traveling Java 8 Lambdas With Headlands / JCache / Hazelcast 📎
Cache processors are able to perform operation on the whole cache:
curl -i -XPUT -d'duke' http://localhost:8080/headlands/resources/caches/workshops/entries/chief
curl -i -H'Content-type:application/json' -XPOST --data 'function process(cache, result) {
for each (entry in cache) {
var key = entry.key;
var value = entry.value;
print(key, "=", value);
result.put(key, value+" result");
}
return result;
}' http://localhost:8080/headlands/resources/cache-processors/workshops
An entry processor only operates on entries with passed keys:
curl -i -H'Content-type:application/json' -XPOST --data '{
"script" : "function process(entry, args) {return \"The answer: \" + entry.getValue();}",
"keys" : [
"chief"
]
}' http://localhost:8080/headlands/resources/entry-processors/workshops
With entry- and cache-processors written in JavaScript only String-instances travel over the wire but are materialized on the other serverside as Java instances. Functional Java 8 interfaces are serialized into a String instead of the default Java serialization.
Checkout the entire curl walk-through.
Headlands ships with hazelcast (just launch multiple instances to get an in-memory grid) and was tested on Payara (Java EE 7 + Java8)
See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: effectivejavaee.com.