Spring Data Key-Value

org.springframework.data.keyvalue.riak.core
Class AsyncRiakTemplate

java.lang.Object
  extended by org.springframework.web.client.support.RestGatewaySupport
      extended by org.springframework.data.keyvalue.riak.core.AbstractRiakTemplate
          extended by org.springframework.data.keyvalue.riak.core.AsyncRiakTemplate
All Implemented Interfaces:
BeanClassLoaderAware, InitializingBean, AsyncBucketKeyValueStoreOperations, AsyncMapReduceOperations

public class AsyncRiakTemplate
extends AbstractRiakTemplate
implements AsyncBucketKeyValueStoreOperations, AsyncMapReduceOperations

An implementation of AsyncBucketKeyValueStoreOperations and AsyncMapReduceOperations for the Riak datastore.

To use the AsyncRiakTemplate, create a singleton in your Spring application-context.xml:


 <bean id="riak" class="org.springframework.data.keyvalue.riak.core.AsyncRiakTemplate"
     p:defaultUri="http://localhost:8098/riak/{bucket}/{key}"
     p:mapReduceUri="http://localhost:8098/mapred"/>
 
To store and retrieve objects in Riak, use the setXXX and getXXX methods (example in Groovy):

 def callback = [
   completed: { v, meta ->
     ... do something with results ...
   },
   failed: { err ->
   }
 ] as AsyncKeyValueStoreOperation
 def obj = new TestObject(name: "My Name", age: 40)
 def future = riak.set("mybucket", "mykey", obj, callback)
 ... this runs asynchronously, so do other work ...
 def name = future.get().name
 println "Hello $name!"
 

Author:
J. Brisbin <[email protected]>

Nested Class Summary
protected  class AsyncRiakTemplate.AsyncDelete<V,R>
           
protected  class AsyncRiakTemplate.AsyncGet<T,R>
           
protected  class AsyncRiakTemplate.AsyncHead<V,R>
           
protected  class AsyncRiakTemplate.AsyncMapReduce<R>
           
protected  class AsyncRiakTemplate.AsyncPost<V,R>
           
protected  class AsyncRiakTemplate.AsyncPut<V,R>
           
protected  class AsyncRiakTemplate.LoggingErrorHandler
           
 
Field Summary
protected  AsyncKeyValueStoreOperation<Throwable,Object> defaultErrorHandler
           
 
Fields inherited from class org.springframework.data.keyvalue.riak.core.AbstractRiakTemplate
bucketKeyResolvers, cache, classLoader, conversionService, defaultQosParameters, defaultType, defaultUri, groovyPresent, httpDate, log, mapReduceUri, prefix, RIAK_CLIENT_ID, RIAK_META_CLASSNAME, RIAK_VCLOCK, useCache, workerPool
 
Fields inherited from class org.springframework.web.client.support.RestGatewaySupport
logger
 
Constructor Summary
AsyncRiakTemplate()
           
AsyncRiakTemplate(ClientHttpRequestFactory requestFactory)
           
 
Method Summary
<B,K,R> Future<?>
containsKey(B bucket, K key, AsyncKeyValueStoreOperation<Boolean,R> callback)
           
<B,K,R> Future<?>
delete(B bucket, K key, AsyncKeyValueStoreOperation<Boolean,R> callback)
          Delete a specific entry from this data store.
<R> Future<?>
execute(MapReduceJob job, AsyncKeyValueStoreOperation<List<?>,R> callback)
          Execute a MapReduceJob synchronously.
<B,K,V,R> Future<?>
get(B bucket, K key, AsyncKeyValueStoreOperation<V,R> callback)
           
<B,K,V,R> Future<?>
getAndSet(B bucket, K key, V value, AsyncKeyValueStoreOperation<V,R> callback)
           
<B,K,R> Future<?>
getAndSetAsBytes(B bucket, K key, byte[] value, AsyncKeyValueStoreOperation<byte[],R> callback)
           
<B,K,V,T,R>
Future<?>
getAndSetAsType(B bucket, K key, V value, Class<T> requiredType, AsyncKeyValueStoreOperation<T,R> callback)
           
<B,K,R> Future<?>
getAsBytes(B bucket, K key, AsyncKeyValueStoreOperation<byte[],R> callback)
           
<B,K,T,R> Future<?>
getAsType(B bucket, K key, Class<T> requiredType, AsyncKeyValueStoreOperation<T,R> callback)
           
<B,R> Future<?>
getBucketSchema(B bucket, QosParameters qosParams, AsyncKeyValueStoreOperation<Map<String,Object>,R> callback)
           
 AsyncKeyValueStoreOperation<Throwable,Object> getDefaultErrorHandler()
           
<B,K> RiakMetaData
getMetaData(B bucket, K key)
           
<B,K,T,R> Future<?>
getWithMetaData(B bucket, K key, Class<T> requiredType, AsyncKeyValueStoreOperation<T,R> callback)
           
