voldemort.client
Class LazyStoreClient<K,V>

java.lang.Object
  extended by voldemort.client.LazyStoreClient<K,V>
All Implemented Interfaces:
StoreClient<K,V>

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

A StoreClient with lazy initialization. This is useful existing codes that initializes clients at service deployment time, when the servers may or may not be available


Constructor Summary
LazyStoreClient(java.util.concurrent.Callable<StoreClient<K,V>> storeClientThunk)
           
LazyStoreClient(java.util.concurrent.Callable<StoreClient<K,V>> storeClientThunk, boolean wrapsRESTClient)
          A Hybrid store client which tries to do immediate bootstrap.
 
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.
 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.
 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
 java.util.List<Node> getResponsibleNodes(K key)
          Returns the list of nodes which should have this key.
 StoreClient<K,V> getStoreClient()
           
 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  StoreClient<K,V> initStoreClient()
           
 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, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyStoreClient

public LazyStoreClient(java.util.concurrent.Callable<StoreClient<K,V>> storeClientThunk)

LazyStoreClient

public LazyStoreClient(java.util.concurrent.Callable<StoreClient<K,V>> storeClientThunk,
                       boolean wrapsRESTClient)
A Hybrid store client which tries to do immediate bootstrap. In case of an exception, we fallback to the lazy way of doing initialization.

Parameters:
storeClientThunk - The callback invoked for doing the actual bootstrap
instantInit - A boolean flag when set indicates that we should try to immediately bootstrap
Method Detail

getStoreClient

public StoreClient<K,V> getStoreClient()

initStoreClient

protected StoreClient<K,V> initStoreClient()

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

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.

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.

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)
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.

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

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.

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

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

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

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

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

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


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