com.basho.riak.client
Class DefaultRiakClient

java.lang.Object
  extended by com.basho.riak.client.DefaultRiakClient
All Implemented Interfaces:
IRiakClient

public final class DefaultRiakClient
extends Object
implements IRiakClient

The default implementation of IRiakClient. Provides convenient, transport agnostic ways to perform bucket and query operations on Riak.

This class is a wrapper around a RawClient of your choice. The RawClient wrapped is passed to all RiakOperations created by this class, so it really needs to be Thread Safe and reusable.
This class provides a Retrier to each RiakOperation it creates. If you provide one please make sure it is Thread safe and reusable.
If you do not provide a Retrier a DefaultRetrier configured for 3 attempts is created.

Author:
russell
See Also:
RawClient, PBClientAdapter, HTTPClientAdapter, DefaultRetrier

Method Summary
 WriteBucket createBucket(String bucketName)
          Create a new WriteBucket operation to create a Bucket named for the passed String.
 FetchBucket fetchBucket(String bucketName)
          Create a new FetchBucket operation, and return it.
 byte[] generateAndSetClientId()
          Generate, set and return "random" byte[4] id for the client.
 byte[] getClientId()
          Retrieve the client id from Riak that this client is using.
 Transport getTransport()
          Optional method, the underlying transport.
 Set<String> listBuckets()
          Set view of buckets in Riak
 BucketKeyMapReduce mapReduce()
          Create MapReduce operation for a set of bucket/key inputs.
 IndexMapReduce mapReduce(IndexQuery query)
          Create a MapReduce operation that uses the supplied IndexQuery as input
 BucketMapReduce mapReduce(String bucket)
          Create MapReduce operation that has the supplied bucket as its input.
 SearchMapReduce mapReduce(String bucket, String query)
          Create a MapReduce operation that uses the supplied Riak Search query as input.
 void ping()
          Ping Riak, check it is available
 IRiakClient setClientId(byte[] clientId)
          Set an ID for this client.
 void shutdown()
           
 Iterable<NodeStats> stats()
          Perform the Riak /stats operation on the node(s) this client is connected to.
 WriteBucket updateBucket(Bucket b)
          Create a new WriteBucket operation to update passed bucket.
 LinkWalk walk(IRiakObject startObject)
          Create a LinkWalk operation that starts at startObject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

listBuckets

public Set<String> listBuckets()
                        throws RiakException
Description copied from interface: IRiakClient
Set view of buckets in Riak

Specified by:
listBuckets in interface IRiakClient
Returns:
a Set of buckets (or empty)
Throws:
RiakException

updateBucket

public WriteBucket updateBucket(Bucket b)
Description copied from interface: IRiakClient
Create a new WriteBucket operation to update passed bucket.

Specified by:
updateBucket in interface IRiakClient
Parameters:
b - the name of the Bucket.
Returns:
a WriteBucket configured to update the supplied bucket for further configuration and execution.
See Also:
WriteBucket

fetchBucket

public FetchBucket fetchBucket(String bucketName)
Description copied from interface: IRiakClient
Create a new FetchBucket operation, and return it.

Specified by:
fetchBucket in interface IRiakClient
Returns:
a FetchBucket configured to return the Bucket called bucketName for further configuration and execution.
See Also:
FetchBucket

createBucket

public WriteBucket createBucket(String bucketName)
Description copied from interface: IRiakClient
Create a new WriteBucket operation to create a Bucket named for the passed String.

Specified by:
createBucket in interface IRiakClient
Parameters:
bucketName - the name of the new bucket.
Returns:
a WriteBucket configured to create the new bucket for further configuration and execution.
See Also:
WriteBucket

setClientId

public IRiakClient setClientId(byte[] clientId)
                        throws RiakException
Description copied from interface: IRiakClient
Set an ID for this client. All requests should include a client id, which can be any 4 bytes that uniquely identify the client, for purposes of tracing object modifications in the vclock. Note: this is 2 calls to Riak.