<B,V,R> Future<V>
put(B bucket, V value, AsyncKeyValueStoreOperation<V,R> callback)
           
<B,V,R> Future<V>
put(B bucket, V value, Map<String,String> metaData, AsyncKeyValueStoreOperation<V,R> callback)
           
<B,V,R> Future<V>
put(B bucket, V value, Map<String,String> metaData, QosParameters qosParams, AsyncKeyValueStoreOperation<V,R> callback)
           
<B,K,V,R> Future<?>
set(B bucket, K key, V value, AsyncKeyValueStoreOperation<V,R> callback)
          Put an object in Riak at a specific bucket and key and invoke callback with the value pulled back out of Riak after the update, which contains full headers and metadata.
<B,K,V,R> Future<?>
set(B bucket, K key, V value, QosParameters qosParams, AsyncKeyValueStoreOperation<V,R> callback)
           
<B,K,R> Future<?>
setAsBytes(B bucket, K key, byte[] value, AsyncKeyValueStoreOperation<byte[],R> callback)
           
<B,K,R> Future<?>
setAsBytes(B bucket, K key, byte[] value, QosParameters qosParams, AsyncKeyValueStoreOperation<byte[],R> callback)
           
 void setDefaultErrorHandler(AsyncKeyValueStoreOperation<Throwable,Object> defaultErrorHandler)
           
<B,K,V,R> Future<?>
setIfKeyNonExistent(B bucket, K key, V value, AsyncKeyValueStoreOperation<V,R> callback)
           
<B,K,R> Future<?>
setIfKeyNonExistentAsBytes(B bucket, K key, byte[] value, AsyncKeyValueStoreOperation<byte[],R> callback)
           
<B,K,V,R> Future<?>
setWithMetaData(B bucket, K key, V value, Map<String,String> metaData, AsyncKeyValueStoreOperation<V,R> callback)
           
<B,K,V,R> Future<V>
setWithMetaData(B bucket, K key, V value, Map<String,String> metaData, QosParameters qosParams, AsyncKeyValueStoreOperation<V,R> callback)
           
 
Methods inherited from class org.springframework.data.keyvalue.riak.core.AbstractRiakTemplate
afterPropertiesSet, checkCache, defaultHeaders, extractMediaType, extractMetaData, extractQosParameters, extractValue, getConversionService, getDefaultQosParameters, getDefaultType, getDefaultUri, getHost, getIgnoreNotFound, getMapReduceUri, getPort, getPrefix, getType, getType, getWorkerPool, isUseCache, resolveBucketKeyPair, setBeanClassLoader, setConversionService, setDefaultQosParameters, setDefaultType, setDefaultUri, setIgnoreNotFound, setMapReduceUri, setUseCache, setWorkerPool
 
Methods inherited from class org.springframework.web.client.support.RestGatewaySupport
getRestTemplate, setRestTemplate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultErrorHandler

protected AsyncKeyValueStoreOperation<Throwable,Object> defaultErrorHandler
Constructor Detail

AsyncRiakTemplate

public AsyncRiakTemplate()

AsyncRiakTemplate

public AsyncRiakTemplate(ClientHttpRequestFactory requestFactory)
Method Detail

getDefaultErrorHandler

public AsyncKeyValueStoreOperation<Throwable,Object> getDefaultErrorHandler()

setDefaultErrorHandler

public void setDefaultErrorHandler(AsyncKeyValueStoreOperation<Throwable,Object> defaultErrorHandler)

set

public <B,K,V,R> Future<?> set(B bucket,
                               K key,
                               V value,
                               AsyncKeyValueStoreOperation<V,R> callback)
Description copied from interface: AsyncBucketKeyValueStoreOperations
Put an object in Riak at a specific bucket and key and invoke callback with the value pulled back out of Riak after the update, which contains full headers and metadata.

Specified by:
set in interface AsyncBucketKeyValueStoreOperations
callback - Called with the update value pulled from Riak

set

public <B,K,V,R> Future<?> set(B bucket,
                               K key,
                               V value,
                               QosParameters qosParams,
                               AsyncKeyValueStoreOperation<V,R> callback)
Specified by:
set in interface AsyncBucketKeyValueStoreOperations
Returns:

setAsBytes

public <B,K,R> Future<?> setAsBytes(B bucket,
                                    K key,
                                    byte[] value,
                                    AsyncKeyValueStoreOperation<byte[],R> callback)
Specified by:
setAsBytes in interface AsyncBucketKeyValueStoreOperations
Returns:

setWithMetaData

public <B,K,V,R> Future<V> setWithMetaData(B bucket,
                                           K key,
                                           V value,
                                           Map<String,String> metaData,
                                           QosParameters qosParams,
                                           AsyncKeyValueStoreOperation<V,R> callback)
Specified by:
setWithMetaData in interface AsyncBucketKeyValueStoreOperations
Returns:

put

public <B,V,R> Future<V> put(B bucket,
                             V value,
                             AsyncKeyValueStoreOperation<V,R> callback)

put

