Class MapCache
- All Implemented Interfaces:
Cache,IMap,Remote,EventListener,Map,RemoteEventListener,LeaseListener
- Since:
- 5.0
- Version:
- 1.0
- Author:
- Guy Korland
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default number of retires to reconnect to server when fault is discovered.Fields inherited from class com.j_spaces.map.AbstractMap
_compression, _entryInfos, _isVersioned, _spaceProxy, _timeout, _timeToLive, _transaction, NONE_COMPRESSION, ZIP_COMPRESSION -
Constructor Summary
ConstructorsConstructorDescriptionMapCache(IJSpace space, boolean isVersioned, int updateMode, EvictionStrategy evictionStrategy, boolean putFirst, int sizeLimit, int compression) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(CacheListener listener) 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.protected voidfinalize()getCacheEntry(Object key) Returns the CacheEntry object associated with the object identified by "key".protected ObjectinternalGet(Object key, Transaction txn, long waitForResponse, int readModifiers) Gets the mapping for this key from this map if it is present.protected ObjectinternalPut(Object key, Object value, Transaction txn, long timeToLive, long timeout) protected ObjectinternalRemove(Object key, Transaction txn, long waitForResponse) Removes the mapping for this key from this map if it is present.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.voidnotify(RemoteEvent remoteEvent) Notify the listener about an event.voidnotify(LeaseRenewalEvent event) Called by theLeaseRenewalManagerwhen it cannot renew a lease that it is managing, and the lease's desired expiration time has not yet been reached.The peek method will return the object associated with "key" if it currently exists (and is valid) in the cache.voidremoveListener(CacheListener listener) Remove a listener from the list of cache listeners.
Optional, not supported by all the implementations, currently supported only by local cacheintsize()Returns the size of this map.values()Returns a collection view of the values contained in this cache.Methods inherited from class com.j_spaces.map.AbstractMap
buildEnvelope, get, get, get, getAll, getLocalSpace, getMasterSpace, getTimeToLive, getTransaction, getWaitForResponse, isEmpty, isVersioned, log, log, put, put, put, put, put, putAll, putAll, remove, remove, remove, setTimeToLive, setTransaction, setVersioned, setWaitForResponseMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
DEFAULT_MAX_CONNECTION_RETRY
public static final int DEFAULT_MAX_CONNECTION_RETRYThe 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 spaceisVersioned-trueif a version should be kept for the valuesupdateMode-SpaceURL.UPDATE_MODE_PULLorSpaceURL.UPDATE_MODE_PUSHevictionStrategy- eviction strategy to use in CacheputFirst-trueif 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:
internalPutin classAbstractMap- Parameters:
key- key for thevalue.value- object(~ entry)txn- transactiontimeToLive- time to leave in master cache- Returns:
- previous value associated with specified key.
-
size
public int size()Description copied from class:AbstractMapReturns 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. -
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:IMapThe clear method will remove all objects from the cache including the key and the associated value. -
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.
-
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. -
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. -
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:
listener- call backCacheListener
-
evict
Description copied from interface:CacheThe evict method will remove object from the cache the matches the provided key. -
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 class:AbstractMapThe 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- Overrides:
loadin classAbstractMap- Parameters:
key- key whose associated value is to be loaded.- Throws:
CacheException- error accord while loading
-
loadAll
Description copied from class:AbstractMapThe 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- Overrides:
loadAllin classAbstractMap- 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:
listener- theCacheListenerto remove
-
notify
Description copied from interface:RemoteEventListenerNotify 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:
notifyin interfaceRemoteEventListener- Parameters:
remoteEvent- the remote event that occurred- Throws:
UnknownEventException- the recipient does not recognize the combination of event identifier and event sourceRemoteException
-
internalRemove
Description copied from class:AbstractMapRemoves the mapping for this key from this map if it is present.- Specified by:
internalRemovein classAbstractMap- 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
Description copied from class:AbstractMapGets the mapping for this key from this map if it is present.- Specified by:
internalGetin classAbstractMap- 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
Description copied from interface:LeaseListenerCalled by theLeaseRenewalManagerwhen 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
LeaseRenewalManagerremoves the affected lease from the managed set of leases. Note also that, because of the reentrancy guarantee made by theLeaseRenewalManager, new leases can be safely added by this method.- Specified by:
notifyin interfaceLeaseListener- Parameters:
event- instance ofLeaseRenewalEventcontaining information about the lease that theLeaseRenewalManagerwas unable to renew, as well as information about the condition that made theLeaseRenewalManagerfail to renew the lease
-
finalize
-