Class MapCache

java.lang.Object
com.j_spaces.map.AbstractMap
com.j_spaces.core.client.cache.map.MapCache
All Implemented Interfaces:
Cache, IMap, Remote, EventListener, Map, RemoteEventListener, LeaseListener

public final class MapCache extends AbstractMap implements RemoteEventListener, LeaseListener
This class provides a lightweight implementation to GigaSpaces IMap interface (A JCache standard extension), for Distributed Caching using java.util.Map API. Simply call Map.get and Map.put methods to store and retrieve values into or from the cache.
Since:
5.0
Version:
1.0
Author:
Guy Korland
  • Field Details

    • DEFAULT_MAX_CONNECTION_RETRY

      public static final int DEFAULT_MAX_CONNECTION_RETRY
      The default number of retires to reconnect to server when fault is discovered.
      See Also:
  • Constructor Details

    • MapCache

      public MapCache(IJSpace space, boolean isVersioned, int updateMode, EvictionStrategy evictionStrategy, boolean putFirst, int sizeLimit, int compression) throws RemoteException
      Constructor.
      Parameters:
      space - proxy to space
      isVersioned - true if a version should be kept for the values
      updateMode - SpaceURL.UPDATE_MODE_PULL or SpaceURL.UPDATE_MODE_PUSH
      evictionStrategy - eviction strategy to use in Cache
      putFirst - true if an unloaded value should be kept in cache on its first put
      Throws:
      RemoteException - might be thrown in case of network exception or server connection fail
  • Method Details

    • internalPut

      protected Object internalPut(Object key, Object value, Transaction txn, long timeToLive, long timeout)
      Specified by:
      internalPut in class AbstractMap
      Parameters:
      key - key for the value.
      value - object(~ entry)
      txn - transaction
      timeToLive - time to leave in master cache
      Returns:
      previous value associated with specified key.
    • size

      public int size()
      Description copied from class: AbstractMap
      Returns the size of this map. The search is scoped to the cache. Other caches in the system will not be searched and a CacheLoader will not be called.
      Specified by:
      size in interface Cache
      Specified by:
      size in interface Map
      Overrides:
      size in class AbstractMap
      Returns:
      the number of key-value mappings in this cache.
    • clear

      public void clear()
      Description copied from interface: Cache
      The clear method will remove all objects from the cache including the key and the associated value.
      Specified by:
      clear in interface Cache
      Specified by:
      clear in interface Map
    • clear

      public void clear(boolean clearMaster)
      Description copied from interface: IMap
      The clear method will remove all objects from the cache including the key and the associated value.
      Specified by:
      clear in interface IMap
      Parameters:
      clearMaster - if true clear also master, when false equals to clear()
    • containsKey

      public boolean containsKey(Object key)
      Description copied from interface: Cache
      Returns true if the cache contains the specified key. The search is scoped to the cache. Other caches in the system will not be searched and a CacheLoader will not be called.
      Specified by:
      containsKey in interface Cache
      Specified by:
      containsKey in interface Map
      Parameters:
      key - key whose presence in this cache is to be tested.
      Returns:
      true, if the cache contains the specified key.
    • containsValue

      public boolean containsValue(Object value)
      Description copied from interface: Cache
      Returns true if this cache maps one or more keys to the specified value. The search is scoped to the cache. Other caches in the system will not be searched and a CacheLoader will not be called.
      Specified by:
      containsValue in interface Cache
      Specified by:
      containsValue in interface Map
      Parameters:
      value - value whose presence in this cache is to be tested.
      Returns:
      true, if the cache contains the specified value.
    • values

      public Collection values()
      Description copied from interface: Cache
      Returns a collection view of the values contained in this cache. The search is scoped to the cache. Other caches in the system will not be searched and a CacheLoader will not be called.
      Specified by:
      values in interface Cache
      Specified by:
      values in interface Map
      Returns:
      a collection view of the values contained in this cache.
    • entrySet

      public Set entrySet()
      Description copied from interface: Cache
      Returns a set view of the objects currently contained in the cache. The search is scoped to the cache. Other caches in the system will not be searched and a CacheLoader will not be called.
      Specified by:
      entrySet in interface Cache
      Specified by:
      entrySet in interface Map
      Returns:
      a set of CacheEntry
    • keySet

      public Set keySet()
      Description copied from interface: Cache
      Returns a set view of the keys currently contained in the cache. The search is scoped to the cache. Other caches in the system will not be searched and a CacheLoader will not be called.
      Specified by:
      keySet in interface Cache
      Specified by:
      keySet in interface Map
      Returns:
      set of the keys
    • addListener

      public void addListener(CacheListener listener)
      Description copied from interface: Cache
      Add a listener to the list of cache listeners.
      Optional, not supported by all the implementations, currently supported only by local cache.
      Specified by:
      addListener in interface Cache
      Parameters:
      listener - call back CacheListener
    • evict

      public boolean evict(Object key)
      Description copied from interface: Cache
      The evict method will remove object from the cache the matches the provided key.
      Specified by:
      evict in interface Cache
      Parameters:
      key - the key to evict
      Returns:
      true, if the key was evicted
    • getCacheEntry

      public CacheEntry getCacheEntry(Object key)
      Description copied from interface: Cache
      Returns the CacheEntry object associated with the object identified by "key".
      Specified by:
      getCacheEntry in interface Cache
      Parameters:
      key - key whose associated value is to be returned.
      Returns:
      the CacheEntry to which this cache maps the specified key, or null if the cache contains no mapping for this key.
    • load

      public void load(Object key) throws CacheException
      Description copied from class: AbstractMap
      The load method provides a means to "pre load" the cache. This method will, load the specified object into the cache using the associated CacheLoader. If the object already exists in the cache, no action is taken. If no loader is associated with the object, no object will be loaded into the cache.
      Specified by:
      load in interface Cache
      Overrides:
      load in class AbstractMap
      Parameters:
      key - key whose associated value is to be loaded.
      Throws:
      CacheException - error accord while loading
    • loadAll

      public void loadAll(Collection keys) throws CacheException
      Description copied from class: AbstractMap
      The loadAll method provides a means to "pre load" objects into the cache. This method will, load the specified objects into the cache using the associated cache loader. If the an object already exists in the cache, no action is taken. If no loader is associated with the object, no object will be loaded into the cache.
      Specified by:
      loadAll in interface Cache
      Overrides:
      loadAll in class AbstractMap
      Parameters:
      keys - keys' Collection whose associated value to be loaded using the associated CacheLoader if this cache doesn't contain it.
      Throws:
      CacheException - error accord while loading
    • peek

      public Object peek(Object key)
      Description copied from interface: Cache
      The peek method will return the object associated with "key" if it currently exists (and is valid) in the cache. The search is scoped to the cache. Other caches in the system will not be searched and a CacheLoader will not be called.
      Specified by:
      peek in interface Cache
      Parameters:
      key - key whose associated value is to be peek.
      Returns:
      the value to which this cache maps the specified key, or null if the cache contains no mapping for this key.
    • removeListener

      public void removeListener(CacheListener listener)
      Description copied from interface: Cache
      Remove a listener from the list of cache listeners.
      Optional, not supported by all the implementations, currently supported only by local cache
      Specified by:
      removeListener in interface Cache
      Parameters:
      listener - the CacheListener to remove
    • notify

      public void notify(RemoteEvent remoteEvent) throws UnknownEventException, RemoteException
      Description copied from interface: RemoteEventListener
      Notify the listener about an event.

      The call to notify is synchronous to allow the party making the call to know if the call succeeded. However, it is not part of the semantics of the call that the notification return can be delayed while the recipient of the call reacts to the occurrence of the event. Simply put, the best strategy on the part of the recipient is to note the occurrence in some way and then return from the notify method as quickly as possible.

      UnknownEventException is thrown when the recipient does not recognize the combination of the event identifier and the event source as something in which it is interested. Throwing this exception has the effect of asking the sender to not send further notifications of this kind of event from this source in the future.

      Specified by:
      notify in interface RemoteEventListener
      Parameters:
      remoteEvent - the remote event that occurred
      Throws:
      UnknownEventException - the recipient does not recognize the combination of event identifier and event source
      RemoteException
    • internalRemove

      protected Object internalRemove(Object key, Transaction txn, long waitForResponse)
      Description copied from class: AbstractMap
      Removes the mapping for this key from this map if it is present.
      Specified by:
      internalRemove in class AbstractMap
      Parameters:
      key - key whose mapping is to be removed from the map.
      waitForResponse - to wait for response
      Returns:
      previous value associated with specified key, or null if there was no mapping for key.
    • internalGet

      protected Object internalGet(Object key, Transaction txn, long waitForResponse, int readModifiers)
      Description copied from class: AbstractMap
      Gets the mapping for this key from this map if it is present.
      Specified by:
      internalGet in class AbstractMap
      Parameters:
      key - key whose mapping is to be removed from the map.
      waitForResponse - to wait for response
      Returns:
      previous value associated with specified key.
    • notify

      public void notify(LeaseRenewalEvent event)
      Description copied from interface: LeaseListener
      Called by the LeaseRenewalManager when it cannot renew a lease that it is managing, and the lease's desired expiration time has not yet been reached.

      Note that, prior to invoking this method, the LeaseRenewalManager removes the affected lease from the managed set of leases. Note also that, because of the reentrancy guarantee made by the LeaseRenewalManager, new leases can be safely added by this method.

      Specified by:
      notify in interface LeaseListener
      Parameters:
      event - instance of LeaseRenewalEvent containing information about the lease that the LeaseRenewalManager was unable to renew, as well as information about the condition that made the LeaseRenewalManager fail to renew the lease
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable