Skip to content

AdamBien/headlands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

headlands

RESTified JCACHE / JSR-107

Installation

  1. Requirements: Java 8 and Java EE 7 server. Tested with WildFly 8 and GlassFish v4
  2. Download the headlands.war and drop it into the "autodeployment" directory.

Usage

Create Cache

curl -i -XPUT -H"Content-type: application/json" -d'{"storeByValue":true}' http://localhost:8080/headlands/resources/caches/workshops

Get cache names

curl http://localhost:8080/headlands/resources/caches/      

Cache Configuration

curl -i -XOPTIONS http://localhost:8080/headlands/resources/caches/workshops

put('chief','duke') at the workshops cache

curl -i -XPUT -d'duke' http://localhost:8080/headlands/resources/caches/workshops/entries/chief

List entries for the cache "workshops"

curl -i http://localhost:8080/headlands/resources/caches/workshops/entries/    

Delete the entry with the key: "chief" at the cache workshops

curl -i -XDELETE http://localhost:8080/headlands/resources/caches/workshops/entries/chief      

Delete all entries of the workshops cache

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"}

Receiving WebSocket notifications

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"
	 }
}