com.couchbase.client
Class CouchbaseClient

java.lang.Object
  extended by net.spy.memcached.compat.SpyObject
      extended by net.spy.memcached.MemcachedClient
          extended by com.couchbase.client.CouchbaseClient
All Implemented Interfaces:
CouchbaseClientIF, Reconfigurable, net.spy.memcached.ConnectionObserver, net.spy.memcached.MemcachedClientIF

public class CouchbaseClient
extends net.spy.memcached.MemcachedClient
implements CouchbaseClientIF, Reconfigurable

A client for Couchbase Server. This class acts as your main entry point while working with your Couchbase cluster (if you want to work with TAP, see the TapClient instead). If you are working with Couchbase Server 2.0, remember to set the appropriate view mode depending on your environment.


Field Summary
static java.lang.String MODE_PREFIX
           
protected  boolean reconfiguring
           
 
Fields inherited from class net.spy.memcached.MemcachedClient
authDescriptor, authMonitor, connFactory, mconn, operationTimeout, opFact, shuttingDown, tcService, transcoder
 
Fields inherited from interface net.spy.memcached.MemcachedClientIF
MAX_KEY_LENGTH
 
Constructor Summary
CouchbaseClient(CouchbaseConnectionFactory cf)
          Get a CouchbaseClient based on the settings from the given CouchbaseConnectionFactory.
CouchbaseClient(java.util.List<java.net.URI> baseList, java.lang.String bucketName, java.lang.String pwd)
          Get a CouchbaseClient based on the initial server list provided.
CouchbaseClient(java.util.List<java.net.URI> baseList, java.lang.String bucketName, java.lang.String user, java.lang.String pwd)
          Get a CouchbaseClient based on the initial server list provided.
 
Method Summary
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> add(java.lang.String key, int exp, java.lang.Object value, net.spy.memcached.PersistTo req)
          Add a value with durability options.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> add(java.lang.String key, int exp, java.lang.Object value, net.spy.memcached.PersistTo req, net.spy.memcached.ReplicateTo rep)
          Add a value with durability options.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> add(java.lang.String key, int exp, java.lang.Object value, net.spy.memcached.ReplicateTo rep)
          Add a value with durability options.
 void addOp(HttpOperation op)
          Adds an operation to the queue where it waits to be sent to Couchbase.
 HttpFuture<java.lang.Boolean> asyncCreateDesignDoc(DesignDocument doc)
          Store a design document in the cluster.
 HttpFuture<java.lang.Boolean> asyncCreateDesignDoc(java.lang.String name, java.lang.String value)
          Store a design document in the cluster.
 HttpFuture<java.lang.Boolean> asyncDeleteDesignDoc(java.lang.String name)
          Delete a design document in the cluster.
 net.spy.memcached.internal.OperationFuture<net.spy.memcached.CASValue<java.lang.Object>> asyncGetAndLock(java.lang.String key, int exp)
          Get and lock the given key asynchronously and decode with the default transcoder.
<T> net.spy.memcached.internal.OperationFuture<net.spy.memcached.CASValue<T>>
asyncGetAndLock(java.lang.String key, int exp, net.spy.memcached.transcoders.Transcoder<T> tc)
          Gets and locks the given key asynchronously.
 HttpFuture<DesignDocument> asyncGetDesignDocument(java.lang.String designDocumentName)
          Gets a future with a design document from the cluster.
 HttpFuture<SpatialView> asyncGetSpatialView(java.lang.String designDocumentName, java.lang.String viewName)
          Gets access to a spatial view contained in a design document from the cluster.
 HttpFuture<View> asyncGetView(java.lang.String designDocumentName, java.lang.String viewName)
          Gets access to a view contained in a design document from the cluster.
 HttpFuture<ViewResponse> asyncQuery(AbstractView view, Query query)
           
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> asyncUnlock(java.lang.String key, long casId)
          Unlock the given key asynchronously from the cache with the default transcoder.
<T> net.spy.memcached.internal.OperationFuture<java.lang.Boolean>
asyncUnlock(java.lang.String key, long casId, net.spy.memcached.transcoders.Transcoder<T> tc)
          Unlock the given key asynchronously from the cache.
 net.spy.memcached.CASResponse cas(java.lang.String key, long cas, java.lang.Object value, net.spy.memcached.PersistTo req)
          Set a value with a CAS and durability options.
 net.spy.memcached.CASResponse cas(java.lang.String key, long cas, java.lang.Object value, net.spy.memcached.PersistTo req, net.spy.memcached.ReplicateTo rep)
          Set a value with a CAS and durability options.
 net.spy.memcached.CASResponse cas(java.lang.String key, long cas, java.lang.Object value, net.spy.memcached.ReplicateTo rep)
          Set a value with a CAS and durability options.
 java.lang.Boolean createDesignDoc(DesignDocument doc)
          Store a design document in the cluster.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> delete(java.lang.String key, net.spy.memcached.PersistTo req)
          Delete a value with durability options for persistence.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> delete(java.lang.String key, net.spy.memcached.PersistTo req, net.spy.memcached.ReplicateTo rep)
          Delete a value with durability options.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> delete(java.lang.String key, net.spy.memcached.ReplicateTo req)
          Delete a value with durability options for replication.
 java.lang.Boolean deleteDesignDoc(java.lang.String name)
          Delete a design document in the cluster.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> flush()
          Flush all data from the bucket immediately.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> flush(int delay)
          Flush all caches from all servers with a delay of application.
 net.spy.memcached.CASValue<java.lang.Object> getAndLock(java.lang.String key, int exp)
          Get and lock with a single key and decode using the default transcoder.
