Class CallableCacheLoaderAdapter<K,V>
java.lang.Object
org.springframework.data.gemfire.cache.CallableCacheLoaderAdapter<K,V>
- All Implemented Interfaces:
Callable<V>,CacheCallback,CacheLoader<K,,V> Declarable
public class CallableCacheLoaderAdapter<K,V>
extends Object
implements Callable<V>, CacheLoader<K,V>
The
CallableCacheLoaderAdapter class is a Callable and GemFire CacheLoader implementation
that adapts the Callable interface into an instance of the CacheLoader interface. This class is
useful in situations where GemFire developers have several CacheLoader implementations that they wish to
use with Spring's Cache Abstraction.- Since:
- 1.9.0
- Author:
- John Blum
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCallableCacheLoaderAdapter(CacheLoader<K, V> delegate) Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoader.CallableCacheLoaderAdapter(CacheLoader<K, V> delegate, K key, Region<K, V> region) Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoaderand is initialized with the given key for which the value will be loaded along with theRegionin which the entry (key/value) belongs.CallableCacheLoaderAdapter(CacheLoader<K, V> delegate, K key, Region<K, V> region, Object argument) Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoaderand is initialized with the given key for which the value will be loaded along with theRegionin which the entry (key/value) belongs. -
Method Summary
Modifier and TypeMethodDescriptionfinal Vcall()Invoked to load a cache value for the specified key.voidclose()Closes any resources used by thisCacheLoader.protected ObjectGets the argument used by thisCacheLoaderto load the value for the specified key.protected CacheLoader<K,V> TheCacheLoaderdelegate used to actually load the cache value for the specified key.protected KgetKey()The specified key for which a value will be loaded by thisCacheLoader.Returns the Region to which the entry (key/value) belongs.load(LoaderHelper<K, V> loaderHelper) Loads a value for the specified cache (i.e.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.geode.cache.Declarable
init, initialize
-
Constructor Details
-
CallableCacheLoaderAdapter
Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoader.- Parameters:
delegate- theCacheLoaderdelegated to by this adapter.- See Also:
-
CallableCacheLoaderAdapter
Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoaderand is initialized with the given key for which the value will be loaded along with theRegionin which the entry (key/value) belongs.- Parameters:
delegate- theCacheLoaderdelegated to by this adapter.key- the key for which the value will be loaded.region- theRegionin which the entry (key/value) belongs.- See Also:
-
CallableCacheLoaderAdapter
public CallableCacheLoaderAdapter(CacheLoader<K, V> delegate, K key, Region<K, V> region, Object argument) Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoaderand is initialized with the given key for which the value will be loaded along with theRegionin which the entry (key/value) belongs. Additionally, an argument may be specified for use with theCacheLoaderdelegate.- Parameters:
delegate- theCacheLoaderdelegated to by this adapter.key- the key for which the value will be loaded.region- theRegionin which the entry (key/value) belongs.argument- the Object argument used with theCacheLoaderdelegate.- See Also:
-
-
Method Details
-
getArgument
Gets the argument used by thisCacheLoaderto load the value for the specified key.- Returns:
- an Object argument used by this
CacheLoaderwhen loading the value for the specified key.
-
getCacheLoader
TheCacheLoaderdelegate used to actually load the cache value for the specified key.- Returns:
- a reference to the actual
CacheLoaderused when loading the cache value for the specified key. - See Also:
-
getKey
The specified key for which a value will be loaded by thisCacheLoader.- Returns:
- the specified key for which the value will be loaded.
-
getRegion
Returns the Region to which the entry (key/value) belongs.- Returns:
- the Region to which the entry belongs.
- See Also:
-
call
Invoked to load a cache value for the specified key. Delegates toload(LoaderHelper). -
close
public void close()Closes any resources used by thisCacheLoader. Delegates to the underlyingCacheLoader.- Specified by:
closein interfaceCacheCallback- See Also:
-
load
Loads a value for the specified cache (i.e.Region) and key with the help of theLoaderHelper. Delegates to the underlyingCacheLoader.- Specified by:
loadin interfaceCacheLoader<K,V> - Parameters:
loaderHelper- aLoaderHelperobject passed in from cache service providing access to the key,Region, argument, andnetSearch.- Returns:
- the value supplied for the specified key, or null if no value can be supplied. A local loader will
always be invoked if one exists. Otherwise one remote loader is invoked. Returning
nullcausesRegion.get(Object, Object)to returnnull. - Throws:
CacheLoaderException- if an error occurs during the load operation. This exception, or any other Exception thrown by this method will be propagated back to the application from theRegion.get(Object)method.- See Also:
-