com.basho.riak.client.http
Class RiakClient

java.lang.Object
  extended by com.basho.riak.client.http.RiakClient

public class RiakClient
extends Object

Primary interface for interacting with Riak via HTTP.


Constructor Summary
RiakClient(RiakConfig config)
           
RiakClient(RiakConfig config, String clientId)
           
RiakClient(String url)
           
RiakClient(String url, String clientId)
           
 
Method Summary
 HttpResponse delete(String bucket, String key)
           
 HttpResponse delete(String bucket, String key, RequestMeta meta)
           
 FetchResponse fetch(String bucket, String key)
           
 FetchResponse fetch(String bucket, String key, RequestMeta meta)
           
 FetchResponse fetchMeta(String bucket, String key)
           
 FetchResponse fetchMeta(String bucket, String key, RequestMeta meta)
          Fetch metadata (e.g.
 BucketResponse getBucketSchema(String bucket)
           
 BucketResponse getBucketSchema(String bucket, RequestMeta meta)
           
 byte[] getClientId()
           
 RiakConfig getConfig()
           
 RiakExceptionHandler getExceptionHandler()
           
 org.apache.http.client.HttpClient getHttpClient()
           
 IndexResponse index(String bucket, String indexName, int value)
          Fetch the keys for index with value
 IndexResponse index(String bucket, String indexName, int start, int end)
          A range index query matching a int index from start to end
 IndexResponse index(String bucket, String indexName, String value)
          Fetch the keys for index with value
 IndexResponse index(String bucket, String indexName, String start, String end)
          A range index query matching a binary index from start to end
 BucketResponse listBucket(String bucket)
           
 BucketResponse listBucket(String bucket, RequestMeta meta)
           
 ListBucketsResponse listBuckets()
          Fetch a list of all the buckets in Riak
 MapReduceResponse mapReduce(String job)
           
 MapReduceResponse mapReduce(String job, RequestMeta meta)
           
 MapReduceBuilder mapReduceOverBucket(String bucket)
           
 MapReduceBuilder mapReduceOverObjects(Map<String,Set<String>> objects)
          Same as mapReduceOverBucket(String), except over a set of objects instead of a bucket.
 MapReduceBuilder mapReduceOverSearch(String bucket, String search)
          Same as mapReduceOverBucket(String), except over a riak-search query instead of a bucket.
 HttpResponse ping()
          GET Riak's ping resource.
 HttpResponse setBucketSchema(String bucket, RiakBucketInfo bucketInfo)
           
 HttpResponse setBucketSchema(String bucket, RiakBucketInfo bucketInfo, RequestMeta meta)
           
 void setClientId(String clientId)
           
 void setExceptionHandler(RiakExceptionHandler exceptionHandler)
           
 void shutdown()
           
 HttpResponse stats()
          GET Riak's /stats (status) resource.
 StoreResponse store(RiakObject object)
           
 StoreResponse store(RiakObject object, RequestMeta meta)
           
 FetchResponse stream(String bucket, String key)
           
 FetchResponse stream(String bucket, String key, RequestMeta meta)
          Similar to fetch(), except the HTTP connection is left open for successful responses, and the Riak response is provided as a stream.
 boolean stream(String bucket, String key, StreamHandler handler, RequestMeta meta)
           
 BucketResponse streamBucket(String bucket)
           
 BucketResponse streamBucket(String bucket, RequestMeta meta)
           
 WalkResponse walk(String bucket, String key, RiakWalkSpec walkSpec)
           
 WalkResponse walk(String bucket, String key, String walkSpec)
           
 WalkResponse walk(String bucket, String key, String walkSpec, RequestMeta meta)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RiakClient

public RiakClient(RiakConfig config)

RiakClient

public RiakClient(RiakConfig config,
                  String clientId)

RiakClient

public RiakClient(String url)

RiakClient

public RiakClient(String url,
                  String clientId)
Method Detail

getConfig

public RiakConfig getConfig()

setBucketSchema

public HttpResponse setBucketSchema(String bucket,
                                    RiakBucketInfo bucketInfo,
                                    RequestMeta meta)

setBucketSchema

public HttpResponse setBucketSchema(String bucket,
                                    RiakBucketInfo bucketInfo)

getBucketSchema

public BucketResponse getBucketSchema(String bucket,
                                      RequestMeta meta)

getBucketSchema

public BucketResponse getBucketSchema(String bucket)

listBucket

public BucketResponse listBucket(String bucket,
                                 RequestMeta meta)

listBucket

public BucketResponse listBucket(String bucket)

streamBucket

public BucketResponse streamBucket(String bucket,
                                   RequestMeta meta)

streamBucket

public BucketResponse streamBucket(String bucket)

store

public StoreResponse store(RiakObject object,
                           RequestMeta meta)

store

public StoreResponse store(RiakObject object)

fetchMeta

public FetchResponse fetchMeta(String bucket,
                               String key,
                               RequestMeta meta)
Fetch metadata (e.g. vclock, last modified, vtag) for the RiakObject stored at bucket and key.

NOTE: if there a sibling values (HTTP status code 300), then a full fetch(String, String, RequestMeta) is executed as well to get all meta values. Examine the FetchResponse.hasSiblings() value to determine if you need to perform conflict resolution.

Parameters:
bucket - The bucket containing the RiakObject to fetch.
key - The key of the RiakObject to fetch.
meta - Extra metadata to attach to the request such as an r- value for the request, HTTP headers, and other query parameters. See RequestMeta.readParams(int).
Returns:
FetchResponse containing HTTP response information and a RiakObject containing only metadata and no value.
Throws:
RiakIORuntimeException - If an error occurs during communication with the Riak server.
RiakResponseRuntimeException - If the Riak server returns a malformed response.

fetchMeta

public FetchResponse fetchMeta(String bucket,
                               String key)

fetch

public FetchResponse fetch(String bucket,
                           String key,
                           RequestMeta meta)

fetch

public FetchResponse fetch(String bucket,
                           String key)

stream

public FetchResponse stream(String bucket,
                            String key,
                            RequestMeta meta)
Similar to fetch(), except the HTTP connection is left open for successful responses, and the Riak response is provided as a stream. The user must remember to call HttpResponseDecorator.close() on the return value.

Parameters:
bucket - The bucket containing the RiakObject to fetch.
key - The key of the RiakObject to fetch.
meta - Extra metadata to attach to the request such as an r value for the request, HTTP headers, and other query parameters. See RequestMeta.readParams().
Returns:
A streaming FetchResponse containing HTTP response information and the response stream. The HTTP connection must be closed manually by the user by calling HttpResponseDecorator.close().

stream

public FetchResponse stream(String bucket,
                            String key)

stream

public boolean stream(String bucket,
                      String key,
                      StreamHandler handler,
                      RequestMeta meta)
               throws IOException
Throws:
IOException

delete

public HttpResponse delete(String bucket,
                           String key,
                           RequestMeta meta)

delete

public HttpResponse delete(String bucket,
                           String key)

walk

public WalkResponse walk(String bucket,
                         String key,
                         String walkSpec,
                         RequestMeta meta)

walk

public WalkResponse walk(String bucket,
                         String key,
                         String walkSpec)

walk

public WalkResponse walk(String bucket,
                         String key,
                         RiakWalkSpec walkSpec)

mapReduce

public MapReduceResponse mapReduce(String job,
                                   RequestMeta meta)

mapReduce

public MapReduceResponse mapReduce(String job)

mapReduceOverBucket

public MapReduceBuilder mapReduceOverBucket(String bucket)

mapReduceOverObjects

public MapReduceBuilder mapReduceOverObjects(Map<String,Set<String>> objects)
Same as mapReduceOverBucket(String), except over a set of objects instead of a bucket.

Parameters:
objects - A set of objects represented as a map of { bucket : [ list of keys in bucket ] }
Returns:
A MapReduceBuilder to build the map reduce job

mapReduceOverSearch

public MapReduceBuilder mapReduceOverSearch(String bucket,
                                            String search)
Same as mapReduceOverBucket(String), except over a riak-search query instead of a bucket.

Parameters:
bucket - The bucket to perform the riak-search over
search - The query that riak-search will execute
Returns:
A MapReduceBuilder to build the map reduce job

getExceptionHandler

public RiakExceptionHandler getExceptionHandler()

setExceptionHandler

public void setExceptionHandler(RiakExceptionHandler exceptionHandler)

getHttpClient

public org.apache.http.client.HttpClient getHttpClient()

getClientId

public byte[] getClientId()

setClientId

public void setClientId(String clientId)

listBuckets

public ListBucketsResponse listBuckets()
Fetch a list of all the buckets in Riak

Returns:
a ListBucketsResponse
Throws:
IOException
JSONException

ping

public HttpResponse ping()
GET Riak's ping resource.

Returns:
an HttpResponse with the result of GET

stats

public HttpResponse stats()
GET Riak's /stats (status) resource.

Returns:
an HttpResponse with the result of GET

index

public IndexResponse index(String bucket,
                           String indexName,
                           String value)
Fetch the keys for index with value

Parameters:
bucket - the bucket
indexName - the name of the index (e.g. 'user_bin')
value - the value of the index
Returns:
an IndexResponse

index

public IndexResponse index(String bucket,
                           String indexName,
                           int value)
Fetch the keys for index with value

Parameters:
bucket - the bucket
indexName - index name (e.g. 'age_int')
value - an int for the index value
Returns:
IndexResponse

index

public IndexResponse index(String bucket,
                           String indexName,
                           String start,
                           String end)
A range index query matching a binary index from start to end

Parameters:
bucket - the bucket
indexName - the index (e.g. 'username_bin')
start - the start value in a range (e.g 'a')
end - the end value in a range (e.g. 'z')
Returns:
an IndexResponse

index

public IndexResponse index(String bucket,
                           String indexName,
                           int start,
                           int end)
A range index query matching a int index from start to end

Parameters:
bucket - the bucket
indexName - the index (e.g. 'age_int')
start - the start value in a range (e.g 16)
end - the end value in a range (e.g. 32)
Returns:
an IndexResponse

shutdown

public void shutdown()


Copyright © 2012. All Rights Reserved.