net.spy.memcached
Class MembaseClient

java.lang.Object
  extended by net.spy.memcached.compat.SpyObject
      extended by net.spy.memcached.MemcachedClient
          extended by net.spy.memcached.MembaseClient
All Implemented Interfaces:
ConnectionObserver, MembaseClientIF, MemcachedClientIF, Reconfigurable
Direct Known Subclasses:
CouchbaseClient

public class MembaseClient
extends MemcachedClient
implements MembaseClientIF, Reconfigurable


Field Summary
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
  MembaseClient(List<URI> baseList, String bucketName, String pwd)
          Get a MembaseClient based on the REST response from a Membase server.
  MembaseClient(List<URI> baseList, String bucketName, String usr, String pwd)
          Get a MembaseClient based on the REST response from a Membase server where the username is different than the bucket name.
  MembaseClient(MembaseConnectionFactory cf)
          Get a MembaseClient based on the REST response from a Membase server where the username is different than the bucket name.
protected MembaseClient(MembaseConnectionFactory cf, boolean subscribe)
          Get a MembaseClient based on the REST response from a Membase server where the username is different than the bucket name.
 
Method Summary
 OperationFuture<CASValue<Object>> asyncGetAndLock(String key, int exp)
          Get and lock the given key asynchronously and decode with the default transcoder.
<T> OperationFuture<CASValue<T>>
asyncGetAndLock(String key, int exp, Transcoder<T> tc)
          Gets and locks the given key asynchronously.
 CASValue<Object> getAndLock(String key, int exp)
          Get and lock with a single key and decode using the default transcoder.
<T> CASValue<T>
getAndLock(String key, int exp, Transcoder<T> tc)
          Getl with a single key.
 void reconfigure(Bucket bucket)
          This function is called when there is a topology change in the cluster.
 boolean shutdown(long timeout, TimeUnit unit)
          Shut down this client gracefully.
 
Methods inherited from class net.spy.memcached.MemcachedClient
add, add, addObserver, append, append, asyncCAS, asyncCAS, asyncCAS, asyncDecr, asyncGet, asyncGet, asyncGetAndTouch, asyncGetAndTouch, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGets, asyncGets, asyncIncr, cas, cas, cas, connectionEstablished, connectionLost, decr, decr, decr, delete, delete, flush, flush, get, get, getAndTouch, getAndTouch, getAvailableServers, getBulk, getBulk, getBulk, getBulk, getNodeLocator, gets, gets, getStats, getStats, getTranscoder, getUnavailableServers, getVersions, incr, incr, incr, listSaslMechanisms, prepend, prepend, removeObserver, replace, replace, set, set, shutdown, 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, toString, wait, wait, wait
 
Methods inherited from interface net.spy.memcached.MemcachedClientIF
add, add, addObserver, append, append, asyncCAS, asyncCAS, asyncDecr, asyncGet, asyncGet, asyncGetAndTouch, asyncGetAndTouch, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGetBulk, asyncGets, asyncGets, asyncIncr, cas, cas, decr, decr, decr, delete, flush, flush, get, get, getAndTouch, getAndTouch, getAvailableServers, getBulk, getBulk, getBulk, getBulk, getNodeLocator, gets, gets, getStats, getStats, getTranscoder, getUnavailableServers, getVersions, incr, incr, incr, listSaslMechanisms, prepend, prepend, removeObserver, replace, replace, set, set, shutdown, touch, touch, waitForQueues
 

Field Detail

reconfiguring

protected volatile boolean reconfiguring
Constructor Detail

MembaseClient

public MembaseClient(List<URI> baseList,
                     String bucketName,
                     String pwd)
              throws IOException,
                     ConfigurationException
Get a MembaseClient based on the REST response from a Membase server. This constructor is merely a convenience for situations where the bucket name is the same as the user name. This is commonly the case. To connect to the "default" special bucket for a given cluster, use an empty string as the password. If a password has not been assigned to the bucket, it is typically an empty string.

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:
IOException - if connections could not be made
ConfigurationException - if the configuration provided by the server has issues or is not compatible

MembaseClient

public MembaseClient(List<URI> baseList,
                     String bucketName,
                     String usr,
                     String pwd)
              throws IOException,
                     ConfigurationException
Get a MembaseClient based on the REST response from a Membase server where the username is different than the bucket name. To connect to the "default" special bucket for a given cluster, use an empty string as the password. If a password has not been assigned to the bucket, it is typically an empty string.

Parameters:
baseList - the URI list of one or more servers from the cluster
bucketName - the bucket name in the cluster you wish to use
usr - the username for the bucket; this nearly always be the same as the bucket name
pwd - the password for the bucket
Throws:
IOException - if connections could not be made
ConfigurationException - if the configuration provided by the server has issues or is not compatible

MembaseClient

public MembaseClient(MembaseConnectionFactory cf)
              throws IOException,
                     ConfigurationException
Get a MembaseClient based on the REST response from a Membase server where the username is different than the bucket name. Note that when specifying a ConnectionFactory you must specify a BinaryConnectionFactory. 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. To connect to the "default" special bucket for a given cluster, use an empty string as the password. If a password has not been assigned to the bucket, it is typically an empty string.

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

MembaseClient

protected MembaseClient(MembaseConnectionFactory cf,
                        boolean subscribe)
                 throws IOException,
                        ConfigurationException
Get a MembaseClient based on the REST response from a Membase server where the username is different than the bucket name. Note that when specifying a ConnectionFactory you must specify a BinaryConnectionFactory. 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. To connect to the "default" special bucket for a given cluster, use an empty string as the password. If a password has not been assigned to the bucket, it is typically an empty string. The subscribe variable is determines whether or not we will subscribe to the configuration changes feed. This constructor should be used when calling super from subclasses of MembaseClient since the subclass might want to start the changes feed later.

Parameters:
cf - the ConnectionFactory to use to create connections
subscribe - whether or not to subscribe to config changes
Throws:
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 function is called when there is a topology change in the cluster. This function is intended for internal use only.

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

asyncGetAndLock

public <T> OperationFuture<CASValue<T>> asyncGetAndLock(String key,
                                                        int exp,
                                                        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 MembaseClientIF
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:
IllegalStateException - in the rare circumstance where queue is too full to accept any more requests

asyncGetAndLock

public OperationFuture<CASValue<Object>> asyncGetAndLock(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 MembaseClientIF
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:
IllegalStateException - in the rare circumstance where queue is too full to accept any more requests

getAndLock

public <T> CASValue<T> getAndLock(String key,
                                  int exp,
                                  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 MembaseClientIF
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:
OperationTimeoutException - if the global operation timeout is exceeded
IllegalStateException - in the rare circumstance where queue is too full to accept any more requests

getAndLock

public CASValue<Object> getAndLock(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 MembaseClientIF
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:
OperationTimeoutException - if the global operation timeout is exceeded
IllegalStateException - in the rare circumstance where queue is too full to accept any more requests

shutdown

public boolean shutdown(long timeout,
                        TimeUnit unit)
Description copied from class: MemcachedClient
Shut down this client gracefully.

Specified by:
shutdown in interface MemcachedClientIF
Overrides:
shutdown in class MemcachedClient
Parameters:
timeout - the amount of time time for shutdown
unit - the TimeUnit for the timeout
Returns:
result of the shutdown request