public class PBClientAdapter extends Object implements RawClient
RiakClient
and adapts it to the RawClient
interface.Constructor and Description |
---|
PBClientAdapter(RiakClient delegate)
Adapt the given pre-created/configured pb client to the
RawClient
interface |
PBClientAdapter(String host,
int port)
Create an instance of the adapter that creates a
RiakClient using
RiakClient.RiakClient(String, int) |
Modifier and Type | Method and Description |
---|---|
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
|
Long |
fetchCounter(String Bucket,
String counter,
FetchMeta meta)
Fetch the value for this counter
|
List<String> |
fetchIndex(IndexQuery indexQuery)
Performs an 2i index query
|
PBStreamingIndex |
fetchIndex(IndexSpec indexSpec)
Performs a 2i query as a streaming operation
|
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.
|
Transport |
getTransport()
The raw transport name.
|
RiakResponse |
head(String bucket,
String key,
FetchMeta fm)
Fetch only the meta-data from
bucket/key |
Long |
incrementCounter(String bucket,
String counter,
long increment,
StoreMeta meta)
Increments a counter by the specified increment
|
WalkResult |
linkWalk(LinkWalkSpec linkWalkSpec)
This is a bit of a hack.
|
Set<String> |
listBuckets()
An Unmodifiable
Iterator view of the all the Buckets in Riak |
StreamingOperation<String> |
listBucketsStreaming()
Iterate over the bucket names in Riak.
|
StreamingOperation<String> |
listKeys(String bucketName)
An unmodifiable view of the keys for the bucket named
bucketName
* You *must* call StreamingOperation.cancel() on the returned
StreamingOperation if you do not iterate through the entire set. |
MapReduceResult |
mapReduce(MapReduceSpec spec)
Perform a map/reduce query defined by
MapReduceSpec |
void |
ping()
Riak connection health check, is Riak reachable.
|
void |
resetBucketProperties(String bucket)
Reset the bucket properties for this bucket back to the default values
|
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 riakObject,
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. |
public PBClientAdapter(String host, int port) throws IOException
RiakClient
using
RiakClient.RiakClient(String, int)
host
- the address of the Riak pb interfaceport
- the port number of the Riak pb interfaceIOException
public PBClientAdapter(RiakClient delegate)
RawClient
interfacedelegate
- the RiakClient
to adapt.public RiakResponse head(String bucket, String key, FetchMeta fm) throws IOException
RawClient
bucket/key
head
in interface RawClient
bucket
- the bucketkey
- the keyfm
- the fetch optionsRiakResponse
that, if it has an IRiakObject
it
will have an empty valueIOException
public RiakResponse fetch(String bucket, String key) throws IOException
RawClient
bucket/key
fetch
in interface RawClient
bucket
- the bucketkey
- the keyRiakResponse
IOException
public RiakResponse fetch(String bucket, String key, int readQuorum) throws IOException
RawClient
bukcet/key
with read quorum
readQuorum
fetch
in interface RawClient
bucket
- the bucketkey
- the keyreadQuorum
- readQuorum, needs to be =< the buckets n_valRiakResponse
IOException
public RiakResponse fetch(String bucket, String key, FetchMeta fetchMeta) throws IOException
RawClient
bucket/key
with
fetchMeta
fetch
in interface RawClient
bucket
- the bucketkey
- the keyfetchMeta
- the extra fetch parameters FetchMeta
RiakResponse
IOException
public RiakResponse store(IRiakObject riakObject, StoreMeta storeMeta) throws IOException
RawClient
IRiakObject
in Riak at the location
bucket/key
store
in interface RawClient
riakObject
- the data to storestoreMeta
- meta data for the store operation as a StoreMeta
RiakResponse
if StoreMeta.getReturnBody()
is
true, or nullIOException
public void store(IRiakObject object) throws IOException
RawClient
IRiakObject
in Riak using the bucket default w/dw
and false for returnBodystore
in interface RawClient
object
- the data to store as an IRiakObject
IOException
public void delete(String bucket, String key) throws IOException
RawClient
bucket/key
delete
in interface RawClient
IOException
public void delete(String bucket, String key, int deleteQuorum) throws IOException
RawClient
bucket/key
using
deleteQuorum
as the rw paramdelete
in interface RawClient
deleteQuorum
- an int that is less than or equal to the bucket's n_valIOException
public void delete(String bucket, String key, DeleteMeta deleteMeta) throws IOException
RawClient
bucket/key
using the parameters in
deleteMeta
delete
in interface RawClient
deleteMeta
- the DeleteMeta
containing the operation parametersIOException
public Set<String> listBuckets() throws IOException
RawClient
Iterator
view of the all the Buckets in RiaklistBuckets
in interface RawClient
IOException
public StreamingOperation<String> listBucketsStreaming() throws IOException
RawClient
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
after you have used it.listBucketsStreaming
in interface RawClient
IOException
public BucketProperties fetchBucket(String bucketName) throws IOException
RawClient
fetchBucket
in interface RawClient
bucketName
- the name of the bucketBucketProperties
(by populated, as populated
as the underlying API allows)IOException
public void updateBucket(String name, BucketProperties bucketProperties) throws IOException
RawClient
BucketProperties
provided.
No guarantees that the underlying API is able to set all the properties
passed.updateBucket
in interface RawClient
name
- the bucket to be updatedbucketProperties
- the set of properties to be writenIOException
public void resetBucketProperties(String bucket) throws IOException
RawClient
resetBucketProperties
in interface RawClient
IOException
public StreamingOperation<String> listKeys(String bucketName) throws IOException
RawClient
bucketName
* You *must* call 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
after you have used it.
Be careful, expensive.listKeys
in interface RawClient
IOException
public WalkResult linkWalk(LinkWalkSpec linkWalkSpec) throws IOException
This is a bit of a hack. The pb interface doesn't really have a Link Walker like the REST interface does. This method runs (maximum) 2 map reduce requests to get the same results the link walk would for the given spec.
The first m/r job gets the end of the link walk and the inputs for second m/r job. The second job gets all those inputs values. Then some client side massaging occurs to massage the result into the correct format.
linkWalk
in interface RawClient
linkWalkSpec
- the LinkWalkSpec
to execute.WalkResult
IOException
public MapReduceResult mapReduce(MapReduceSpec spec) throws IOException, MapReduceTimeoutException
RawClient
MapReduceSpec
mapReduce
in interface RawClient
spec
- the m/r job specificationMapReduceResult
IOException
MapReduceTimeoutException
public List<String> fetchIndex(IndexQuery indexQuery) throws IOException
RawClient
fetchIndex
in interface RawClient
indexQuery
- the query to performIOException
public PBStreamingIndex fetchIndex(IndexSpec indexSpec) throws IOException
RawClient
fetchIndex
in interface RawClient
IOException
public Long incrementCounter(String bucket, String counter, long increment, StoreMeta meta) throws IOException
RawClient
incrementCounter
in interface RawClient
bucket
- the name of the bucketcounter
- the name (key) of the counterincrement
- the amount to increment. Note this can be a negative value.meta
- the query parametersIOException
public Long fetchCounter(String Bucket, String counter, FetchMeta meta) throws IOException
RawClient
fetchCounter
in interface RawClient
Bucket
- the name of the bucketcounter
- the name (key) of the countermeta
- query parametersIOException
public byte[] generateAndSetClientId() throws IOException
RawClient
generateAndSetClientId
in interface RawClient
IOException
public void setClientId(byte[] clientId) throws IOException
RawClient
setClientId
in interface RawClient
clientId
- any 4 bytesIOException
public byte[] getClientId() throws IOException
RawClient
getClientId
in interface RawClient
IOException
public void ping() throws IOException
RawClient
ping
in interface RawClient
IOException
- if Riak is not reachable or returns anything other than OKpublic Transport getTransport()
RawClient
getTransport
in interface RawClient
Transport
for the client or null if not implemented.Copyright © 2014. All Rights Reserved.