<T> net.spy.memcached.CASValue<T>
getAndLock(java.lang.String key, int exp, net.spy.memcached.transcoders.Transcoder<T> tc)
          Getl with a single key.
 DesignDocument getDesignDocument(java.lang.String designDocumentName)
          Returns a representation of a design document stored in the cluster.
 net.spy.memcached.internal.OperationFuture<java.util.Map<java.lang.String,java.lang.String>> getKeyStats(java.lang.String key)
           
 int getNumVBuckets()
          Gets the number of vBuckets that are contained in the cluster.
 SpatialView getSpatialView(java.lang.String designDocumentName, java.lang.String viewName)
          Gets access to a spatial view contained in a design document from the cluster.
 View getView(java.lang.String designDocumentName, java.lang.String viewName)
          Gets access to a view contained in a design document from the cluster.
 java.util.Map<net.spy.memcached.MemcachedNode,net.spy.memcached.ObserveResponse> observe(java.lang.String key, long cas)
          Observe a key with a associated CAS.
 void observePoll(java.lang.String key, long cas, net.spy.memcached.PersistTo persist, net.spy.memcached.ReplicateTo replicate, boolean isDelete)
          Poll and observe a key with the given CAS and persist settings.
 Paginator paginatedQuery(View view, Query query, int docsPerPage)
          A paginated query allows the user to get the results of a large query in small chunks allowing for better performance.
 ViewResponse query(AbstractView view, Query query)
          Queries a Couchbase view and returns the result.
 void reconfigure(Bucket bucket)
          This method is called when there is a topology change in the cluster.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> replace(java.lang.String key, int exp, java.lang.Object value, net.spy.memcached.PersistTo req)
          Replace a value with durability options.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> replace(java.lang.String key, int exp, java.lang.Object value, net.spy.memcached.PersistTo req, net.spy.memcached.ReplicateTo rep)
          Replace a value with durability options.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> replace(java.lang.String key, int exp, java.lang.Object value, net.spy.memcached.ReplicateTo rep)
          Replace a value with durability options.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> set(java.lang.String key, int exp, java.lang.Object value, net.spy.memcached.PersistTo req)
          Set a value with durability options.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> set(java.lang.String key, int exp, java.lang.Object value, net.spy.memcached.PersistTo req, net.spy.memcached.ReplicateTo rep)
          Set a value with durability options.
 net.spy.memcached.internal.OperationFuture<java.lang.Boolean> set(java.lang.String key, int exp, java.lang.Object value, net.spy.memcached.ReplicateTo rep)
          Set a value with durability options.
 boolean shutdown(long timeout, java.util.concurrent.TimeUnit unit)
           
 java.lang.Boolean unlock(java.lang.String key, long casId)
          Unlock the given key synchronously from the cache with the default transcoder.
<T> java.lang.Boolean
unlock(java.lang.String key, long casId, net.spy.memcached.transcoders.Transcoder<T> tc)
          Unlock the given key synchronously from the cache.
 
Methods inherited from class net.spy.memcached.MemcachedClient
add, add, addObserver, append, append, asyncCAS, asyncCAS, asyncCAS, asyncDecr, asyncDecr, asyncGet, asyncGet, asyncGetAndTouch, asyncGetAndTouch, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGets, asyncGets, asyncIncr, asyncIncr, broadcastOp, broadcastOp, cas, cas, cas, connectionEstablished, connectionLost, decr, decr, decr, decr, decr, decr, delete, delete, get, get, getAndTouch, getAndTouch, getAvailableServers, getBulk, getBulk, getBulk, getBulk, getBulk, getBulk, getNodeLocator, gets, gets, getStats, getStats, getTranscoder, getUnavailableServers, getVersions, incr, incr, incr, incr, incr, incr, listSaslMechanisms, prepend, prepend, removeObserver, replace, replace, set, set, shutdown, toString, touch, touch, waitForQueues
 
