com.basho.riak.client.raw.pbc
Class PBClientAdapter

java.lang.Object
  extended by com.basho.riak.client.raw.pbc.PBClientAdapter
All Implemented Interfaces:
RawClient

public class PBClientAdapter
extends Object
implements RawClient

Wraps the pbc.RiakClient and adapts it to the RawClient interface.

Author:
russell

Constructor Summary
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)
 
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
 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
 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
 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PBClientAdapter

public PBClientAdapter(String host,
                       int port)
                throws IOException
Create an instance of the adapter that creates a RiakClient using RiakClient.RiakClient(String, int)

Parameters:
host - the address of the Riak pb interface
port - the port number of the Riak pb interface
Throws:
IOException

PBClientAdapter

public PBClientAdapter(RiakClient delegate)
Adapt the given pre-created/configured pb client to the RawClient interface

Parameters:
delegate - the RiakClient to adapt.
Method Detail

head

public RiakResponse head(String bucket,
                         String key,
                         FetchMeta fm)
                  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
fm - 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 riakObject,
                          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:
riakObject - 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

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.

Specified by:
linkWalk in interface RawClient
Parameters:
linkWalkSpec - the LinkWalkSpec to execute.
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

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

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

getTransport

public Transport getTransport()
Description copied from interface: RawClient
The raw transport name.

Specified by:
getTransport in interface RawClient
Returns:
the Transport for the client or null if not implemented.

shutdown

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

stats

public NodeStats stats()
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.


Copyright © 2012. All Rights Reserved.