voldemort.client
Class DefaultStoreClient<K,V>

java.lang.Object
  extended by voldemort.client.DefaultStoreClient<K,V>
Type Parameters:
K - The key type
V - The value type
All Implemented Interfaces:
StoreClient<K,V>

public class DefaultStoreClient<K,V>
extends java.lang.Object
implements StoreClient<K,V>

The default StoreClient implementation you get back from a StoreClientFactory


Constructor Summary
DefaultStoreClient(java.lang.String storeName, InconsistencyResolver<Versioned<V>> resolver, StoreClientFactory storeFactory, int maxMetadataRefreshAttempts)
           
 
Method Summary
 boolean applyUpdate(UpdateAction<K,V> action)
          Apply the given action repeatedly until no ObsoleteVersionException is thrown.
 boolean applyUpdate(UpdateAction<K,V> action, int maxTries)
          Apply the given action repeatedly until no ObsoleteVersionException is thrown or maxTries unsuccessful attempts have been made.
 void bootStrap()
           
 boolean delete(K key)
          Delete any version of the given key which equal to or less than the current versions
 boolean delete(K key, Version version)
          Delete the specified version and any prior versions of the given key
 Versioned<V> get(K key)
          Get the versioned value associated with the given key or null if no value is associated with the key.
 Versioned<V> get(K key, Versioned<V> defaultValue)
          Get the versioned value associated with the given key or the defaultValue if no value is associated with the key.
 java.util.Map<K,Versioned<V>> getAll(java.lang.Iterable<K> keys)
          Gets the versioned values associated with the given keys and returns them in a Map of keys to versioned values.
 java.util.List<voldemort.cluster.Node> getResponsibleNodes(K key)
          Returns the list of nodes which should have this key.
 V getValue(K key)
          Get the value associated with the given key or null if there is no value associated with this key.
 V getValue(K key, V defaultValue)
          Get the value associated with the given key or defaultValue if there is no value associated with the key.
 void put(K key, V value)
          Associated the given value to the key, clobbering any existing values stored for the key.
 void put(K key, Versioned<V> versioned)
          Put the given Versioned value into the store for the given key if the version is greater to or concurrent with existing values.
 boolean putIfNotObsolete(K key, Versioned<V> versioned)
          Put the versioned value to the key, ignoring any ObsoleteVersionException that may be thrown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultStoreClient

public DefaultStoreClient(java.lang.String storeName,
                          InconsistencyResolver<Versioned<V>> resolver,
                          StoreClientFactory storeFactory,
                          int maxMetadataRefreshAttempts)
Method Detail

bootStrap

public void bootStrap()

delete

public boolean delete(K key)
Description copied from interface: StoreClient
Delete any version of the given key which equal to or less than the current versions

Specified by:
delete in interface StoreClient<K,V>
Parameters:
key - The key
Returns:
true if anything is deleted

delete

public boolean delete(K key,
                      Version version)
Description copied from interface: StoreClient
Delete the specified version and any prior versions of the given key

Specified by:
delete in interface StoreClient<K,V>
Parameters:
key - The key to delete
version - The version of the key
Returns:
true if anything is deleted

getValue

public V getValue(K key,
                  V defaultValue)
Description copied from interface: StoreClient
Get the value associated with the given key or defaultValue if there is no value associated with the key. This method strips off all version information and is only useful when no further storage operations will be done on this key.

Specified by:
getValue in interface StoreClient<K,V>
Parameters:
key - The key for which to fetch the associated value
defaultValue - A value to return if there is no value associated with this key
Returns:
Either the value stored for the key or the default value.

getValue

public V getValue(K key)
Description copied from interface: StoreClient
Get the value associated with the given key or null if there is no value associated with this key. This method strips off all version information and is only useful when no further storage operations will be done on this key.

Specified by:
getValue in interface StoreClient<K,V>
Parameters:
key - The key

get

public Versioned<V> get(K key,
                        Versioned<V> defaultValue)
Description copied from interface: StoreClient
Get the versioned value associated with the given key or the defaultValue if no value is associated with the key.

Specified by:
get in interface StoreClient<K,V>
Parameters:
key - The key for which to fetch the value.
Returns:
The versioned value, or the defaultValue if no value is stored for this key.

get

public Versioned<V> get(K key)
Description copied from interface: StoreClient
Get the versioned value associated with the given key or null if no value is associated with the key.

Specified by:
get in interface StoreClient<K,V>
Parameters:
key - The key for which to fetch the value.
Returns:
The versioned value, or null if no value is stored for this key.

getAll

public java.util.Map<K,Versioned<V>> getAll(java.lang.Iterable<K> keys)
Description copied from interface: StoreClient
Gets the versioned values associated with the given keys and returns them in a Map of keys to versioned values. Note that the returned map will only contain entries for the keys which have a value associated with them.

Specified by:
getAll in interface StoreClient<K,V>
Parameters:
keys - The keys for which to fetch the values.
Returns:
A Map of keys to versioned values.

put

public void put(K key,
                V value)
Description copied from interface: StoreClient
Associated the given value to the key, clobbering any existing values stored for the key.

Specified by:
put in interface StoreClient<K,V>
Parameters:
key - The key
value - The value

putIfNotObsolete

public boolean putIfNotObsolete(K key,
                                Versioned<V> versioned)
Description copied from interface: StoreClient
Put the versioned value to the key, ignoring any ObsoleteVersionException that may be thrown

Specified by:
putIfNotObsolete in interface StoreClient<K,V>
Parameters:
key - The key
versioned - The versioned value
Returns:
true if the put succeeded

put

public void put(K key,
                Versioned<V> versioned)
         throws ObsoleteVersionException
Description copied from interface: StoreClient
Put the given Versioned value into the store for the given key if the version is greater to or concurrent with existing values. Throw an ObsoleteVersionException otherwise.

Specified by:
put in interface StoreClient<K,V>
Parameters:
key - The key
versioned - The value and its versioned
Throws:
ObsoleteVersionException

applyUpdate

public boolean applyUpdate(UpdateAction<K,V> action)
Description copied from interface: StoreClient
Apply the given action repeatedly until no ObsoleteVersionException is thrown. This is useful for implementing a read-modify-store loop that could be pre-empted by another concurrent update, and should be repeated until it succeeds.

Specified by:
applyUpdate in interface StoreClient<K,V>
Parameters:
action - The action to apply. This is meant as a callback for the user to extend to provide their own logic.
Returns:
true if the action is successfully applied, false if the 3 attempts all result in ObsoleteVersionException

applyUpdate

public boolean applyUpdate(UpdateAction<K,V> action,
                           int maxTries)
Description copied from interface: StoreClient
Apply the given action repeatedly until no ObsoleteVersionException is thrown or maxTries unsuccessful attempts have been made. This is useful for implementing a read-modify-store loop.

Specified by:
applyUpdate in interface StoreClient<K,V>
Parameters:
action - The action to apply
Returns:
true if the action is successfully applied, false if maxTries failed attempts have been made

getResponsibleNodes

public java.util.List<voldemort.cluster.Node> getResponsibleNodes(K key)
Description copied from interface: StoreClient
Returns the list of nodes which should have this key.

Specified by:
getResponsibleNodes in interface StoreClient<K,V>
Returns:
a list of Nodes which should hold this key


Jay Kreps