Package com.j_spaces.map
Class AbstractMap
java.lang.Object
com.j_spaces.map.AbstractMap
Base class for all Map implementations.
- Since:
- 5.0
- Version:
- 1.0
- Author:
- Guy Korland
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StorageTypeprotected MapVersionTableprotected booleanprotected ISpaceProxyprotected longprotected longprotected Transactionstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionAbstractMap(IJSpace space, long timeToLive, Transaction txn, int compression, boolean isVersioned) AbstractMap constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected SpaceMapEntrybuildEnvelope(Object key, Object value, String cacheID) Build Envelope using ClientUIDHandler utility class and adds the version if needed.The get method will return, from the cache, the object associated with the argument "key".Returns the object that is associated withkeyin this cache.get(Object key, Transaction txn, long waitForResponse, int readModifiers) Returns the object that is associated withkeyin this cache.getAll(Collection keys) The getAll method will return, from the cache, a Map of the objects associated with the Collection of keys in argument "keys".final IJSpaceReturns the Local Space proxy if exists.final IJSpaceReturns the Master Space proxy.final longReturns how long cached objects will live in the cache.final TransactionReturns active transaction ornullif no transaction defined.final longReturns how long wait for response for theIMap.put(java.lang.Object, java.lang.Object, long),IMap.get(java.lang.Object, long)andIMap.remove(java.lang.Object, long)calls.protected abstract ObjectinternalGet(Object key, Transaction txn, long waitForResponse, int readModifiers) Gets the mapping for this key from this map if it is present.protected abstract ObjectinternalPut(Object key, Object value, Transaction txn, long timeToLive, long timeout) protected abstract ObjectinternalRemove(Object key, Transaction txn, long waitForResponse) Removes the mapping for this key from this map if it is present.final booleanisEmpty()Return true if entrySet().isEmpty() return true.final booleanCheck if using optimistic locking.voidThe load method provides a means to "pre load" the cache.voidloadAll(Collection keys) The loadAll method provides a means to "pre load" objects into the cache.protected voidprotected voidfinal ObjectThe put method adds the object "value" to the cache identified by the object "key".final ObjectPutsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.Putsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.final Objectput(Object key, Object value, Transaction txn, long timeToLive) Putsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.final Objectput(Object key, Object value, Transaction txn, long timeToLive, long timeout) Putsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.voidCopies all of the mappings from the specified map to the cache.voidputAll(Map map, Transaction txn, long timeToLive) Copies all of the mappings from the specified map to the cache.The remove method will delete the object from the cache including the key, the associated value and the associated CacheStatistics object.Removes the mapping for thiskeyfrom this cache.remove(Object key, Transaction txn, long waitForResponse) Removes the mapping for thiskeyfrom this cache.final voidsetTimeToLive(long millisecond) Sets the duration that entries will stay in the cache.final voidsetTransaction(Transaction transaction) Set current transaction, all the map calls will be performed under this transaction.final voidsetVersioned(boolean versioned) Sets optimistic locking mode.final voidsetWaitForResponse(long timeout) Sets the timeout for theIMap.put(java.lang.Object, java.lang.Object, long),IMap.get(java.lang.Object, long)andIMap.remove(java.lang.Object, long)calls to wait for response.intsize()Returns the size of this map.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.j_spaces.javax.cache.Cache
addListener, clear, containsKey, containsValue, entrySet, equals, evict, getCacheEntry, hashCode, keySet, peek, removeListener, valuesMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
NONE_COMPRESSION
public static final int NONE_COMPRESSION- See Also:
-
ZIP_COMPRESSION
public static final int ZIP_COMPRESSION- See Also:
-
_transaction
-
_timeToLive
protected long _timeToLive -
_timeout
protected long _timeout -
_spaceProxy
-
_compression
-
_isVersioned
protected boolean _isVersioned -
_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 forvalueobject in cache.txn- if notnullall operation will be executed with the desired transaction.compression- NONE = 0 , ZIP = 1isVersioned-trueif 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:
setVersionedin interfaceIMap- Parameters:
versioned-trueif optimistic locking is needed
-
isVersioned
public final boolean isVersioned()Check if using optimistic locking.- Specified by:
isVersionedin interfaceIMap- Returns:
trueif using optimistic locking
-
setTimeToLive
public final void setTimeToLive(long millisecond) Sets the duration that entries will stay in the cache.- Specified by:
setTimeToLivein interfaceIMap- 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:
getTimeToLivein interfaceIMap- Returns:
- how long entries will live in the cache, in milliseconds
-
setWaitForResponse
public final void setWaitForResponse(long timeout) Sets the timeout for theIMap.put(java.lang.Object, java.lang.Object, long),IMap.get(java.lang.Object, long)andIMap.remove(java.lang.Object, long)calls to wait for response.- Specified by:
setWaitForResponsein interfaceIMap- Parameters:
timeout- time to wait for response
-
getWaitForResponse
public final long getWaitForResponse()Returns how long wait for response for theIMap.put(java.lang.Object, java.lang.Object, long),IMap.get(java.lang.Object, long)andIMap.remove(java.lang.Object, long)calls.- Specified by:
getWaitForResponsein interfaceIMap- 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 thevalue.value- object(~ entry)txn- transactiontimeToLive- 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
The put method adds the object "value" to the cache identified by the object "key". -
put
Putsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache. -
put
Description copied from interface:IMapPutsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache. -
put
Description copied from interface:IMapPutsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.- Specified by:
putin interfaceIMap- Parameters:
key- key for thevaluevalue- object(~ entry)txn- the transaction object, if any, under which to perform the puttimeToLive- 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
Putsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.- Specified by:
putin interfaceIMap- Parameters:
key- key for thevaluevalue- object(~ entry)txn- the transaction object, if any, under which to perform the puttimeToLive- time to keep object in this cache, in millisecondstimeout- time to wait for response- Returns:
- previous value associated with specified key, or null if there was no mapping for key.
-
putAll
Copies all of the mappings from the specified map to the cache. -
putAll
Copies all of the mappings from the specified map to the cache. -
getAll
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:
getAllin interfaceCache- 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
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. -
get
Returns the object that is associated withkeyin this cache. Client will wait at mostwaitForResponsemilliseconds for get call to return. -
get
Returns the object that is associated withkeyin this cache. Client will wait at mostwaitForResponsemilliseconds for get call to return.- Specified by:
getin interfaceIMap- Parameters:
key- key whose associated value is to be returned.txn- the transaction object, if any, under which to perform the getwaitForResponse- time to wait for responsereadModifiers- one or a union ofReadModifiers.- 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. -
isEmpty
public final boolean isEmpty()Return true if entrySet().isEmpty() return true. -
remove
The remove method will delete the object from the cache including the key, the associated value and the associated CacheStatistics object. -
remove
Removes the mapping for thiskeyfrom this cache. Client will wait at mostwaitForResponsemilliseconds for get call to return. -
remove
Removes the mapping for thiskeyfrom this cache. Client will wait at mostwaitForResponsemilliseconds for get call to return. -
setTransaction
Set current transaction, all the map calls will be performed under this transaction. Setting tonullwill turn all the following map calls to be with transaction. In order toIMap 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:
setTransactionin interfaceIMap- Parameters:
transaction- active transaction ornull
-
getTransaction
Returns active transaction ornullif no transaction defined.- Specified by:
getTransactionin interfaceIMap- Returns:
- Transaction
-
load
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:
loadin interfaceCache- Parameters:
key- key whose associated value is to be loaded.- Throws:
CacheException- error accord while loading
-
loadAll
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:
loadAllin interfaceCache- 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
Returns the Master Space proxy.- Specified by:
getMasterSpacein interfaceIMap- Returns:
- the master space proxy
-
getLocalSpace
Returns the Local Space proxy if exists.- Specified by:
getLocalSpacein interfaceIMap- Returns:
- the local space proxy
-
buildEnvelope
Build Envelope using ClientUIDHandler utility class and adds the version if needed. -
log
-
log
-