Specified by:
setClientId in interface IRiakClient
Parameters:
clientId - byte[4] that uniquely identify the client
Returns:
this
Throws:
RiakException - if operation fails

generateAndSetClientId

public byte[] generateAndSetClientId()
                              throws RiakException
Description copied from interface: IRiakClient
Generate, set and return "random" byte[4] id for the client. Note: this is a call to Riak.

Specified by:
generateAndSetClientId in interface IRiakClient
Returns:
a byte[4] id for this client.
Throws:
RiakException
See Also:
ClientId

getClientId

public byte[] getClientId()
                   throws RiakException
Description copied from interface: IRiakClient
Retrieve the client id from Riak that this client is using. Note: this is a call to Riak.

Specified by:
getClientId in interface IRiakClient
Returns:
a byte[4] that Riak uses to identify this client.
Throws:
RiakException

mapReduce

public BucketKeyMapReduce mapReduce()
Description copied from interface: IRiakClient
Create MapReduce operation for a set of bucket/key inputs. See also Map Reduce on the basho site.

Specified by:
mapReduce in interface IRiakClient
Returns:
a BucketKeyMapReduce for configuration and execution.
See Also:
MapReduce, BucketKeyMapReduce

mapReduce

public BucketMapReduce mapReduce(String bucket)
Description copied from interface: IRiakClient
Create MapReduce operation that has the supplied bucket as its input.

Specified by:
mapReduce in interface IRiakClient
Parameters:
bucket - the String name of the input bucket to the M/R job.
Returns:
a BucketMapReduce for further configuration and execution.
See Also:
MapReduce, BucketMapReduce

mapReduce

public SearchMapReduce mapReduce(String bucket,
                                 String query)
Description copied from interface: IRiakClient
Create a MapReduce operation that uses the supplied Riak Search query as input. See also Riak Search on the basho wiki for more information.

Specified by:
mapReduce in interface IRiakClient
Parameters:
bucket - the input bucket for the search query
query - the input query for the search
Returns:
a SearchMapReduce operation for further configuration and execution.

mapReduce

public IndexMapReduce mapReduce(IndexQuery query)
Description copied from interface: IRiakClient
Create a MapReduce operation that uses the supplied IndexQuery as input

Note: if you just want to fetch an index see Bucket.fetchIndex(com.basho.riak.client.query.indexes.RiakIndex) to create a FetchIndex operation

Specified by:
mapReduce in interface IRiakClient
Parameters:
query - the IndexQuery to use as input
Returns:
a MapReduce operation for further configuration and execution

walk

public LinkWalk walk(IRiakObject startObject)
Description copied from interface: IRiakClient
Create a LinkWalk operation that starts at startObject. See also Link Walking on the basho site.

Specified by:
walk in interface IRiakClient
Parameters:
startObject - the IRiakObject to start the Link walk from.
Returns:
a LinkWalk operation for further configuration and execution.
See Also:
LinkWalk

ping

public void ping()
          throws RiakException
Description copied from interface: IRiakClient
Ping Riak, check it is available

Specified by:
ping in interface IRiakClient
Throws:
RiakException - if Riak does not respond OK

getTransport

public Transport getTransport()
Description copied from interface: IRiakClient
Optional method, the underlying transport.

Specified by:
getTransport in interface IRiakClient
Returns:
a Transport or null if not implemented.

shutdown

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

stats

public Iterable<NodeStats> stats()
                          throws RiakException
Description copied from interface: IRiakClient
Perform the Riak /stats operation on the node(s) this client is connected to.

This is not supported by the Riak Protobuf API

Specified by:
stats in interface IRiakClient
Returns:
an Iterable object that contains one or more NodeStats
Throws:
RiakException - If Riak does not respond or if the protobuf API is being used


Copyright © 2012. All Rights Reserved.