Methods inherited from class net.spy.memcached.compat.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.spy.memcached.MemcachedClientIF
add, add, addObserver, append, append, asyncCAS, asyncCAS, asyncDecr, asyncDecr, asyncGet, asyncGet, asyncGetAndTouch, asyncGetAndTouch, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGets, asyncGets, asyncIncr, asyncIncr, cas, cas, decr, decr, decr, decr, decr, decr, delete, get, get, getAndTouch, getAndTouch, getAvailableServers, getBulk, getBulk, getBulk, getBulk, getBulk, getBulk, getNodeLocator, gets, gets, getStats, getStats, getTranscoder, getUnavailableServers, getVersions, incr, incr, incr, incr, incr, incr, listSaslMechanisms, prepend, prepend, removeObserver, replace, replace, set, set, shutdown, touch, touch, waitForQueues
 

Field Detail

MODE_PREFIX

public static final java.lang.String MODE_PREFIX

reconfiguring

protected volatile boolean reconfiguring
Constructor Detail

CouchbaseClient

public CouchbaseClient(java.util.List<java.net.URI> baseList,
                       java.lang.String bucketName,
                       java.lang.String pwd)
                throws java.io.IOException
Get a CouchbaseClient based on the initial server list provided. This constructor should be used if the bucket name is the same as the username (which is normally the case). If your bucket does not have a password (likely the "default" bucket), use an empty string instead. This method is only a convenience method so you don't have to create a CouchbaseConnectionFactory for yourself.

Parameters:
baseList - the URI list of one or more servers from the cluster
bucketName - the bucket name in the cluster you wish to use
pwd - the password for the bucket
Throws:
java.io.IOException - if connections could not be made
ConfigurationException - if the configuration provided by the server has issues or is not compatible

CouchbaseClient

public CouchbaseClient(java.util.List<java.net.URI> baseList,
                       java.lang.String bucketName,
                       java.lang.String user,
                       java.lang.String pwd)
                throws java.io.IOException
Get a CouchbaseClient based on the initial server list provided. Currently, Couchbase Server does not support a different username than the bucket name. Therefore, this method ignores the given username for now but will likely use it in the future. This constructor should be used if the bucket name is NOT the same as the username. If your bucket does not have a password (likely the "default" bucket), use an empty string instead. This method is only a convenience method so you don't have to create a CouchbaseConnectionFactory for yourself.

Parameters:
baseList - the URI list of one or more servers from the cluster
bucketName - the bucket name in the cluster you wish to use
user - the username for the bucket
pwd - the password for the bucket
Throws:
java.io.IOException - if connections could not be made
ConfigurationException - if the configuration provided by the server has issues or is not compatible

CouchbaseClient

public CouchbaseClient(CouchbaseConnectionFactory cf)
                throws java.io.IOException
Get a CouchbaseClient based on the settings from the given CouchbaseConnectionFactory. If your bucket does not have a password (likely the "default" bucket), use an empty string instead. The URI list provided here is only used during the initial connection to the cluster. Afterwards, the actual cluster-map is synchronized from the cluster and maintained internally by the client. This allows the client to update the map as needed (when the cluster topology changes). Note that when specifying a ConnectionFactory you must specify a BinaryConnectionFactory (which is the case if you use the CouchbaseConnectionFactory). Also the ConnectionFactory's protocol and locator values are always overwritten. The protocol will always be binary and the locator will be chosen based on the bucket type you are connecting to. The subscribe variable determines whether or not we will subscribe to the configuration changes feed. This constructor should be used when calling super from subclasses of CouchbaseClient since the subclass might want to start the changes feed later.

Parameters:
cf - the ConnectionFactory to use to create connections
Throws:
java.io.IOException - if connections could not be made
ConfigurationException - if the configuration provided by the server has issues or is not compatible
Method Detail

reconfigure

public void reconfigure(Bucket bucket)
This method is called when there is a topology change in the cluster. This method is intended for internal use only.

Specified by:
reconfigure in interface Reconfigurable
Parameters:
bucket - updated vbucket configuration

asyncGetView

public HttpFuture<View> asyncGetView(java.lang.String designDocumentName,
                                     java.lang.String viewName)
Gets access to a view contained in a design document from the cluster. The purpose of a view is take the structured data stored within the Couchbase Server database as JSON documents, extract the fields and information, and to produce an index of the selected information. The result is a view on the stored data. The view that is created during this process allows you to iterate, select and query the information in your database from the raw data objects that have been stored. Note that since an HttpFuture is returned, the caller must also check to see if the View is null. The HttpFuture does provide a getStatus() method which can be used to check whether or not the view request has been successful.

Parameters:
designDocumentName - the name of the design document.
viewName - the name of the view to get.
Returns:
a View object from the cluster.
Throws:
java.lang.InterruptedException - if the operation is interrupted while in flight
java.util.concurrent.ExecutionException - if an error occurs during execution

asyncGetSpatialView

public HttpFuture<SpatialView> asyncGetSpatialView(java.lang.String designDocumentName,
                                                   java.lang.String viewName)
Gets access to a spatial view contained in a design document from the cluster. Note that since an HttpFuture is returned, the caller must also check to see if the View is null. The HttpFuture does provide a getStatus() method which can be used to check whether or not the view request has been successful.

