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>
Direct Known Subclasses:
DynamicTimeoutStoreClient, ZenStoreClient

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

The default StoreClient implementation you get back from a StoreClientFactory


Field Summary
protected  java.util.concurrent.Callable<java.lang.Object> beforeRebootstrapCallback
           
protected  int metadataRefreshAttempts
           
protected  InconsistencyResolver<Versioned<V>> resolver
           
protected  Store<K,V,java.lang.Object> store
           
protected  StoreClientFactory storeFactory
           
protected  java.lang.String storeName
           
 
Constructor Summary
DefaultStoreClient()
           
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, java.lang.Object transforms)
          Get the versioned value associated with the given key and apply the given transforms to it before returning the value.
 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.
 Versioned<V> get(K key, Versioned<V> defaultValue, java.lang.Object transform)
           
 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.Map<K,Versioned<V>> getAll(java.lang.Iterable<K> keys, java.util.Map<K,java.lang.Object> transforms)
          Like getAll, except that the transforms are applied on the value associated with each key before returning the results
protected  Versioned<V> getItemOrThrow(K key, Versioned<V> defaultValue, java.util.List<Versioned<V>> items)
           
 java.util.List<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.
protected  Version getVersion(K key)
           
protected  java.util.List<Version> getVersions(K key)
           
 Version put(K key, V value)
          Associated the given value to the key, clobbering any existing values stored for the key.
 Version 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.
 Version put(K key, Versioned<V> versioned, java.lang.Object transform)
           
 Version put(K key, V value, java.lang.Object transforms)
          Like #put(Object, Object), except that the given transforms are applied on the value before writing it to the store
 boolean putIfNotObsolete(K key, Versioned<V> versioned)
          Put the versioned value to the key, ignoring any ObsoleteVersionException that may be thrown
 void setBeforeRebootstrapCallback(java.util.concurrent.Callable<java.lang.Object> callback)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

beforeRebootstrapCallback

protected java.util.concurrent.Callable<java.lang.Object> beforeRebootstrapCallback

storeFactory

protected StoreClientFactory storeFactory

metadataRefreshAttempts

protected int metadataRefreshAttempts

storeName

protected java.lang.String storeName

resolver

protected InconsistencyResolver<Versioned<V>> resolver

store

protected volatile Store<K,V,java.lang.Object> store
Constructor Detail

DefaultStoreClient

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

DefaultStoreClient

public DefaultStoreClient()
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,
                        Versioned<V> defaultValue,
                        java.lang.Object transform)

getVersions

protected java.util.List<Version> getVersions(K key)

getItemOrThrow

protected Versioned<V> getItemOrThrow(K key,
                                      Versioned<V> defaultValue,
                                      java.util.List<Versioned<V>> items)

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 Version 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
Returns:
version The version of the object

put

public Version put(K key,
                   Versioned<V> versioned,
                   java.lang.Object transform)
            throws ObsoleteVersionException
Throws:
ObsoleteVersionException

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 Version 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<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

getVersion

protected Version getVersion(K key)

get

public Versioned<V> get(K key,
                        java.lang.Object transforms)
Description copied from interface: StoreClient
Get the versioned value associated with the given key and apply the given transforms to it before returning the value. Returns null if no value is associated with the key

Specified by:
get in interface StoreClient<K,V>
Parameters:
key - the key for which the value is fetched
transforms - the transforms to be applied on the value fetched from the store
Returns:
the transformed 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,
                                            java.util.Map<K,java.lang.Object> transforms)
Description copied from interface: StoreClient
Like getAll, except that the transforms are applied on the value associated with each key before returning the results

Specified by:
getAll in interface StoreClient<K,V>
Parameters:
keys - the keys for which the values are fetched
transforms - the map of transforms, describing the transform to be applied to the value for each key
Returns:
A map of keys to transformed versioned values

put

public Version put(K key,
                   V value,
                   java.lang.Object transforms)
Description copied from interface: StoreClient
Like #put(Object, Object), except that the given transforms are applied on the value before writing it to the store

Specified by:
put in interface StoreClient<K,V>
Parameters:
key - the key
value - the value
transforms - the transforms to be applied on the value
Returns:
version The version of the object

setBeforeRebootstrapCallback

public void setBeforeRebootstrapCallback(java.util.concurrent.Callable<java.lang.Object> callback)


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu