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

    Constructors
    Constructor
    Description
    CallableCacheLoaderAdapter(org.apache.geode.cache.CacheLoader<K,V> delegate)
    Constructs an instance of the CallableCacheLoaderAdapter that delegates to the given CacheLoader.
    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 given CacheLoader and is initialized with the given key for which the value will be loaded along with the Region 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 given CacheLoader and is initialized with the given key for which the value will be loaded along with the Region in which the entry (key/value) belongs.
  • Method Summary

    Modifier and Type
    Method
    Description
    final V
    Invoked to load a cache value for the specified key.
    void
    Closes any resources used by this CacheLoader.
    protected Object
    Gets the argument used by this CacheLoader to load the value for the specified key.
    protected org.apache.geode.cache.CacheLoader<K,V>
    The CacheLoader delegate used to actually load the cache value for the specified key.
    protected K
    The specified key for which a value will be loaded by this CacheLoader.
    protected org.apache.geode.cache.Region<K,V>
    Returns the Region to which the entry (key/value) belongs.
    load(org.apache.geode.cache.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, wait

    Methods inherited from interface org.apache.geode.cache.Declarable

    init, initialize
  • Constructor Details

    • CallableCacheLoaderAdapter

      public CallableCacheLoaderAdapter(org.apache.geode.cache.CacheLoader<K,V> delegate)
      Constructs an instance of the CallableCacheLoaderAdapter that delegates to the given CacheLoader.
      Parameters:
      delegate - the CacheLoader 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 given CacheLoader and is initialized with the given key for which the value will be loaded along with the Region in which the entry (key/value) belongs.
      Parameters:
      delegate - the CacheLoader delegated to by this adapter.
      key - the key for which the value will be loaded.
      region - the Region in which the entry (key/value) belongs.
      See Also:
    • 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 given CacheLoader and is initialized with the given key for which the value will be loaded along with the Region in which the entry (key/value) belongs. Additionally, an argument may be specified for use with the CacheLoader delegate.
      Parameters:
      delegate - the CacheLoader delegated to by this adapter.
      key - the key for which the value will be loaded.
      region - the Region in which the entry (key/value) belongs.
      argument - the Object argument used with the CacheLoader delegate.
      See Also:
  • Method Details

    • getArgument

      protected Object getArgument()
      Gets the argument used by this CacheLoader 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

      protected org.apache.geode.cache.CacheLoader<K,V> getCacheLoader()
      The CacheLoader 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

      protected K getKey()
      The specified key for which a value will be loaded by this CacheLoader.
      Returns:
      the specified key for which the value will be loaded.
    • getRegion

      protected org.apache.geode.cache.Region<K,V> getRegion()
      Returns the Region to which the entry (key/value) belongs.
      Returns:
      the Region to which the entry belongs.
      See Also:
      • Region
    • call

      public final V call() throws Exception
      Invoked to load a cache value for the specified key. Delegates to load(LoaderHelper).
      Specified by:
      call in interface Callable<K>
      Returns:
      the loaded cache value for the specified key.
      Throws:
      IllegalStateException - if the Region or key references are null.
      Exception - if the load operation fails.
      See Also:
    • close

      public void close()
      Closes any resources used by this CacheLoader. Delegates to the underlying CacheLoader.
      Specified by:
      close in interface org.apache.geode.cache.CacheCallback
      See Also:
    • load

      public V load(org.apache.geode.cache.LoaderHelper<K,V> loaderHelper) throws org.apache.geode.cache.CacheLoaderException
      Loads a value for the specified cache (i.e. Region) and key with the help of the LoaderHelper. Delegates to the underlying CacheLoader.
      Specified by:
      load in interface org.apache.geode.cache.CacheLoader<K,V>
      Parameters:
      loaderHelper - a LoaderHelper object passed in from cache service providing access to the key, Region, argument, and netSearch.
      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 causes Region.get(Object, Object) to return null.
      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 the Region.get(Object) method.
      See Also: