com.basho.riak.client.raw
Class ClusterClient<T extends Configuration>

java.lang.Object
  extended by com.basho.riak.client.raw.ClusterClient<T>
All Implemented Interfaces:
RawClient
Direct Known Subclasses:
HTTPClusterClient, PBClusterClient

public abstract class ClusterClient<T extends Configuration>
extends Object
implements RawClient

A RawClient that can be configured with a cluster of Riak clients that connect to different Riak nodes. It uses a very basic modulus round robin algorithm to select the client to use.

Author:
russell

Constructor Summary
ClusterClient(ClusterConfig<T> clusterConfig)
           
 
Method Summary
 void delete(String bucket, String key)
          Delete the data at bucket/key
 void delete(String bucket, String key, DeleteMeta deleteMeta)
          Delete the data at bucket/key using the parameters in deleteMeta
 void delete(String bucket, String key, int deleteQuorum)
          Delete the data at bucket/key using deleteQuorum as the rw param
 RiakResponse fetch(String bucket, String key)
          Fetch data from bucket/key
 RiakResponse fetch(String bucket, String key, FetchMeta fetchMeta)
          Fetch data from the given bucket/key with fetchMeta
 RiakResponse fetch(String bucket, String key, int readQuorum)
          Fetch data from the given bukcet/key with read quorum readQuorum
 BucketProperties fetchBucket(String bucketName)
          The set of properties for the given bucket
 List<String> fetchIndex(IndexQuery indexQuery)
          Performs an 2i index query
protected abstract  RawClient[] fromConfig(ClusterConfig<T> clusterConfig)
          Create an array of clients for the cluster from the given ClusterConfig.
 byte[] generateAndSetClientId()
          If you don't set a client id explicitly at least call this to set one.
 byte[] getClientId()
          Ask Riak for the client id for the current connection.
 RiakResponse head(String bucket, String key, FetchMeta fetchMeta)
          Fetch only the meta-data from bucket/key
 WalkResult linkWalk(LinkWalkSpec linkWalkSpec)
          Performs a link walk operation described by the LinkWalkSpec provided.
 Set<String> listBuckets()
          An Unmodifiable Iterator view of the all the Buckets in Riak
 Iterable<String> listKeys(String bucketName)
          An unmodifiable Iterator view of the keys for the bucket named bucketName May be backed by a stream or a collection.
 MapReduceResult mapReduce(MapReduceSpec spec)
          Perform a map/reduce query defined by MapReduceSpec
 void ping()
          Riak connection health check, is Riak reachable.
 void setClientId(byte[] clientId)
          Set a client id, currently must be a 4 bytes exactly
 void shutdown()
           
 NodeStats stats()
          Performs a Riak /stats operation on the node(s) this client is connected to.
 void store(IRiakObject object)
          Store the given IRiakObject in Riak using the bucket default w/dw and false for returnBody
 RiakResponse store(IRiakObject object, StoreMeta storeMeta)
          Store the given IRiakObject in Riak at the location bucket/key
 void updateBucket(String name, BucketProperties bucketProperties)
          Update a buckets properties from the BucketProperties provided.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.basho.riak.client.raw.RawClient
getTransport
 

Constructor Detail

ClusterClient

public ClusterClient(ClusterConfig<T> clusterConfig)
              throws IOException
Throws:
IOException
Method Detail

fromConfig

protected abstract RawClient[] fromConfig(ClusterConfig<T> clusterConfig)
                                   throws IOException
Create an array of clients for the cluster from the given ClusterConfig.

Returns:
the array of RawClient delegates that make up the cluster
Throws:
IOException

head

public RiakResponse head(String bucket,
                         String key,
                         FetchMeta fetchMeta)
                  throws IOException
Description copied from interface: RawClient
Fetch only the meta-data from bucket/key

Specified by:
head in interface RawClient
Parameters:
bucket - the bucket
key - the key
fetchMeta - the fetch options
Returns:
a RiakResponse that, if it has an IRiakObject it will have an empty value
Throws:
IOException

fetch

public RiakResponse fetch(String bucket,
                          String key)
                   throws IOException
Description copied from interface: RawClient
Fetch data from bucket/key

Specified by:
fetch in interface RawClient
Parameters:
bucket - the bucket
key - the key
Returns:
a RiakResponse
Throws:
IOException

fetch

public RiakResponse fetch(String bucket,
                          String key,
                          int readQuorum)
                   throws IOException
Description copied from interface: RawClient
Fetch data from the given bukcet/key with read quorum readQuorum

Specified by:
fetch in interface RawClient
Parameters:
bucket - the bucket
key - the key
readQuorum - readQuorum, needs to be =< the buckets n_val
Returns:
a RiakResponse
Throws:
IOException

fetch

public RiakResponse fetch(String bucket,
                          String key,
                          FetchMeta fetchMeta)
                   throws IOException
Description copied from interface: RawClient
Fetch data from the given bucket/key with fetchMeta

Specified by:
fetch in interface RawClient
Parameters:
bucket - the bucket
key - the key
fetchMeta - the extra fetch parameters FetchMeta
Returns:
a RiakResponse
Throws:
IOException

store

public RiakResponse store(IRiakObject object,
                          StoreMeta storeMeta)
                   throws IOException
Description copied from interface: RawClient
Store the given IRiakObject in Riak at the location bucket/key