Parameters:
designDocumentName - the name of the design document.
viewName - the name of the spatial view to get.
Returns:
a HttpFuture object from the cluster.
Throws:
java.lang.InterruptedException - if the operation is interrupted while in flight
java.util.concurrent.ExecutionException - if an error occurs during execution

asyncGetDesignDocument

public HttpFuture<DesignDocument> asyncGetDesignDocument(java.lang.String designDocumentName)
Gets a future with a design document from the cluster. If no design document was found, the enclosed DesignDocument inside the future will be null.

Parameters:
designDocumentName - the name of the design document.
Returns:
a future containing a DesignDocument from the cluster.

getView

public View getView(java.lang.String designDocumentName,
                    java.lang.String viewName)
Gets access to a view contained in a design document from the cluster. The purpose of a view is take the structured data stored within the Couchbase Server database as JSON documents, extract the fields and information, and to produce an index of the selected information. The result is a view on the stored data. The view that is created during this process allows you to iterate, select and query the information in your database from the raw data objects that have been stored.

Parameters:
designDocumentName - the name of the design document.
viewName - the name of the view to get.
Returns:
a View object from the cluster.
Throws:
InvalidViewException - if no design document or view was found.
java.util.concurrent.CancellationException - if operation was canceled.

getSpatialView

public SpatialView getSpatialView(java.lang.String designDocumentName,
                                  java.lang.String viewName)
Gets access to a spatial view contained in a design document from the cluster. Spatial views enable you to return recorded geometry data in the bucket and perform queries which return information based on whether the recorded geometries existing within a given two-dimensional range such as a bounding box.

Parameters:
designDocumentName - the name of the design document.
viewName - the name of the view to get.
Returns:
a SpatialView object from the cluster.
Throws:
InvalidViewException - if no design document or view was found.
java.util.concurrent.CancellationException - if operation was canceled.

getDesignDocument

public DesignDocument getDesignDocument(java.lang.String designDocumentName)
Returns a representation of a design document stored in the cluster.

Parameters:
designDocumentName - the name of the design document.
Returns:
a DesignDocument object from the cluster.
Throws:
InvalidViewException - if no design document or view was found.
java.util.concurrent.CancellationException - if operation was canceled.

createDesignDoc

public java.lang.Boolean createDesignDoc(DesignDocument doc)
Store a design document in the cluster.

Parameters:
doc - the design document to store.
Returns:
the result of the creation operation.
Throws:
java.util.concurrent.CancellationException - if operation was canceled.

asyncCreateDesignDoc

public HttpFuture<java.lang.Boolean> asyncCreateDesignDoc(java.lang.String name,
                                                          java.lang.String value)
                                                   throws java.io.UnsupportedEncodingException
Store a design document in the cluster.

Parameters:
name - the name of the design document.
value - the full design document definition as a string.
Returns:
a future containing the result of the creation operation.
Throws:
java.io.UnsupportedEncodingException

asyncCreateDesignDoc

public HttpFuture<java.lang.Boolean> asyncCreateDesignDoc(DesignDocument doc)
                                                   throws java.io.UnsupportedEncodingException
Store a design document in the cluster.

Parameters:
doc - the design document to store.
Returns:
a future containing the result of the creation operation.
Throws:
java.io.UnsupportedEncodingException

deleteDesignDoc

public java.lang.Boolean deleteDesignDoc(java.lang.String name)
Delete a design document in the cluster.

Parameters:
name - the design document to delete.
Returns:
the result of the deletion operation.
Throws:
java.util.concurrent.CancellationException - if operation was canceled.

asyncDeleteDesignDoc

public HttpFuture<java.lang.Boolean> asyncDeleteDesignDoc(java.lang.String name)
                                                   throws java.io.UnsupportedEncodingException
Delete a design document in the cluster.

Parameters:
name - the design document to delete.
Returns:
a future containing the result of the deletion operation.
Throws:
java.io.UnsupportedEncodingException

asyncQuery

public HttpFuture<ViewResponse> asyncQuery(AbstractView view,
                                           Query query)

query

public ViewResponse query(AbstractView view,
                          Query query)
Queries a Couchbase view and returns the result. The result can be accessed row-wise via an iterator. This type of query will return the view result along with all of the documents for each row in the query.

Parameters:
view - the view to run the query against.
query - the type of query to run against the view.
Returns:
a ViewResponseWithDocs containing the results of the query.
Throws:
java.util.concurrent.CancellationException - if operation was canceled.

paginatedQuery

public Paginator paginatedQuery(View view,
                                Query query,
                                int docsPerPage)
A paginated query allows the user to get the results of a large query in small chunks allowing for better performance. The result allows you to iterate through the results of the query and when you get to the end of the current result set the client will automatically fetch the next set of results.

Parameters:
view - the view to query against.
query - the query for this request.
docsPerPage - the amount of documents per page.
Returns:
A Paginator (iterator) to use for reading the results of the query.

