Class DefaultGigaMap
GigaMap interface simplifying the work with JCache and Map
interface on top of the Space.
Provides declarative transactions support (for methods that are by nature transactional, such
as get and put) and the ability to set defaults for both
timeToLive and waitForResponse.
Will also automatically apply the current running transaction isolation level when performing read operations (that in turn are translated into the Space).
- Author:
- kimchy
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultGigaMap(IMap map, TransactionProvider txProvider, ExceptionTranslator exTranslator, int defaultIsolationLevel) Constructs a new DefaultGigaMap implementation. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(CacheListener cacheListener) Add a listener to the list of cache listeners.
Optional, not supported by all the implementations, currently supported only by local cache.voidclear()The clear method will remove all objects from the cache including the key and the associated value.voidclear(boolean clearMaster) The clear method will remove all objects from the cache including the key and the associated value.booleancontainsKey(Object key) Returns true if the cache contains the specified key.booleancontainsValue(Object value) Returns true if this cache maps one or more keys to the specified value.entrySet()Returns a set view of the objects currently contained in the cache.booleanThe evict method will remove object from the cache the matches the provided key.The get method will return, from the cache, the object associated with the argument "key".Returns the object that is associated withkeyin this cache.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".getCacheEntry(Object key) Returns the CacheEntry object associated with the object identified by "key".Returns the current running transaction.longReturns the default time to live of entries in the map.longReturns the default wait for response value for entries in the map.getMap()Returns theIMapused by this GigaMap implementation to delegate different space operations.intGets the isolation level from the current running transaction (enabling the usage of Spring declarative isolation level settings).Returns the transaction provider allowing accessing the current running transaction.booleanisEmpty()Return true if entrySet().isEmpty() return true.booleanReturnstrueif the given key is locked.keySet()Returns a set view of the keys currently contained in the cache.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.Locks the given key for any updates.Locks the given key for any updates.The peek method will return the object associated with "key" if it currently exists (and is valid) in the cache.The put method adds the object "value" to the cache identified by the object "key".Putsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.Putsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.put(Object key, Object value, long timeToLive, LockHandle lockHandle) Putsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.put(Object key, Object value, LockHandle lockHandle) Putsvalueto the cache with specifiedkey.voidCopies all of the mappings from the specified map to the cache.voidCopies all of the mappings from the specified map to the cache.voidputAndUnlock(Object key, Object value) Unlocks the given key and puts the given value in a single operation.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, long waitForResponse, LockHandle lockHandle) Removes the mapping for thiskeyfrom this cache.voidremoveListener(CacheListener cacheListener) Remove a listener from the list of cache listeners.
Optional, not supported by all the implementations, currently supported only by local cachevoidsetDefaultLockTimeToLive(long defaultLockTimeToLive) voidsetDefaultTimeToLive(long defaultTimeToLive) voidsetDefaultWaitForResponse(long defaultWaitForResponse) voidsetDefaultWaitingForLockTimeout(long defaultWaitingForLockTimeout) intsize()Returns the size of this map.toString()voidUnlocks the given lock on the keyvalues()Returns a collection view of the values contained in this cache.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
DefaultGigaMap
public DefaultGigaMap(IMap map, TransactionProvider txProvider, ExceptionTranslator exTranslator, int defaultIsolationLevel) Constructs a new DefaultGigaMap implementation.- Parameters:
map- The map implementation to delegate operations totxProvider- The transaction provider for declarative transaction ex.exTranslator- Exception translator to translate low level exceptions into GigaSpaces runtime exception
-
-
Method Details
-
setDefaultWaitForResponse
public void setDefaultWaitForResponse(long defaultWaitForResponse) -
setDefaultTimeToLive
public void setDefaultTimeToLive(long defaultTimeToLive) -
setDefaultLockTimeToLive
public void setDefaultLockTimeToLive(long defaultLockTimeToLive) -
setDefaultWaitingForLockTimeout
public void setDefaultWaitingForLockTimeout(long defaultWaitingForLockTimeout) -
getMap
Description copied from interface:GigaMapReturns theIMapused by this GigaMap implementation to delegate different space operations.Allows to execute map operations that are not exposed by this interface, as well as using it as a parameter to other low level GigaSpace components.
If a transaction object is required for low level operations (as low level operations do not have declarative transaction ex) the
GigaMap.getTxProvider()should be used to acquire the current running transaction. -
getTxProvider
Description copied from interface:GigaMapReturns the transaction provider allowing accessing the current running transaction. Allows to execute low levelIMapoperations that requires explicit transaction object.- Specified by:
getTxProviderin interfaceGigaMap
-
size
public int size()Description copied from interface:CacheReturns 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 boolean isEmpty()Description copied from interface:CacheReturn true if entrySet().isEmpty() return true. -
containsKey
Description copied from interface:CacheReturns 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:
containsKeyin interfaceCache- Specified by:
containsKeyin interfaceMap- Parameters:
key- key whose presence in this cache is to be tested.- Returns:
true, if the cache contains the specified key.
-
containsValue
Description copied from interface:CacheReturns 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:
containsValuein interfaceCache- Specified by:
containsValuein interfaceMap- Parameters:
value- value whose presence in this cache is to be tested.- Returns:
true, if the cache contains the specified value.
-
get
Description copied from interface:CacheThe 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
Description copied from interface:GigaMapReturns the object that is associated withkeyin this cache. Client will wait at mostwaitForResponsemilliseconds for get call to return. -
get
Description copied from interface:GigaMapReturns the object that is associated withkeyin this cache. Client will wait at mostwaitForResponsemilliseconds for get call to return.- Specified by:
getin interfaceGigaMap- Parameters:
key- key whose associated value is to be returned.waitForResponse- time to wait for responsemodifiers- one or a union ofReadModifiers.- Returns:
- Returns the object that is associated with the key
-
put
Description copied from interface:CacheThe put method adds the object "value" to the cache identified by the object "key". -
put
Description copied from interface:GigaMapPutsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache. -
put
Description copied from interface:GigaMapPutsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.- Specified by:
putin interfaceGigaMap- Parameters:
key- key for thevaluevalue- object(~ entry)timeToLive- time to keep object in this cache, in millisecondstimeout- A timeout to use if the object is locked under a transaction (in milliseconds)- Returns:
- previous value associated with specified key, or null if there was no mapping for key.
-
put
Description copied from interface:GigaMapPutsvalueto the cache with specifiedkey. -
put
Description copied from interface:GigaMapPutsvalueto the cache with specifiedkeyfortimeToLivemilliseconds to live in the cache.- Specified by:
putin interfaceGigaMap- Parameters:
key- key for thevaluevalue- object(~ entry)timeToLive- time to keep object in this cache, in millisecondslockHandle- If the key is locked, will perform the operation within the same lock- Returns:
- previous value associated with specified key, or null if there was no mapping for key.
-
remove
Description copied from interface:CacheThe remove method will delete the object from the cache including the key, the associated value and the associated CacheStatistics object. -
remove
Description copied from interface:GigaMapRemoves the mapping for thiskeyfrom this cache. Client will wait at mostwaitForResponsemilliseconds for get call to return. -
remove
Description copied from interface:GigaMapRemoves the mapping for thiskeyfrom this cache. Client will wait at mostwaitForResponsemilliseconds for get call to return. -
putAll
Description copied from interface:CacheCopies all of the mappings from the specified map to the cache. -
putAll
Description copied from interface:GigaMapCopies all of the mappings from the specified map to the cache. -
clear
public void clear()Description copied from interface:CacheThe clear method will remove all objects from the cache including the key and the associated value. -
clear
public void clear(boolean clearMaster) Description copied from interface:GigaMapThe clear method will remove all objects from the cache including the key and the associated value.- Specified by:
clearin interfaceGigaMap- Parameters:
clearMaster- iftrueclear also master, whenfalsesame asMap.clear().)
-
keySet
Description copied from interface:CacheReturns 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. -
values
Description copied from interface:CacheReturns 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. -
entrySet
Description copied from interface:CacheReturns 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. -
addListener
Description copied from interface:CacheAdd a listener to the list of cache listeners.
Optional, not supported by all the implementations, currently supported only by local cache.- Specified by:
addListenerin interfaceCache- Parameters:
cacheListener- call backCacheListener
-
evict
Description copied from interface:CacheThe evict method will remove object from the cache the matches the provided key. -
getAll
Description copied from interface:CacheThe 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
-
getCacheEntry
Description copied from interface:CacheReturns the CacheEntry object associated with the object identified by "key".- Specified by:
getCacheEntryin interfaceCache- 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
Description copied from interface:CacheThe 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
Description copied from interface:CacheThe 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
-
peek
Description copied from interface:CacheThe 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. -
removeListener
Description copied from interface:CacheRemove a listener from the list of cache listeners.
Optional, not supported by all the implementations, currently supported only by local cache- Specified by:
removeListenerin interfaceCache- Parameters:
cacheListener- theCacheListenerto remove
-
getCurrentTransaction
Description copied from interface:GigaMapReturns the current running transaction. Can benullif no transaction is in progress.- Specified by:
getCurrentTransactionin interfaceGigaMap
-
lock
Description copied from interface:GigaMapLocks the given key for any updates. Returns aLockHandlethat can be bused to perform specific updates under the same lock (by callingGigaMap.put(Object, Object, org.openspaces.core.map.LockHandle)for example).Will use the configured default lock time to live and default waiting for lock timeout values. By default the lock time to live is 60 seconds and waiting for lock timeout is 10 seconds.
-
lock
Description copied from interface:GigaMapLocks the given key for any updates. Returns aLockHandlethat can be used to perform specific updates under the same lock (by using the transaction object stored within it). -
unlock
Description copied from interface:GigaMapUnlocks the given lock on the key -
isLocked
Description copied from interface:GigaMapReturnstrueif the given key is locked. Otherwise returnsfalse. -
putAndUnlock
Description copied from interface:GigaMapUnlocks the given key and puts the given value in a single operation.- Specified by:
putAndUnlockin interfaceGigaMap- Parameters:
key- The key to unlock and put the value invalue- The value to put after unlocking the key
-
getDefaultTimeToLive
public long getDefaultTimeToLive()Description copied from interface:GigaMapReturns the default time to live of entries in the map.- Specified by:
getDefaultTimeToLivein interfaceGigaMap
-
getDefaultWaitForResponse
public long getDefaultWaitForResponse()Description copied from interface:GigaMapReturns the default wait for response value for entries in the map.- Specified by:
getDefaultWaitForResponsein interfaceGigaMap
-
getModifiersForIsolationLevel
public int getModifiersForIsolationLevel()Gets the isolation level from the current running transaction (enabling the usage of Spring declarative isolation level settings). If there is no transaction in progress or the transaction isolation isTransactionDefinition.ISOLATION_DEFAULTwill use the default isolation level associated with this class (which isREPEATABLE_READ). -
toString
-