Class AbstractMap

java.lang.Object
com.j_spaces.map.AbstractMap
All Implemented Interfaces:
Cache, IMap, Map
Direct Known Subclasses:
GSMapImpl, MapCache

public abstract class AbstractMap extends Object implements IMap
Base class for all Map implementations.
Since:
5.0
Version:
1.0
Author:
Guy Korland
  • Field Details

    • NONE_COMPRESSION

      public static final int NONE_COMPRESSION
      See Also:
    • ZIP_COMPRESSION

      public static final int ZIP_COMPRESSION
      See Also:
    • _transaction

      protected Transaction _transaction
    • _timeToLive

      protected long _timeToLive
    • _timeout

      protected long _timeout
    • _spaceProxy

      protected ISpaceProxy _spaceProxy
    • _compression

      protected final StorageType _compression
    • _isVersioned

      protected boolean _isVersioned
    • _entryInfos

      protected MapVersionTable _entryInfos
  • Constructor Details

    • AbstractMap

      public AbstractMap(IJSpace space, long timeToLive, Transaction txn, int compression, boolean isVersioned)
      AbstractMap constructor.
      Parameters:
      space - Space proxy or DCache proxy.
      timeToLive - Time to live for value object in cache.
      txn - if not null all operation will be executed with the desired transaction.
      compression - NONE = 0 , ZIP = 1
      isVersioned - true if versioned To set new transaction use: setTransaction(txn) To reset the transaction use: setTransaction(null) To get the current transaction use: getTransaction()
  • Method Details

    • setVersioned

      public final void setVersioned(boolean versioned)
      Sets optimistic locking mode.
      Specified by:
      setVersioned in interface IMap
      Parameters:
      versioned - true if optimistic locking is needed
    • isVersioned

      public final boolean isVersioned()
      Check if using optimistic locking.
      Specified by:
      isVersioned in interface IMap
      Returns:
      true if using optimistic locking
    • setTimeToLive

      public final void setTimeToLive(long millisecond)
      Sets the duration that entries will stay in the cache.
      Specified by:
      setTimeToLive in interface IMap
      Parameters:
      millisecond - how long entries will live in the cache, in milliseconds
    • getTimeToLive

      public final long getTimeToLive()
      Returns how long cached objects will live in the cache.
      Specified by:
      getTimeToLive in interface IMap
      Returns:
      how long entries will live in the cache, in milliseconds
    • setWaitForResponse

      public final void setWaitForResponse(long timeout)
      Specified by:
      setWaitForResponse in interface IMap
      Parameters:
      timeout - time to wait for response
    • getWaitForResponse

      public final long getWaitForResponse()
      Specified by:
      getWaitForResponse in interface IMap
      Returns:
      time to wait for response
    • internalPut

      protected abstract Object internalPut(Object key, Object value, Transaction txn, long timeToLive, long timeout) throws CacheException
      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.
      Throws:
      CacheException
    • internalGet

      protected abstract Object internalGet(Object key, Transaction txn, long waitForResponse, int readModifiers) throws CacheException
      Gets the mapping for this key from this map if it is present.
      Parameters:
      key - key whose mapping is to be removed from the map.
      waitForResponse - to wait for response
      Returns:
      previous value associated with specified key.
      Throws:
      CacheException
    • internalRemove

      protected abstract Object internalRemove(Object key, Transaction txn, long waitForResponse) throws CacheException
      Removes the mapping for this key from this map if it is present.
      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.
      Throws:
      CacheException
    • put

      public final Object put(Object key, Object value)
      The put method adds the object "value" to the cache identified by the object "key".
      Specified by:
      put in interface Cache
      Specified by:
      put in interface Map
      Parameters:
      key - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      previous value associated with specified key, or null if there was no mapping for key.
    • put

      public final Object put(Object key, Object value, long timeToLive)
      Puts value to the cache with specified key for timeToLive milliseconds to live in the cache.
      Specified by:
      put in interface IMap
      Parameters:
      key - key for the value
      value - object(~ entry)
      timeToLive - time to keep object in this cache, in milliseconds
      Returns:
      previous value associated with specified key, or null if there was no mapping for key.
    • put

      public Object put(Object key, Object value, long timeToLive, long timeout)
      Description copied from interface: IMap
      Puts value to the cache with specified key for timeToLive milliseconds to live in the cache.
      Specified by:
      put in interface IMap
      Parameters:
      key - key for the value
      value - object(~ entry)
      timeToLive - time to keep object in this cache, in milliseconds
      Returns:
      previous value associated with specified key, or null if there was no mapping for key.
    • put

      public final Object put(Object key, Object value, Transaction txn, long timeToLive)
      Description copied from interface: IMap
      Puts value to the cache with specified key for timeToLive milliseconds to live in the cache.
      Specified by:
      put in interface IMap
      Parameters:
      key - key for the value
      value - object(~ entry)
      txn - the transaction object, if any, under which to perform the put
      timeToLive - time to keep object in this cache, in milliseconds
      Returns:
      previous value associated with specified key, or null if there was no mapping for key.
    • put

      public final Object put(Object key, Object value, Transaction txn, long timeToLive, long timeout)
      Puts value to the cache with specified key for timeToLive milliseconds to live in the cache.
      Specified by:
      put in interface IMap
      Parameters:
      key - key for the value
      value - object(~ entry)
      txn - the transaction object, if any, under which to perform the put
      timeToLive - time to keep object in this cache, in milliseconds
      timeout - time to wait for response
      Returns:
      previous value associated with specified key, or null if there was no mapping for key.
    • putAll

      public void putAll(Map map)
      Copies all of the mappings from the specified map to the cache.
      Specified by:
      putAll in interface Cache
      Specified by:
      putAll in interface Map
      Parameters:
      map - A map of key and values to be copy into the cache
    • putAll

      public void putAll(Map map, Transaction txn, long timeToLive)
      Copies all of the mappings from the specified map to the cache.
      Specified by:
      putAll in interface IMap
      Parameters:
      map - A map of key and values to be copy into the cache
      txn - the transaction object, if any, under which to perform the put
      timeToLive - time to keep object in this cache, in milliseconds
    • getAll

      public Map getAll(Collection keys) throws CacheException
      The getAll method will return, from the cache, a Map of the objects associated with the Collection of keys in argument "keys". If the objects are not in the cache, the associated cache loader will be called. If no loader is associated with an object, a null is returned. If a problem is encountered during the retrieving or loading of the objects, an exception will be thrown.
      Specified by:
      getAll in interface Cache
      Parameters:
      keys - keys whose associated values are to be returned.
      Returns:
      Map of the objects associated with the Collection of keys
      Throws:
      CacheException - error accord while loading
    • get

      public Object get(Object key)
      The get method will return, from the cache, the object associated with the argument "key". If the object is not in the cache, the associated cache loader will be called. If no loader is associated with the object, a null is returned. If a problem is encountered during the retrieving or loading of the object, an exception (to be defined) will be thrown.
      Specified by:
      get in interface Cache
      Specified by:
      get in interface Map
      Parameters:
      key - key whose associated value is to be returned.
      Returns:
      the value to which this cache maps the specified key, or null if the cache contains no mapping for this key.
    • get

      public Object get(Object key, long waitForResponse)
      Returns the object that is associated with key in this cache. Client will wait at most waitForResponse milliseconds for get call to return.
      Specified by:
      get in interface IMap
      Parameters:
      key - key whose associated value is to be returned.
      waitForResponse - time to wait for response
      Returns:
      Returns the object that is associated with the key
    • get

      public Object get(Object key, Transaction txn, long waitForResponse, int readModifiers)
      Returns the object that is associated with key in this cache. Client will wait at most waitForResponse milliseconds for get call to return.
      Specified by:
      get in interface IMap
      Parameters:
      key - key whose associated value is to be returned.
      txn - the transaction object, if any, under which to perform the get
      waitForResponse - time to wait for response
      readModifiers - one or a union of ReadModifiers.
      Returns:
      Returns the object that is associated with the key
    • size

      public int size()
      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
      Returns:
      the number of key-value mappings in this cache.
    • isEmpty

      public final boolean isEmpty()
      Return true if entrySet().isEmpty() return true.
      Specified by:
      isEmpty in interface Cache
      Specified by:
      isEmpty in interface Map
      Returns:
      true if empty
    • remove

      public Object remove(Object key)
      The remove method will delete the object from the cache including the key, the associated value and the associated CacheStatistics object.
      Specified by:
      remove in interface Cache
      Specified by:
      remove in interface Map
      Parameters:
      key - key whose associated value is to be removed.
      Returns:
      previous value associated with specified key, or null if there was no mapping for key.
    • remove

      public Object remove(Object key, long waitForResponse)
      Removes the mapping for this key from this cache. Client will wait at most waitForResponse milliseconds for get call to return.
      Specified by:
      remove in interface IMap
      Parameters:
      key - key whose associated value is to be returned.
      waitForResponse - time to wait for response
      Returns:
      The removed object
    • remove

      public Object remove(Object key, Transaction txn, long waitForResponse)
      Removes the mapping for this key from this cache. Client will wait at most waitForResponse milliseconds for get call to return.
      Specified by:
      remove in interface IMap
      Parameters:
      key - key whose associated value is to be returned.
      txn - the transaction object, if any, under which to perform the remove
      waitForResponse - time to wait for response
      Returns:
      The removed object
    • setTransaction

      public final void setTransaction(Transaction transaction)
      Set current transaction, all the map calls will be performed under this transaction. Setting to null will turn all the following map calls to be with transaction. In order to
      
      
       IMap map = ... ;
       TransactionManager tm = ... ;
      
       Transaction.Created created = TransactionFactory#create(tm, 10000);
       map.setTransaction(Created.transaction)
      
       map.put( "key1", "value1"); // under transaction
       map.put( "key2", "value2"); // under transaction
      
       Created.transaction.commit();
      
       map.setTransaction( null);
      
       map.remove( "key2"); // not under transaction
       
      Specified by:
      setTransaction in interface IMap
      Parameters:
      transaction - active transaction or null
    • getTransaction

      public final Transaction getTransaction()
      Returns active transaction or null if no transaction defined.
      Specified by:
      getTransaction in interface IMap
      Returns:
      Transaction
    • load

      public void load(Object key) throws CacheException
      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
      Parameters:
      key - key whose associated value is to be loaded.
      Throws:
      CacheException - error accord while loading
    • loadAll

      public void loadAll(Collection keys) throws CacheException
      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
      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
    • getMasterSpace

      public final IJSpace getMasterSpace()
      Returns the Master Space proxy.
      Specified by:
      getMasterSpace in interface IMap
      Returns:
      the master space proxy
    • getLocalSpace

      public final IJSpace getLocalSpace()
      Returns the Local Space proxy if exists.
      Specified by:
      getLocalSpace in interface IMap
      Returns:
      the local space proxy
    • buildEnvelope

      protected SpaceMapEntry buildEnvelope(Object key, Object value, String cacheID)
      Build Envelope using ClientUIDHandler utility class and adds the version if needed.
    • log

      protected void log(String description, Exception ex)
    • log

      protected void log(String description)