Specified by:
store in interface RawClient
Parameters:
object - the data to store
storeMeta - meta data for the store operation as a StoreMeta
Returns:
a RiakResponse if StoreMeta.getReturnBody() is true, or null
Throws:
IOException

store

public void store(IRiakObject object)
           throws IOException
Description copied from interface: RawClient
Store the given IRiakObject in Riak using the bucket default w/dw and false for returnBody

Specified by:
store in interface RawClient
Parameters:
object - the data to store as an IRiakObject
Throws:
IOException

delete

public void delete(String bucket,
                   String key)
            throws IOException
Description copied from interface: RawClient
Delete the data at bucket/key

Specified by:
delete in interface RawClient
Throws:
IOException

delete

public void delete(String bucket,
                   String key,
                   int deleteQuorum)
            throws IOException
Description copied from interface: RawClient
Delete the data at bucket/key using deleteQuorum as the rw param

Specified by:
delete in interface RawClient
deleteQuorum - an int that is less than or equal to the bucket's n_val
Throws:
IOException

delete

public void delete(String bucket,
                   String key,
                   DeleteMeta deleteMeta)
            throws IOException
Description copied from interface: RawClient
Delete the data at bucket/key using the parameters in deleteMeta

Specified by:
delete in interface RawClient
deleteMeta - the DeleteMeta containing the operation parameters
Throws:
IOException

listBuckets

public Set<String> listBuckets()
                        throws IOException
Description copied from interface: RawClient
An Unmodifiable Iterator view of the all the Buckets in Riak

Specified by:
listBuckets in interface RawClient
Throws:
IOException

fetchBucket

public BucketProperties fetchBucket(String bucketName)
                             throws IOException
Description copied from interface: RawClient
The set of properties for the given bucket

Specified by:
fetchBucket in interface RawClient
Parameters:
bucketName - the name of the bucket
Returns:
a populated BucketProperties (by populated, as populated as the underlying API allows)
Throws:
IOException

updateBucket

public void updateBucket(String name,
                         BucketProperties bucketProperties)
                  throws IOException
Description copied from interface: RawClient
Update a buckets properties from the BucketProperties provided. No guarantees that the underlying API is able to set all the properties passed.

Specified by:
updateBucket in interface RawClient
Parameters:
name - the bucket to be updated
bucketProperties - the set of properties to be writen
Throws:
IOException

listKeys

public Iterable<String> listKeys(String bucketName)
                          throws IOException
Description copied from interface: RawClient
An unmodifiable Iterator view of the keys for the bucket named bucketName May be backed by a stream or a collection. Be careful, expensive.

Specified by:
listKeys in interface RawClient
Returns:
an unmodifiable, iterable view of the keys for tha bucket
Throws:
IOException

linkWalk

public WalkResult linkWalk(LinkWalkSpec linkWalkSpec)
                    throws IOException
Description copied from interface: RawClient
Performs a link walk operation described by the LinkWalkSpec provided. The underlying API may not support Link Walking directly but will approximate it at some cost.

Specified by:
linkWalk in interface RawClient
Returns:
a WalkResult
Throws:
IOException

mapReduce

public MapReduceResult mapReduce(MapReduceSpec spec)
                          throws IOException,
                                 MapReduceTimeoutException
Description copied from interface: RawClient
Perform a map/reduce query defined by MapReduceSpec

Specified by:
mapReduce in interface RawClient
Parameters:
spec - the m/r job specification
Returns:
A MapReduceResult
Throws:
IOException
MapReduceTimeoutException

generateAndSetClientId

public byte[] generateAndSetClientId()
                              throws IOException
Description copied from interface: RawClient
If you don't set a client id explicitly at least call this to set one. It generates the 4 byte ID and sets that Id on the client IE you *don't* need to call setClientId() with the result of generate.

Specified by:
generateAndSetClientId in interface RawClient
Returns:
the generated clientId for the client
Throws:
IOException

setClientId

public void setClientId(byte[] clientId)
                 throws IOException
Description copied from interface: RawClient
Set a client id, currently must be a 4 bytes exactly

Specified by:
setClientId in interface RawClient
Parameters:
clientId - any 4 bytes
Throws:
IOException

getClientId

public byte[] getClientId()
                   throws IOException
Description copied from interface: RawClient
Ask Riak for the client id for the current connection.

Specified by:
getClientId in interface RawClient
Returns:
whatever 4 bytes Riak uses to identify this client
Throws:
IOException

ping

public void ping()
          throws IOException
Description copied from interface: RawClient
Riak connection health check, is Riak reachable. Can be used for diagnostics/monitoring

Specified by:
ping in interface RawClient
Throws:
IOException - if Riak is not reachable or returns anything other than OK

fetchIndex

public List<String> fetchIndex(IndexQuery indexQuery)
                        throws IOException
Description copied from interface: RawClient
Performs an 2i index query

Specified by:
fetchIndex in interface RawClient
Parameters:
indexQuery - the query to perform
Returns:
a List of keys (or empty list)
Throws:
IOException

shutdown

public void shutdown()
Specified by:
shutdown in interface RawClient

stats

public NodeStats stats()
                throws IOException
Description copied from interface: RawClient
Performs a Riak /stats operation on the node(s) this client is connected to. The NodeStats object that is returned contains one or more sets of stats and can be Iterated over.

Specified by:
stats in interface RawClient
Returns:
a NodeStats object that represents one or more sets of stats.
Throws:
IOException


Copyright © 2012. All Rights Reserved.