addOp

public void addOp(HttpOperation op)
Adds an operation to the queue where it waits to be sent to Couchbase. This function is for internal use only.


asyncGetAndLock

public <T> net.spy.memcached.internal.OperationFuture<net.spy.memcached.CASValue<T>> asyncGetAndLock(java.lang.String key,
                                                                                                     int exp,
                                                                                                     net.spy.memcached.transcoders.Transcoder<T> tc)
Gets and locks the given key asynchronously. By default the maximum allowed timeout is 30 seconds. Timeouts greater than this will be set to 30 seconds.

Specified by:
asyncGetAndLock in interface CouchbaseClientIF
Parameters:
key - the key to fetch and lock
exp - the amount of time the lock should be valid for in seconds.
tc - the transcoder to serialize and unserialize value
Returns:
a future that will hold the return value of the fetch
Throws:
java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests

asyncGetAndLock

public net.spy.memcached.internal.OperationFuture<net.spy.memcached.CASValue<java.lang.Object>> asyncGetAndLock(java.lang.String key,
                                                                                                                int exp)
Get and lock the given key asynchronously and decode with the default transcoder. By default the maximum allowed timeout is 30 seconds. Timeouts greater than this will be set to 30 seconds.

Specified by:
asyncGetAndLock in interface CouchbaseClientIF
Parameters:
key - the key to fetch and lock
exp - the amount of time the lock should be valid for in seconds.
Returns:
a future that will hold the return value of the fetch
Throws:
java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests

getAndLock

public <T> net.spy.memcached.CASValue<T> getAndLock(java.lang.String key,
                                                    int exp,
                                                    net.spy.memcached.transcoders.Transcoder<T> tc)
Getl with a single key. By default the maximum allowed timeout is 30 seconds. Timeouts greater than this will be set to 30 seconds.

Specified by:
getAndLock in interface CouchbaseClientIF
Parameters:
key - the key to get and lock
exp - the amount of time the lock should be valid for in seconds.
tc - the transcoder to serialize and unserialize value
Returns:
the result from the cache (null if there is none)
Throws:
net.spy.memcached.OperationTimeoutException - if the global operation timeout is exceeded
java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
java.util.concurrent.CancellationException - if operation was canceled

getAndLock

public net.spy.memcached.CASValue<java.lang.Object> getAndLock(java.lang.String key,
                                                               int exp)
Get and lock with a single key and decode using the default transcoder. By default the maximum allowed timeout is 30 seconds. Timeouts greater than this will be set to 30 seconds.

Specified by:
getAndLock in interface CouchbaseClientIF
Parameters:
key - the key to get and lock
exp - the amount of time the lock should be valid for in seconds.
Returns:
the result from the cache (null if there is none)
Throws:
net.spy.memcached.OperationTimeoutException - if the global operation timeout is exceeded
java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests

asyncUnlock

public <T> net.spy.memcached.internal.OperationFuture<java.lang.Boolean> asyncUnlock(java.lang.String key,
                                                                                     long casId,
                                                                                     net.spy.memcached.transcoders.Transcoder<T> tc)
Unlock the given key asynchronously from the cache.

Specified by:
asyncUnlock in interface CouchbaseClientIF
Parameters:
key - the key to unlock
casId - the CAS identifier
tc - the transcoder to serialize and unserialize value
Returns:
whether or not the operation was performed
Throws:
java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests

asyncUnlock

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> asyncUnlock(java.lang.String key,
                                                                                 long casId)
Unlock the given key asynchronously from the cache with the default transcoder.

Specified by:
asyncUnlock in interface CouchbaseClientIF
Parameters:
key - the key to unlock
casId - the CAS identifier
Returns:
whether or not the operation was performed
Throws:
java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests

unlock

public <T> java.lang.Boolean unlock(java.lang.String key,
                                    long casId,
                                    net.spy.memcached.transcoders.Transcoder<T> tc)
Unlock the given key synchronously from the cache.

Specified by:
unlock in interface CouchbaseClientIF
Parameters:
key - the key to unlock
casId - the CAS identifier
tc - the transcoder to serialize and unserialize value
Returns:
whether or not the operation was performed
Throws:
java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
java.util.concurrent.CancellationException - if operation was canceled

unlock

public java.lang.Boolean unlock(java.lang.String key,
                                long casId)
Unlock the given key synchronously from the cache with the default transcoder.

Specified by:
unlock in interface CouchbaseClientIF
Parameters:
key - the key to unlock
casId - the CAS identifier
Returns:
whether or not the operation was performed
Throws:
java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests

delete

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> delete(java.lang.String key,
                                                                            net.spy.memcached.PersistTo req,
                                                                            net.spy.memcached.ReplicateTo rep)
Delete a value with durability options. The durability options here operate similarly to those documented in the set method.

