RESTified JCACHE / JSR-107
- Requirements: Java 8 and Java EE 7 server. Tested with WildFly 8 and GlassFish v4
- Download the headlands.war and drop it into the "autodeployment" directory.
curl -i -XPUT -H"Content-type: application/json" -d'{"storeByValue":true}' http://localhost:8080/headlands/resources/caches/workshops
curl http://localhost:8080/headlands/resources/caches/
curl -i -XOPTIONS http://localhost:8080/headlands/resources/caches/workshops
curl -i -XPUT -d'duke' http://localhost:8080/headlands/resources/caches/workshops/entries/chief
curl -i http://localhost:8080/headlands/resources/caches/workshops/entries/
curl -i -XDELETE http://localhost:8080/headlands/resources/caches/workshops/entries/chief
curl -i -XDELETE http://localhost:8080/headlands/resources/caches/workshops/entries
Submit and execute a cache processor written in JavaScript (Nashorn) to the workshops cache. A cache processor has access to the entire cache with the specified name. The result is just a convenience Map which is going to be serialized and sent back to the client.
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
Output:
{"chief":"duke result"}
Submit and execute an entry processor which operates on the specified 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
Output:
{"chief":"The answer: duke"}
Cache-change events are delivered via the following URI
ws://localhost:8080/headlands/firehose/{cache-name}
The change events are delivered in the following JSON-format:
{"cacheName":"cache-1465959736089","eventType":"UPDATED","key":"status1465959736241","status1465959736241":
{"newValue":"java rocks 1465959736241-UPDATED",
"oldValue":"java rocks 1465959736241"
}
}