Skip to content

Instantly share code, notes, and snippets.

@jbrisbin
Last active December 17, 2015 11:09
Show Gist options
  • Save jbrisbin/5600246 to your computer and use it in GitHub Desktop.
Save jbrisbin/5600246 to your computer and use it in GitHub Desktop.
Example of Riak data support based on Reactor.
// Set a UriTemplateSelector to respond to any events happening on data in the 'test' bucket
riak.on(U("/test/{key}"), (Event ev) -> {
String key = ev.getHeaders().get("key");
boolean isStore = StoreEvent.class.isInstance(ev);
// Only count down on store
if (isStore) {
latch.countDown();
}
});
// Get a Bucket and access it using a callback
riak.fetchBucket("test").onSuccess(
bucket -> {
// Create a regular RiakOperation<T> but execute it in the Dispatcher
StoreObject<String> storeOp = bucket.store("test", "Hello World!");
riak.send(storeOp);
}
);
// Get the value of a key as a String in an async Promise
Promise<String> pStr = riak.fetch(b, "test", String.class);
// Block the calling thread for 30 seconds to get the delayed result
String s = pStr.await(30, TimeUnit.SECONDS);
// Use Composable.map
Composable<String> cStr = riak.fetchBucket("test").map(
bucket -> {
return bucket.getName();
}
);
// Send bulk operations to the server
DeleteObject[] deleteOps = new DeleteObject[objCount];
for (int i = 0; i < objCount; i++) {
deleteOps[i] = test.delete("test" + i);
}
riak.send(deleteOps).onSuccess(v -> latch.countDown());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment