Class CallableCacheLoaderAdapter<K,V>
java.lang.Object
org.springframework.data.gemfire.cache.CallableCacheLoaderAdapter<K,V>
- All Implemented Interfaces:
Callable<V>
,org.apache.geode.cache.CacheCallback
,org.apache.geode.cache.CacheLoader<K,
,V> org.apache.geode.cache.Declarable
public class CallableCacheLoaderAdapter<K,V>
extends Object
implements Callable<V>, org.apache.geode.cache.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
- See Also:
-
Callable
CacheLoader
LoaderHelper
Region
-
Constructor Summary
ConstructorDescriptionCallableCacheLoaderAdapter
(org.apache.geode.cache.CacheLoader<K, V> delegate) Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoader
.CallableCacheLoaderAdapter
(org.apache.geode.cache.CacheLoader<K, V> delegate, K key, org.apache.geode.cache.Region<K, V> region) Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoader
and is initialized with the given key for which the value will be loaded along with theRegion
in which the entry (key/value) belongs.CallableCacheLoaderAdapter
(org.apache.geode.cache.CacheLoader<K, V> delegate, K key, org.apache.geode.cache.Region<K, V> region, Object argument) Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoader
and is initialized with the given key for which the value will be loaded along with theRegion
in which the entry (key/value) belongs. -
Method Summary
Modifier and TypeMethodDescriptionfinal V
call()
Invoked to load a cache value for the specified key.void
close()
Closes any resources used by thisCacheLoader
.protected Object
Gets the argument used by thisCacheLoader
to load the value for the specified key.TheCacheLoader
delegate used to actually load the cache value for the specified key.protected K
getKey()
The specified key for which a value will be loaded by thisCacheLoader
.Returns the Region to which the entry (key/value) belongs.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, wait
Methods 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
- theCacheLoader
delegated to by this adapter.- See Also:
-
CallableCacheLoaderAdapter
public CallableCacheLoaderAdapter(org.apache.geode.cache.CacheLoader<K, V> delegate, K key, org.apache.geode.cache.Region<K, V> region) Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoader
and is initialized with the given key for which the value will be loaded along with theRegion
in which the entry (key/value) belongs.- Parameters:
delegate
- theCacheLoader
delegated to by this adapter.key
- the key for which the value will be loaded.region
- theRegion
in which the entry (key/value) belongs.- See Also:
-
CallableCacheLoaderAdapter(CacheLoader, Object, Region, Object)
CacheLoader
Region
-
CallableCacheLoaderAdapter
public CallableCacheLoaderAdapter(org.apache.geode.cache.CacheLoader<K, V> delegate, K key, org.apache.geode.cache.Region<K, V> region, Object argument) Constructs an instance of the CallableCacheLoaderAdapter that delegates to the givenCacheLoader
and is initialized with the given key for which the value will be loaded along with theRegion
in which the entry (key/value) belongs. Additionally, an argument may be specified for use with theCacheLoader
delegate.- Parameters:
delegate
- theCacheLoader
delegated to by this adapter.key
- the key for which the value will be loaded.region
- theRegion
in which the entry (key/value) belongs.argument
- the Object argument used with theCacheLoader
delegate.- See Also:
-
CallableCacheLoaderAdapter(CacheLoader, Object, Region, Object)
CacheLoader
Region
-
-
Method Details
-
getArgument
Gets the argument used by thisCacheLoader
to load the value for the specified key.- Returns:
- an Object argument used by this
CacheLoader
when loading the value for the specified key.
-
getCacheLoader
TheCacheLoader
delegate used to actually load the cache value for the specified key.- Returns:
- a reference to the actual
CacheLoader
used when loading the cache value for the specified key. - See Also:
-
CacheLoader
-
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:
-
Region
-
call
Invoked to load a cache value for the specified key. Delegates toload(LoaderHelper)
.- Specified by:
call
in interfaceCallable<K>
- Returns:
- the loaded cache value for the specified key.
- Throws:
IllegalStateException
- if theRegion
or key references are null.Exception
- if the load operation fails.- See Also:
-
close
public void close()Closes any resources used by thisCacheLoader
. Delegates to the underlyingCacheLoader
.- Specified by:
close
in interfaceorg.apache.geode.cache.CacheCallback
- See Also:
-
load
public V load(org.apache.geode.cache.LoaderHelper<K, V> loaderHelper) throws org.apache.geode.cache.CacheLoaderExceptionLoads a value for the specified cache (i.e.Region
) and key with the help of theLoaderHelper
. Delegates to the underlyingCacheLoader
.- Specified by:
load
in interfaceorg.apache.geode.cache.CacheLoader<K,
V> - Parameters:
loaderHelper
- aLoaderHelper
object 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
null
causesRegion.get(Object, Object)
to returnnull
. - Throws:
org.apache.geode.cache.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:
-
CacheLoader.load(LoaderHelper)
LoaderHelper
getCacheLoader()
-