Specified by:
delete in interface CouchbaseClientIF
Parameters:
key - the key to set
req - the Persistence to Master value
rep - the Persistence to Replicas
Returns:
whether or not the operation was performed

delete

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> delete(java.lang.String key,
                                                                            net.spy.memcached.PersistTo req)
Delete a value with durability options for persistence.

Specified by:
delete in interface CouchbaseClientIF
Parameters:
key - the key to set
req - the persistence option requested
Returns:
whether or not the operation was performed

delete

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> delete(java.lang.String key,
                                                                            net.spy.memcached.ReplicateTo req)
Delete a value with durability options for replication.

Specified by:
delete in interface CouchbaseClientIF
Parameters:
key - the key to set
req - the replication option requested
Returns:
whether or not the operation was performed

set

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> set(java.lang.String key,
                                                                         int exp,
                                                                         java.lang.Object value,
                                                                         net.spy.memcached.PersistTo req,
                                                                         net.spy.memcached.ReplicateTo rep)
Set a value with durability options. To make sure that a value is stored the way you want it to in the cluster, you can use the PersistTo and ReplicateTo arguments. The operation will block until the desired state is satisfied or otherwise an exception is raised. There are many reasons why this could happen, the more frequent ones are as follows: - The given replication settings are invalid. - The operation could not be completed within the timeout. - Something goes wrong and a cluster failover is triggered. The client does not attempt to guarantee the given durability constraints, it just reports whether the operation has been completed or not. If it is not achieved, it is the responsibility of the application code using this API to re-retrieve the items to verify desired state, redo the operation or both. Note that even if an exception during the observation is raised, this doesn't mean that the operation has failed. A normal set() operation is initiated and after the OperationFuture has returned, the key itself is observed with the given durability options (watch out for Observed*Exceptions) in this case.

Specified by:
set in interface CouchbaseClientIF
Parameters:
key - the key to store.
exp - the expiry value to use.
value - the value of the key.
req - the amount of nodes the item should be persisted to before returning.
rep - the amount of nodes the item should be replicated to before returning.
Returns:
the future result of the set operation.

set

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> set(java.lang.String key,
                                                                         int exp,
                                                                         java.lang.Object value,
                                                                         net.spy.memcached.PersistTo req)
Set a value with durability options. This is a shorthand method so that you only need to provide a PersistTo value if you don't care if the value is already replicated. A PersistTo.TWO durability setting implies a replication to at least one node. For more information on how the durability options work, see the docblock for the set() operation with both PersistTo and ReplicateTo settings.

Specified by:
set in interface CouchbaseClientIF
Parameters:
key - the key to store.
exp - the expiry value to use.
value - the value of the key.
req - the amount of nodes the item should be persisted to before returning.
Returns:
the future result of the set operation.

set

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> set(java.lang.String key,
                                                                         int exp,
                                                                         java.lang.Object value,
                                                                         net.spy.memcached.ReplicateTo rep)
Set a value with durability options. This method allows you to express durability at the replication level only and is the functional equivalent of PersistTo.ZERO. A common use case for this would be to achieve good insert-performance and at the same time making sure that the data is at least replicated to the given amount of nodes to provide a better level of data safety. For more information on how the durability options work, see the docblock for the set() operation with both PersistTo and ReplicateTo settings.

Specified by:
set in interface CouchbaseClientIF
Parameters:
key - the key to store.
exp - the expiry value to use.
value - the value of the key.
rep - the amount of nodes the item should be replicated to before returning.
Returns:
the future result of the set operation.

add

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> add(java.lang.String key,
                                                                         int exp,
                                                                         java.lang.Object value,
                                                                         net.spy.memcached.PersistTo req,
                                                                         net.spy.memcached.ReplicateTo rep)
Add a value with durability options. To make sure that a value is stored the way you want it to in the cluster, you can use the PersistTo and ReplicateTo arguments. The operation will block until the desired state is satisfied or otherwise an exception is raised. There are many reasons why this could happen, the more frequent ones are as follows: - The given replication settings are invalid. - The operation could not be completed within the timeout. - Something goes wrong and a cluster failover is triggered. The client does not attempt to guarantee the given durability constraints, it just reports whether the operation has been completed or not. If it is not achieved, it is the responsibility of the application code using this API to re-retrieve the items to verify desired state, redo the operation or both. Note that even if an exception during the observation is raised, this doesn't mean that the operation has failed. A normal add() operation is initiated and after the OperationFuture has returned, the key itself is observed with the given durability options (watch out for Observed*Exceptions) in this case.

Specified by:
add in interface CouchbaseClientIF
Parameters:
key - the key to store.
exp - the expiry value to use.
value - the value of the key.
req - the amount of nodes the item should be persisted to before returning.
rep - the amount of nodes the item should be replicated to before returning.
Returns:
the future result of the add operation.

add

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> add(java.lang.String key,
                                                                         int exp,
                                                                         java.lang.Object value,
                                                                         net.spy.memcached.PersistTo req)
