GigaSpaces - Open Spaces

org.openspaces.core
Class DefaultGigaMap

java.lang.Object
  extended by org.openspaces.core.DefaultGigaMap
All Implemented Interfaces:
com.j_spaces.javax.cache.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(com.j_spaces.map.IMap map, TransactionProvider txProvider, ExceptionTranslator exTranslator, int defaultIsolationLevel)
          Constructs a new DefaultGigaMap implementation.
 
Method Summary
 void addListener(com.j_spaces.javax.cache.CacheListener cacheListener)
           
 void clear()
           
 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)
           
 boolean containsValue(Object value)
           
 Set entrySet()
           
 boolean evict(Object key)
           
 Object get(Object 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)
           
 com.j_spaces.javax.cache.CacheEntry getCacheEntry(Object 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.
 com.j_spaces.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()
           
 boolean isLocked(Object key)
          Returns true if the given key is locked.
 Set keySet()
           
 void load(Object key)
           
 void loadAll(Collection keys)
           
 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)
           
 Object put(Object key, Object value)
           
 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.
 void putAll(Map t)
           
 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)
           
 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(com.j_spaces.javax.cache.CacheListener cacheListener)
           
 void setDefaultLockTimeToLive(long defaultLockTimeToLive)
           
 void setDefaultTimeToLive(long defaultTimeToLive)
           
 void setDefaultWaitForResponse(long defaultWaitForResponse)
           
 void setDefaultWaitingForLockTimeout(long defaultWaitingForLockTimeout)
           
 int size()
           
 String toString()
           
 void unlock(Object key)
          Unlocks the given lock on the key
 Collection values()
           
 
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(com.j_spaces.map.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 com.j_spaces.map.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()
Specified by:
size in interface com.j_spaces.javax.cache.Cache
Specified by:
size in interface Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface com.j_spaces.javax.cache.Cache
Specified by:
isEmpty in interface Map

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface com.j_spaces.javax.cache.Cache
Specified by:
containsKey in interface Map

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface com.j_spaces.javax.cache.Cache
Specified by:
containsValue in interface Map

get

public Object get(Object key)
Specified by:
get in interface com.j_spaces.javax.cache.Cache
Specified by:
get in interface Map

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)
Specified by:
put in interface com.j_spaces.javax.cache.Cache
Specified by:
put in interface Map

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,
                  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)
Specified by:
remove in interface com.j_spaces.javax.cache.Cache
Specified by:
remove in interface Map

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)
Specified by:
putAll in interface com.j_spaces.javax.cache.Cache
Specified by:
putAll in interface Map

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()
Specified by:
clear in interface com.j_spaces.javax.cache.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()
Specified by:
keySet in interface com.j_spaces.javax.cache.Cache
Specified by:
keySet in interface Map

values

public Collection values()
Specified by:
values in interface com.j_spaces.javax.cache.Cache
Specified by:
values in interface Map

entrySet

public Set entrySet()
Specified by:
entrySet in interface com.j_spaces.javax.cache.Cache
Specified by:
entrySet in interface Map

addListener

public void addListener(com.j_spaces.javax.cache.CacheListener cacheListener)
Specified by:
addListener in interface com.j_spaces.javax.cache.Cache

evict

public boolean evict(Object key)
Specified by:
evict in interface com.j_spaces.javax.cache.Cache

getAll

public Map getAll(Collection keys)
           throws com.j_spaces.javax.cache.CacheException
Specified by:
getAll in interface com.j_spaces.javax.cache.Cache
Throws:
com.j_spaces.javax.cache.CacheException

getCacheEntry

public com.j_spaces.javax.cache.CacheEntry getCacheEntry(Object key)
Specified by:
getCacheEntry in interface com.j_spaces.javax.cache.Cache

load

public void load(Object key)
          throws com.j_spaces.javax.cache.CacheException
Specified by:
load in interface com.j_spaces.javax.cache.Cache
Throws:
com.j_spaces.javax.cache.CacheException

loadAll

public void loadAll(Collection keys)
             throws com.j_spaces.javax.cache.CacheException
Specified by:
loadAll in interface com.j_spaces.javax.cache.Cache
Throws:
com.j_spaces.javax.cache.CacheException

peek

public Object peek(Object key)
Specified by:
peek in interface com.j_spaces.javax.cache.Cache

removeListener

public void removeListener(com.j_spaces.javax.cache.CacheListener cacheListener)
Specified by:
removeListener in interface com.j_spaces.javax.cache.Cache

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 - Open Spaces

Copyright © GigaSpaces.