public <B,V,R> Future<V> put(B bucket,
                             V value,
                             Map<String,String> metaData,
                             AsyncKeyValueStoreOperation<V,R> callback)

put

public <B,V,R> Future<V> put(B bucket,
                             V value,
                             Map<String,String> metaData,
                             QosParameters qosParams,
                             AsyncKeyValueStoreOperation<V,R> callback)

get

public <B,K,V,R> Future<?> get(B bucket,
                               K key,
                               AsyncKeyValueStoreOperation<V,R> callback)
Specified by:
get in interface AsyncBucketKeyValueStoreOperations
Returns:

getMetaData

public <B,K> RiakMetaData getMetaData(B bucket,
                                      K key)

getBucketSchema

public <B,R> Future<?> getBucketSchema(B bucket,
                                       QosParameters qosParams,
                                       AsyncKeyValueStoreOperation<Map<String,Object>,R> callback)

getWithMetaData

public <B,K,T,R> Future<?> getWithMetaData(B bucket,
                                           K key,
                                           Class<T> requiredType,
                                           AsyncKeyValueStoreOperation<T,R> callback)

getAsBytes

public <B,K,R> Future<?> getAsBytes(B bucket,
                                    K key,
                                    AsyncKeyValueStoreOperation<byte[],R> callback)
Specified by:
getAsBytes in interface AsyncBucketKeyValueStoreOperations
Returns:

getAsType

public <B,K,T,R> Future<?> getAsType(B bucket,
                                     K key,
                                     Class<T> requiredType,
                                     AsyncKeyValueStoreOperation<T,R> callback)
Specified by:
getAsType in interface AsyncBucketKeyValueStoreOperations
Returns:

getAndSet

public <B,K,V,R> Future<?> getAndSet(B bucket,
                                     K key,
                                     V value,
                                     AsyncKeyValueStoreOperation<V,R> callback)
Specified by:
getAndSet in interface AsyncBucketKeyValueStoreOperations
Returns:

getAndSetAsBytes

public <B,K,R> Future<?> getAndSetAsBytes(B bucket,
                                          K key,
                                          byte[] value,
                                          AsyncKeyValueStoreOperation<byte[],R> callback)
Specified by:
getAndSetAsBytes in interface AsyncBucketKeyValueStoreOperations
Returns:

getAndSetAsType

public <B,K,V,T,R> Future<?> getAndSetAsType(B bucket,
                                             K key,
                                             V value,
                                             Class<T> requiredType,
                                             AsyncKeyValueStoreOperation<T,R> callback)
Specified by:
getAndSetAsType in interface AsyncBucketKeyValueStoreOperations
Returns:

setIfKeyNonExistent

public <B,K,V,R> Future<?> setIfKeyNonExistent(B bucket,
                                               K key,
                                               V value,
                                               AsyncKeyValueStoreOperation<V,R> callback)
Specified by:
setIfKeyNonExistent in interface AsyncBucketKeyValueStoreOperations
Returns:

setIfKeyNonExistentAsBytes

public <B,K,R> Future<?> setIfKeyNonExistentAsBytes(B bucket,
                                                    K key,
                                                    byte[] value,
                                                    AsyncKeyValueStoreOperation<byte[],R> callback)
Specified by:
setIfKeyNonExistentAsBytes in interface AsyncBucketKeyValueStoreOperations
Returns:

containsKey

public <B,K,R> Future<?> containsKey(B bucket,
                                     K key,
                                     AsyncKeyValueStoreOperation<Boolean,R> callback)
Specified by:
containsKey in interface AsyncBucketKeyValueStoreOperations
Returns:

delete

public <B,K,R> Future<?> delete(B bucket,
                                K key,
                                AsyncKeyValueStoreOperation<Boolean,R> callback)
Description copied from interface: AsyncBucketKeyValueStoreOperations
Delete a specific entry from this data store.

Specified by:
delete in interface AsyncBucketKeyValueStoreOperations
Returns:

setAsBytes

public <B,K,R> Future<?> setAsBytes(B bucket,
                                    K key,
                                    byte[] value,
                                    QosParameters qosParams,
                                    AsyncKeyValueStoreOperation<byte[],R> callback)
Specified by:
setAsBytes in interface AsyncBucketKeyValueStoreOperations
Returns:

setWithMetaData

public <B,K,V,R> Future<?> setWithMetaData(B bucket,
                                           K key,
                                           V value,
                                           Map<String,String> metaData,
                                           AsyncKeyValueStoreOperation<V,R> callback)
Specified by:
setWithMetaData in interface AsyncBucketKeyValueStoreOperations
Returns:

execute

public <R> Future<?> execute(MapReduceJob job,
                             AsyncKeyValueStoreOperation<List<?>,R> callback)
Description copied from interface: AsyncMapReduceOperations
Execute a MapReduceJob synchronously.

Specified by:
execute in interface AsyncMapReduceOperations
Returns:

Spring Data Key-Value

Copyright © 2010-2011 SpringSource. All Rights Reserved.