Add a value with durability options. This is a shorthand method so that you only need to provide a PersistTo value if you don't care if the value is already replicated. A PersistTo.TWO durability setting implies a replication to at least one node. For more information on how the durability options work, see the docblock for the add() operation with both PersistTo and ReplicateTo settings.

Specified by:
add in interface CouchbaseClientIF
Parameters:
key - the key to store.
exp - the expiry value to use.
value - the value of the key.
req - the amount of nodes the item should be persisted to before returning.
Returns:
the future result of the add operation.

add

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> add(java.lang.String key,
                                                                         int exp,
                                                                         java.lang.Object value,
                                                                         net.spy.memcached.ReplicateTo rep)
Add a value with durability options. This method allows you to express durability at the replication level only and is the functional equivalent of PersistTo.ZERO. A common use case for this would be to achieve good insert-performance and at the same time making sure that the data is at least replicated to the given amount of nodes to provide a better level of data safety. For more information on how the durability options work, see the docblock for the add() operation with both PersistTo and ReplicateTo settings.

Specified by:
add in interface CouchbaseClientIF
Parameters:
key - the key to store.
exp - the expiry value to use.
value - the value of the key.
rep - the amount of nodes the item should be replicated to before returning.
Returns:
the future result of the add operation.

replace

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> replace(java.lang.String key,
                                                                             int exp,
                                                                             java.lang.Object value,
                                                                             net.spy.memcached.PersistTo req,
                                                                             net.spy.memcached.ReplicateTo rep)
Replace a value with durability options. To make sure that a value is stored the way you want it to in the cluster, you can use the PersistTo and ReplicateTo arguments. The operation will block until the desired state is satisfied or otherwise an exception is raised. There are many reasons why this could happen, the more frequent ones are as follows: - The given replication settings are invalid. - The operation could not be completed within the timeout. - Something goes wrong and a cluster failover is triggered. The client does not attempt to guarantee the given durability constraints, it just reports whether the operation has been completed or not. If it is not achieved, it is the responsibility of the application code using this API to re-retrieve the items to verify desired state, redo the operation or both. Note that even if an exception during the observation is raised, this doesn't mean that the operation has failed. A normal replace() operation is initiated and after the OperationFuture has returned, the key itself is observed with the given durability options (watch out for Observed*Exceptions) in this case.

Specified by:
replace in interface CouchbaseClientIF
Parameters:
key - the key to store.
exp - the expiry value to use.
value - the value of the key.
req - the amount of nodes the item should be persisted to before returning.
rep - the amount of nodes the item should be replicated to before returning.
Returns:
the future result of the replace operation.

replace

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> replace(java.lang.String key,
                                                                             int exp,
                                                                             java.lang.Object value,
                                                                             net.spy.memcached.PersistTo req)
Replace a value with durability options. This is a shorthand method so that you only need to provide a PersistTo value if you don't care if the value is already replicated. A PersistTo.TWO durability setting implies a replication to at least one node. For more information on how the durability options work, see the docblock for the replace() operation with both PersistTo and ReplicateTo settings.

Specified by:
replace in interface CouchbaseClientIF
Parameters:
key - the key to store.
exp - the expiry value to use.
value - the value of the key.
req - the amount of nodes the item should be persisted to before returning.
Returns:
the future result of the replace operation.

replace

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> replace(java.lang.String key,
                                                                             int exp,
                                                                             java.lang.Object value,
                                                                             net.spy.memcached.ReplicateTo rep)
Replace a value with durability options. This method allows you to express durability at the replication level only and is the functional equivalent of PersistTo.ZERO. A common use case for this would be to achieve good insert-performance and at the same time making sure that the data is at least replicated to the given amount of nodes to provide a better level of data safety. For more information on how the durability options work, see the docblock for the replace() operation with both PersistTo and ReplicateTo settings.

Specified by:
replace in interface CouchbaseClientIF
Parameters:
key - the key to store.
exp - the expiry value to use.
value - the value of the key.
rep - the amount of nodes the item should be replicated to before returning.
Returns:
the future result of the replace operation.

cas

public net.spy.memcached.CASResponse cas(java.lang.String key,
                                         long cas,
                                         java.lang.Object value,
                                         net.spy.memcached.PersistTo req,
                                         net.spy.memcached.ReplicateTo rep)
Set a value with a CAS and durability options. To make sure that a value is stored the way you want it to in the cluster, you can use the PersistTo and ReplicateTo arguments. The operation will block until the desired state is satisfied or otherwise an exception is raised. There are many reasons why this could happen, the more frequent ones are as follows: - The given replication settings are invalid. - The operation could not be completed within the timeout. - Something goes wrong and a cluster failover is triggered. The client does not attempt to guarantee the given durability constraints, it just reports whether the operation has been completed or not. If it is not achieved, it is the responsibility of the application code using this API to re-retrieve the items to verify desired state, redo the operation or both. Note that even if an exception during the observation is raised, this doesn't mean that the operation has failed. A normal asyncCAS() operation is initiated and after the OperationFuture has returned, the key itself is observed with the given durability options (watch out for Observed*Exceptions) in this case.

