public class DefaultGigaMap extends Object implements GigaMap
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).
Constructor and Description |
---|
DefaultGigaMap(IMap map,
TransactionProvider txProvider,
ExceptionTranslator exTranslator,
int defaultIsolationLevel)
Constructs a new DefaultGigaMap implementation.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(CacheListener cacheListener)
Add a listener to the list of cache listeners.
Optional, not supported by all the implementations, currently supported only by local cache. |
void |
clear()
The clear method will remove all objects from the cache including the key and the associated
value.
|
void |
clear(boolean clearMaster)
The clear method will remove all objects from the cache including the key and the associated
value.
|
boolean |
containsKey(Object key)
Returns true if the cache contains the specified key.
|
boolean |
containsValue(Object value)
Returns true if this cache maps one or more keys to the specified value.
|
Set |
entrySet()
Returns a set view of the objects currently contained in the cache.
|
boolean |
evict(Object key)
The evict method will remove object from the cache the matches the provided key.
|
Object |
get(Object key)
The get method will return, from the cache, the object associated with the argument "key".
|
Object |
get(Object key,
long waitForResponse)
Returns the object that is associated with
key in this cache. |
Object |
get(Object key,
long waitForResponse,
int modifiers)
Returns the object that is associated with
key in this cache. |
Map |
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".
|
CacheEntry |
getCacheEntry(Object key)
Returns the CacheEntry object associated with the object identified by "key".
|
Transaction |
getCurrentTransaction()
Returns the current running transaction.
|
long |
getDefaultTimeToLive()
Returns the default time to live of entries in the map.
|
long |
getDefaultWaitForResponse()
Returns the default wait for response value for entries in the map.
|
IMap |
getMap()
Returns the
IMap used by this GigaMap implementation to delegate different space
operations. |
int |
getModifiersForIsolationLevel()
Gets the isolation level from the current running transaction (enabling the usage of Spring
declarative isolation level settings).
|
TransactionProvider |
getTxProvider()
Returns the transaction provider allowing accessing the current running transaction.
|
boolean |
isEmpty()
Return true if entrySet().isEmpty() return true.
|
boolean |
isLocked(Object key)
Returns
true if the given key is locked. |
Set |
keySet()
Returns a set view of the keys currently contained in the cache.
|
void |
load(Object key)
The load method provides a means to "pre load" the cache.
|
void |
loadAll(Collection keys)
The loadAll method provides a means to "pre load" objects into the cache.
|
LockHandle |
lock(Object key)
Locks the given key for any updates.
|
LockHandle |
lock(Object key,
long lockTimeToLive,
long waitingForLockTimeout)
Locks the given key for any updates.
|
Object |
peek(Object key)
The peek method will return the object associated with "key" if it currently exists (and is
valid) in the cache.
|
Object |
put(Object key,
Object value)
The put method adds the object "value" to the cache identified by the object "key".
|
Object |
put(Object key,
Object value,
LockHandle lockHandle)
Puts
value to the cache with specified key . |
Object |
put(Object key,
Object value,
long timeToLive)
Puts
value to the cache with specified key for
timeToLive milliseconds to live in the cache. |
Object |
put(Object key,
Object value,
long timeToLive,
LockHandle lockHandle)
Puts
value to the cache with specified key for
timeToLive milliseconds to live in the cache. |
Object |
put(Object key,
Object value,
long timeToLive,
long timeout)
Puts
value to the cache with specified key for
timeToLive milliseconds to live in the cache. |
void |
putAll(Map t)
Copies all of the mappings from the specified map to the cache.
|
void |
putAll(Map t,
long timeToLive)
Copies all of the mappings from the specified map to the cache.
|
void |
putAndUnlock(Object key,
Object value)
Unlocks the given key and puts the given value in a single operation.
|
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.
|
Object |
remove(Object key,
long waitForResponse)
Removes the mapping for this
key from this cache. |
Object |
remove(Object key,
long waitForResponse,
LockHandle lockHandle)
Removes the mapping for this
key from this cache. |
void |
removeListener(CacheListener cacheListener)
Remove a listener from the list of cache listeners.
Optional, not supported by all the implementations, currently supported only by local cache |
void |
setDefaultLockTimeToLive(long defaultLockTimeToLive) |
void |
setDefaultTimeToLive(long defaultTimeToLive) |
void |
setDefaultWaitForResponse(long defaultWaitForResponse) |
void |
setDefaultWaitingForLockTimeout(long defaultWaitingForLockTimeout) |
int |
size()
Returns the size of this map.
|
String |
toString() |
void |
unlock(Object key)
Unlocks the given lock on the key
|
Collection |
values()
Returns a collection view of the values contained in this cache.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public DefaultGigaMap(IMap map, TransactionProvider txProvider, ExceptionTranslator exTranslator, int defaultIsolationLevel)
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 exceptionpublic void setDefaultWaitForResponse(long defaultWaitForResponse)
public void setDefaultTimeToLive(long defaultTimeToLive)
public void setDefaultLockTimeToLive(long defaultLockTimeToLive)
public void setDefaultWaitingForLockTimeout(long defaultWaitingForLockTimeout)
public IMap getMap()
GigaMap
IMap
used 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.
public TransactionProvider getTxProvider()
GigaMap
IMap
operations that requires explicit transaction object.getTxProvider
in interface GigaMap
public int size()
Cache
public boolean isEmpty()
Cache
public boolean containsKey(Object key)
Cache
containsKey
in interface Cache
containsKey
in interface Map
key
- key whose presence in this cache is to be tested.true
, if the cache contains the specified key.public boolean containsValue(Object value)
Cache
containsValue
in interface Cache
containsValue
in interface Map
value
- value whose presence in this cache is to be tested.true
, if the cache contains the specified value.public Object get(Object key)
Cache
public Object get(Object key, long waitForResponse)
GigaMap
key
in this cache. Client will wait
at most waitForResponse
milliseconds for get call to return.public Object get(Object key, long waitForResponse, int modifiers)
GigaMap
key
in this cache. Client will wait
at most waitForResponse
milliseconds for get call to return.get
in interface GigaMap
key
- key whose associated value is to be returned.waitForResponse
- time to wait for responsemodifiers
- one or a union of ReadModifiers
.public Object put(Object key, Object value)
Cache
public Object put(Object key, Object value, long timeToLive)
GigaMap
value
to the cache with specified key
for
timeToLive
milliseconds to live in the cache.public Object put(Object key, Object value, long timeToLive, long timeout)
GigaMap
value
to the cache with specified key
for
timeToLive
milliseconds to live in the cache.put
in interface GigaMap
key
- key for the value
value
- 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)public Object put(Object key, Object value, LockHandle lockHandle)
GigaMap
value
to the cache with specified key
.public Object put(Object key, Object value, long timeToLive, LockHandle lockHandle)
GigaMap
value
to the cache with specified key
for
timeToLive
milliseconds to live in the cache.put
in interface GigaMap
key
- key for the value
value
- object(~ entry)timeToLive
- time to keep object in this cache, in millisecondslockHandle
- If the key is locked, will perform the operation within the same lockpublic Object remove(Object key)
Cache
public Object remove(Object key, long waitForResponse)
GigaMap
key
from this cache. Client will wait at most
waitForResponse
milliseconds for get call to return.public Object remove(Object key, long waitForResponse, LockHandle lockHandle)
GigaMap
key
from this cache. Client will wait at most
waitForResponse
milliseconds for get call to return.public void putAll(Map t)
Cache
public void putAll(Map t, long timeToLive)
GigaMap
public void clear()
Cache
public void clear(boolean clearMaster)
GigaMap
clear
in interface GigaMap
clearMaster
- if true
clear also master, when false
same as
Map.clear()
.)public Set keySet()
Cache
public Collection values()
Cache
public Set entrySet()
Cache
public void addListener(CacheListener cacheListener)
Cache
addListener
in interface Cache
cacheListener
- call back CacheListener
public boolean evict(Object key)
Cache
public Map getAll(Collection keys) throws CacheException
Cache
getAll
in interface Cache
keys
- keys whose associated values are to be returned.CacheException
- error accord while loadingpublic CacheEntry getCacheEntry(Object key)
Cache
getCacheEntry
in interface Cache
key
- key whose associated value is to be returned.public void load(Object key) throws CacheException
Cache
load
in interface Cache
key
- key whose associated value is to be loaded.CacheException
- error accord while loadingpublic void loadAll(Collection keys) throws CacheException
Cache
loadAll
in interface Cache
keys
- keys' Collection whose associated value to be loaded using the associated
CacheLoader if this cache doesn't contain it.CacheException
- error accord while loadingpublic Object peek(Object key)
Cache
public void removeListener(CacheListener cacheListener)
Cache
removeListener
in interface Cache
cacheListener
- the CacheListener
to removepublic Transaction getCurrentTransaction()
GigaMap
null
if no transaction is in
progress.getCurrentTransaction
in interface GigaMap
public LockHandle lock(Object key)
GigaMap
LockHandle
that can be bused to perform specific updates under the same lock (by calling GigaMap.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.
public LockHandle lock(Object key, long lockTimeToLive, long waitingForLockTimeout)
GigaMap
LockHandle
that can be used to perform specific updates under the same lock (by using the transaction
object stored within it).public void unlock(Object key)
GigaMap
public boolean isLocked(Object key)
GigaMap
true
if the given key is locked. Otherwise returns false
.public void putAndUnlock(Object key, Object value)
GigaMap
putAndUnlock
in interface GigaMap
key
- The key to unlock and put the value invalue
- The value to put after unlocking the keypublic long getDefaultTimeToLive()
GigaMap
getDefaultTimeToLive
in interface GigaMap
public long getDefaultWaitForResponse()
GigaMap
getDefaultWaitForResponse
in interface GigaMap
public int getModifiersForIsolationLevel()
TransactionDefinition.ISOLATION_DEFAULT
will use the default isolation level associated with this class (which is
REPEATABLE_READ
).Copyright © GigaSpaces.