GigaSpaces XAP 7.0 API

org.openspaces.core
Class DefaultGigaMap

java.lang.Object
  extended by org.openspaces.core.DefaultGigaMap
All Implemented Interfaces:
Cache, Map, GigaMap

public class DefaultGigaMap
extends Object
implements GigaMap

An implementation of the 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

Constructor Summary
DefaultGigaMap(IMap map, TransactionProvider txProvider, ExceptionTranslator exTranslator, int defaultIsolationLevel)
          Constructs a new DefaultGigaMap implementation.
 
Method Summary
 void addListener(CacheListener cacheListener)
          Add a listener to the list of cache listeners.
 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".
 net.jini.core.transaction.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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.j_spaces.javax.cache.Cache
equals, hashCode
 

Constructor Detail

DefaultGigaMap

public DefaultGigaMap(IMap map,
                      TransactionProvider txProvider,
                      ExceptionTranslator exTranslator,
                      int defaultIsolationLevel)
Constructs a new DefaultGigaMap implementation.

Parameters:
map - The map implementation to delegate operations to
txProvider - The transaction provider for declarative transaction ex.
exTranslator - Exception translator to translate low level exceptions into GigaSpaces runtime exception
Method Detail

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

public IMap getMap()
Description copied from interface: GigaMap
Returns the 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.

Specified by:
getMap in interface GigaMap

getTxProvider

public TransactionProvider getTxProvider()
Description copied from interface: GigaMap
Returns the transaction provider allowing accessing the current running transaction. Allows to execute low level IMap operations that requires explicit transaction object.

Specified by:
getTxProvider in interface GigaMap

size

public int size()
Description copied from interface: Cache
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 boolean isEmpty()
Description copied from interface: Cache
Return true if entrySet().isEmpty() return true.

Specified by:
isEmpty in interface Cache
Specified by:
isEmpty in interface Map
Returns:
true if empty

containsKey

public boolean containsKey(Object key)
Description copied from interface: Cache
Returns 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:
containsKey in interface Cache
Specified by:
containsKey in interface Map
Parameters:
key - key whose presence in this cache is to be tested.
Returns:
true, if the cache contains the specified key.

containsValue

public boolean containsValue(Object value)
Description copied from interface: Cache
Returns 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:
containsValue in interface Cache
Specified by:
containsValue in interface Map
Parameters:
value - value whose presence in this cache is to be tested.
Returns:
true, if the cache contains the specified value.

get

public Object get(Object key)
Description copied from interface: Cache
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)
Description copied from interface: GigaMap
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 GigaMap
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,
                  long waitForResponse,
                  int modifiers)
Description copied from interface: GigaMap
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 GigaMap
Parameters:
key - key whose associated value is to be returned.
waitForResponse - time to wait for response
modifiers - one or a union of ReadModifiers.
Returns:
Returns the object that is associated with the key

put

public Object put(Object key,
                  Object value)
Description copied from interface: Cache
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 Object put(Object key,
                  Object value,
                  long timeToLive)
Description copied from interface: GigaMap
Puts value to the cache with specified key for timeToLive milliseconds to live in the cache.

Specified by:
put in interface GigaMap
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: GigaMap
Puts value to the cache with specified key for timeToLive milliseconds to live in the cache.

Specified by:
put in interface GigaMap
Parameters:
key - key for the value
value - object(~ entry)
timeToLive - time to keep object in this cache, in milliseconds
timeout - 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

public Object put(Object key,
                  Object value,
                  LockHandle lockHandle)
Description copied from interface: GigaMap
Puts value to the cache with specified key.

Specified by:
put in interface GigaMap
Parameters:
key - key for the value
value - object(~ entry)
lockHandle - 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.

put

public Object put(Object key,
                  Object value,
                  long timeToLive,
                  LockHandle lockHandle)
Description copied from interface: GigaMap
Puts value to the cache with specified key for timeToLive milliseconds to live in the cache.

Specified by:
put in interface GigaMap
Parameters:
key - key for the value
value - object(~ entry)
timeToLive - time to keep object in this cache, in milliseconds
lockHandle - 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

public Object remove(Object key)
Description copied from interface: Cache
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)
Description copied from interface: GigaMap
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 GigaMap
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,
                     long waitForResponse,
                     LockHandle lockHandle)
Description copied from interface: GigaMap
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 GigaMap
Parameters:
key - key whose associated value is to be returned.
waitForResponse - time to wait for response
lockHandle - If the key is locked, will perform the operation within the same lock
Returns:
The removed object

putAll

public void putAll(Map t)
Description copied from interface: Cache
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:
t - A map of key and values to be copy into the cache

putAll

public void putAll(Map t,
                   long timeToLive)
Description copied from interface: GigaMap
Copies all of the mappings from the specified map to the cache.

Specified by:
putAll in interface GigaMap
Parameters:
t - A map of key and values to be copy into the cache

clear

public void clear()
Description copied from interface: Cache
The clear method will remove all objects from the cache including the key and the associated value.