Specified by:
cas in interface CouchbaseClientIF
Parameters:
key - the key to store.
cas - the CAS value to use.
value - the value of the key.
req - the amount of nodes the item should be persisted to before returning.
rep - the amount of nodes the item should be replicated to before returning.
Returns:
the future result of the CAS operation.

cas

public net.spy.memcached.CASResponse cas(java.lang.String key,
                                         long cas,
                                         java.lang.Object value,
                                         net.spy.memcached.PersistTo req)
Set a value with a CAS and durability options. This is a shorthand method so that you only need to provide a PersistTo value if you don't care if the value is already replicated. A PersistTo.TWO durability setting implies a replication to at least one node. For more information on how the durability options work, see the docblock for the cas() operation with both PersistTo and ReplicateTo settings.

Specified by:
cas in interface CouchbaseClientIF
Parameters:
key - the key to store.
cas - the CAS value to use.
value - the value of the key.
req - the amount of nodes the item should be persisted to before returning.
Returns:
the future result of the CAS operation.

cas

public net.spy.memcached.CASResponse cas(java.lang.String key,
                                         long cas,
                                         java.lang.Object value,
                                         net.spy.memcached.ReplicateTo rep)
Set a value with a CAS and durability options. This method allows you to express durability at the replication level only and is the functional equivalent of PersistTo.ZERO. A common use case for this would be to achieve good insert-performance and at the same time making sure that the data is at least replicated to the given amount of nodes to provide a better level of data safety. For more information on how the durability options work, see the docblock for the cas() operation with both PersistTo and ReplicateTo settings.

Specified by:
cas in interface CouchbaseClientIF
Parameters:
key - the key to store.
cas - the CAS value to use.
value - the value of the key.
rep - the amount of nodes the item should be replicated to before returning.
Returns:
the future result of the CAS operation.

observe

public java.util.Map<net.spy.memcached.MemcachedNode,net.spy.memcached.ObserveResponse> observe(java.lang.String key,
                                                                                                long cas)
Observe a key with a associated CAS. This method allows you to check immediately on the state of a given key/CAS combination. It is normally used by higher-level methods when used in combination with durability constraints (ReplicateTo, PersistTo), but can also be used separately.

Specified by:
observe in interface CouchbaseClientIF
Parameters:
key - the key to observe.
cas - the CAS of the key (0 will ignore it).
Returns:
ObserveReponse the Response on master and replicas.
Throws:
java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests.

getNumVBuckets

public int getNumVBuckets()
Gets the number of vBuckets that are contained in the cluster. This function is for internal use only and should rarely be since there are few use cases in which it is necessary.

Specified by:
getNumVBuckets in interface CouchbaseClientIF

shutdown

public boolean shutdown(long timeout,
                        java.util.concurrent.TimeUnit unit)
Specified by:
shutdown in interface net.spy.memcached.MemcachedClientIF
Overrides:
shutdown in class net.spy.memcached.MemcachedClient

observePoll

public void observePoll(java.lang.String key,
                        long cas,
                        net.spy.memcached.PersistTo persist,
                        net.spy.memcached.ReplicateTo replicate,
                        boolean isDelete)
Poll and observe a key with the given CAS and persist settings. Based on the given persistence and replication settings, it observes the key and raises an exception if a timeout has been reached. This method is normally utilized through higher-level methods but can also be used directly. If persist is null, it will default to PersistTo.ZERO and if replicate is null, it will default to ReplicateTo.ZERO. This is the default behavior and is the same as not observing at all.

Parameters:
key - the key to observe.
cas - the CAS value for the key.
persist - the persistence settings.
replicate - the replication settings.
isDelete - if the key is to be deleted.

getKeyStats

public net.spy.memcached.internal.OperationFuture<java.util.Map<java.lang.String,java.lang.String>> getKeyStats(java.lang.String key)

flush

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> flush()
Flush all data from the bucket immediately. Note that if the bucket is of type memcached the flush will be nearly instantaneous. Running a flush() on a Couchbase bucket can take quite a while, depending on the amount of data and the load on the system.

Specified by:
flush in interface net.spy.memcached.MemcachedClientIF
Overrides:
flush in class net.spy.memcached.MemcachedClient
Returns:
a OperationFuture indicating the result of the flush.

flush

public net.spy.memcached.internal.OperationFuture<java.lang.Boolean> flush(int delay)
Flush all caches from all servers with a delay of application.

Specified by:
flush in interface net.spy.memcached.MemcachedClientIF
Overrides:
flush in class net.spy.memcached.MemcachedClient
Parameters:
delay - the period of time to delay, in seconds
Returns:
whether or not the operation was accepted


Copyright © 2006-2009 Dustin Sallings, 2009-2012 Couchbase, Inc.