public final class DefaultRiakClient extends Object implements IRiakClient
This class is a wrapper around a RawClient
of your choice. The RawClient
wrapped is passed to all
RiakOperation
s 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.
RawClient
,
PBClientAdapter
,
HTTPClientAdapter
,
DefaultRetrier
Modifier and Type | Method and Description |
---|---|
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
|
StreamingOperation<String> |
listBucketsStreaming()
Iterate over the bucket names 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
|
void |
resetBucket(String bucketName)
(non-Javadoc)
|
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. |
public Set<String> listBuckets() throws RiakException
IRiakClient
listBuckets
in interface IRiakClient
RiakException
public StreamingOperation<String> listBucketsStreaming() throws RiakException
IRiakClient
StreamingOperation.cancel()
on the returned
StreamingOperation
if you do not iterate through the entire set.
As a safeguard the stream is closed automatically when the iterator is
weakly reachable but due to the nature of the GC it is inadvisable to
rely on this to close the iterator. Do not retain a reference to this Iterable
after you have used it.listBucketsStreaming
in interface IRiakClient
RiakException
RawClient.listBucketsStreaming()
public WriteBucket updateBucket(Bucket b)
IRiakClient
WriteBucket
operation to update passed bucket.updateBucket
in interface IRiakClient
b
- the name of the Bucket
.WriteBucket
configured to update the supplied bucket
for further configuration and execution.WriteBucket
public FetchBucket fetchBucket(String bucketName)
IRiakClient
FetchBucket
operation, and return it.fetchBucket
in interface IRiakClient
FetchBucket
configured to return the Bucket
called bucketName
for further configuration and execution.FetchBucket
public WriteBucket createBucket(String bucketName)
IRiakClient
WriteBucket
operation
to create a Bucket
named for the passed String.createBucket
in interface IRiakClient
bucketName
- the name of the new bucket.WriteBucket
configured to create the new bucket
for further configuration and execution.WriteBucket
public void resetBucket(String bucketName) throws RiakException
resetBucket
in interface IRiakClient
RiakException
RawClient.resetBucketProperties(java.lang.String)
public IRiakClient setClientId(byte[] clientId) throws RiakException
IRiakClient
setClientId
in interface IRiakClient
clientId
- byte[4] that uniquely identify the clientRiakException
- if operation failspublic byte[] generateAndSetClientId() throws RiakException
IRiakClient
generateAndSetClientId
in interface IRiakClient
RiakException
ClientId
public byte[] getClientId() throws RiakException
IRiakClient
getClientId
in interface IRiakClient
RiakException
public BucketKeyMapReduce mapReduce()
IRiakClient
MapReduce
operation for a set of
bucket/key inputs.
See also Map Reduce on the basho site.mapReduce
in interface IRiakClient
BucketKeyMapReduce
for configuration and execution.MapReduce
,
BucketKeyMapReduce
public BucketMapReduce mapReduce(String bucket)
IRiakClient
MapReduce
operation that has the supplied bucket as its input.mapReduce
in interface IRiakClient
bucket
- the String name of the input bucket to the M/R job.BucketMapReduce
for further configuration and execution.MapReduce
,
BucketMapReduce
public SearchMapReduce mapReduce(String bucket, String query)
IRiakClient
MapReduce
operation that uses the supplied Riak Search
query as input.
See also
Riak Search on the basho wiki for more information.mapReduce
in interface IRiakClient
bucket
- the input bucket for the search queryquery
- the input query for the searchSearchMapReduce
operation for further configuration and
execution.public IndexMapReduce mapReduce(IndexQuery query)
IRiakClient
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
mapReduce
in interface IRiakClient
query
- the IndexQuery
to use as inputMapReduce
operation for further configuration and
executionpublic LinkWalk walk(IRiakObject startObject)
IRiakClient
LinkWalk
operation that starts at startObject.
See also Link Walking on the basho site.walk
in interface IRiakClient
startObject
- the IRiakObject to start the Link walk from.LinkWalk
operation for further configuration and execution.LinkWalk
public void ping() throws RiakException
IRiakClient
ping
in interface IRiakClient
RiakException
- if Riak does not respond OKpublic Transport getTransport()
IRiakClient
getTransport
in interface IRiakClient
Transport
or null if not implemented.public void shutdown()
shutdown
in interface IRiakClient
public Iterable<NodeStats> stats() throws RiakException
IRiakClient
/stats
operation on the node(s) this client
is connected to.
This is not supported by the Riak Protobuf API
stats
in interface IRiakClient
Iterable
object that contains one or more NodeStats
RiakException
- If Riak does not respond or if the protobuf API is being usedCopyright © 2014. All Rights Reserved.