Specified by:
clear in interface Cache
Specified by:
clear in interface Map

clear

public void clear(boolean clearMaster)
Description copied from interface: GigaMap
The clear method will remove all objects from the cache including the key and the associated value.

Specified by:
clear in interface GigaMap
Parameters:
clearMaster - if true clear also master, when false same as Map.clear().)

keySet

public Set keySet()
Description copied from interface: Cache
Returns 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.

Specified by:
keySet in interface Cache
Specified by:
keySet in interface Map
Returns:
set of the keys

values

public Collection values()
Description copied from interface: Cache
Returns 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.

Specified by:
values in interface Cache
Specified by:
values in interface Map
Returns:
a collection view of the values contained in this cache.

entrySet

public Set entrySet()
Description copied from interface: Cache
Returns 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.

Specified by:
entrySet in interface Cache
Specified by:
entrySet in interface Map
Returns:
a set of CacheEntry

addListener

public void addListener(CacheListener cacheListener)
Description copied from interface: Cache
Add a listener to the list of cache listeners.
Optional, not supported by all the implementations, currently supported only by local cache.

Specified by:
addListener in interface Cache
Parameters:
cacheListener - call back CacheListener

evict

public boolean evict(Object key)
Description copied from interface: Cache
The evict method will remove object from the cache the matches the provided key.

Specified by:
evict in interface Cache
Parameters:
key - the key to evict
Returns:
true, if the key was evicted

getAll

public Map getAll(Collection keys)
           throws CacheException
Description copied from interface: Cache
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

getCacheEntry

public CacheEntry getCacheEntry(Object key)
Description copied from interface: Cache
Returns the CacheEntry object associated with the object identified by "key".

Specified by:
getCacheEntry in interface Cache
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

public void load(Object key)
          throws CacheException
Description copied from interface: Cache
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
Description copied from interface: Cache
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

peek

public Object peek(Object key)
Description copied from interface: Cache
The 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.

Specified by:
peek in interface Cache
Parameters:
key - key whose associated value is to be peek.
Returns:
the value to which this cache maps the specified key, or null if the cache contains no mapping for this key.

removeListener

public void removeListener(CacheListener cacheListener)
Description copied from interface: Cache
Remove a listener from the list of cache listeners.
Optional, not supported by all the implementations, currently supported only by local cache

Specified by:
removeListener in interface Cache
Parameters:
cacheListener - the CacheListener to remove

getCurrentTransaction

public net.jini.core.transaction.Transaction getCurrentTransaction()
Description copied from interface: GigaMap
Returns the current running transaction. Can be null if no transaction is in progress.

Specified by:
getCurrentTransaction in interface GigaMap

lock

public LockHandle lock(Object key)
Description copied from interface: GigaMap
Locks the given key for any updates. Returns a 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.

Specified by:
lock in interface GigaMap
Parameters:
key - The key to lock
Returns:
LockHandle that can be used to perform operations under the given lock

lock

public LockHandle lock(Object key,
                       long lockTimeToLive,
                       long waitingForLockTimeout)
Description copied from interface: GigaMap
Locks the given key for any updates. Returns a LockHandle that can be used to perform specific updates under the same lock (by using the transaction object stored within it).

Specified by:
lock in interface GigaMap
Parameters:
key - The key to lock
lockTimeToLive - The lock time to live (in milliseconds)
waitingForLockTimeout - The time to wait for an already locked lock
Returns:
LockHandle that can be used to perform operations under the given lock

unlock

public void unlock(Object key)
Description copied from interface: GigaMap
Unlocks the given lock on the key

Specified by:
unlock in interface GigaMap
Parameters:
key - The key to unlock

isLocked

public boolean isLocked(Object key)
Description copied from interface: GigaMap
Returns true if the given key is locked. Otherwise returns false.

Specified by:
isLocked in interface GigaMap
Parameters:
key - The key to check if it locked or not.
Returns:
true if the given key is locked or not.

putAndUnlock

public void putAndUnlock(Object key,
                         Object value)
Description copied from interface: GigaMap
Unlocks the given key and puts the given value in a single operation.

Specified by:
putAndUnlock in interface GigaMap
Parameters:
key - The key to unlock and put the value in
value - The value to put after unlocking the key

getDefaultTimeToLive

public long getDefaultTimeToLive()
Description copied from interface: GigaMap
Returns the default time to live of entries in the map.

Specified by:
getDefaultTimeToLive in interface GigaMap

getDefaultWaitForResponse

public long getDefaultWaitForResponse()
Description copied from interface: GigaMap
Returns the default wait for response value for entries in the map.

Specified by:
getDefaultWaitForResponse in interface GigaMap

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 is TransactionDefinition.ISOLATION_DEFAULT will use the default isolation level associated with this class (which is REPEATABLE_READ).


toString

public String toString()
Overrides:
toString in class Object

GigaSpaces XAP 7.0 API

Copyright © GigaSpaces.