Interface OptimisticNamedCache
-
- All Superinterfaces:
AutoCloseable
,CacheMap
,ConcurrentMap
,InvocableMap
,Map
,NamedCache
,NamedCollection
,NamedMap
,ObservableMap
,QueryMap
,Releasable
public interface OptimisticNamedCache extends NamedCache
An extension to theNamedCache
interface that adds support for optimistic transactions.Each operation has an associated predicate in the form of a Filter that is used to ensure that the value being updated is the expected value. Update and delete operations have explicit predicates where insert has an implicit predicate. Typically when a value is read and later modified in the scope of a transaction, a predicate is supplied to ensure that the value being modified is the same value that was previously read.
When one of the optimistic operations are invoked, the predicate is applied to the latest committed value. If the predicate holds, a write lock is obtained for the row and the value is updated according to the operation. If the predicate fails a
PredicateFailedException
is thrown back to the caller.In addition to the
PredicateFailedException
, all mutating operations may throw aUnableToAcquireLockException
if unable to acquire a write lock.- Since:
- Coherence 3.6
- Author:
- jp, js 2009.2.10
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.tangosol.util.InvocableMap
InvocableMap.Entry<K,V>, InvocableMap.EntryAggregator<K,V,R>, InvocableMap.EntryProcessor<K,V,R>, InvocableMap.ParallelAwareAggregator<K,V,P,R>, InvocableMap.StreamingAggregator<K,V,P,R>
-
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K extends Object,V extends Object>
-
Nested classes/interfaces inherited from interface com.tangosol.net.NamedMap
NamedMap.Option
-
Nested classes/interfaces inherited from interface com.tangosol.util.QueryMap
QueryMap.Entry<K,V>
-
-
Field Summary
-
Fields inherited from interface com.tangosol.net.cache.CacheMap
EXPIRY_DEFAULT, EXPIRY_NEVER
-
Fields inherited from interface com.tangosol.util.ConcurrentMap
LOCK_ALL
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
delete(Object oKey, Filter validator)
Delete an existing value.void
insert(Object oKey, Object oValue)
Insert a new value.boolean
lock(Object oKey)
Locking,ConcurrentMap.lock(Object)
, is currently not available when using a transactional cache.boolean
lock(Object oKey, long cWait)
Locking,ConcurrentMap.lock(Object, long)
, is currently not available when using a transactional cache.Object
put(Object oKey, Object oValue, long cMillis)
Put with expiry,NamedCache.put(Object, Object, long)
, is currently not available when using a transactional cache.boolean
unlock(Object oKey)
Unlocking,ConcurrentMap.unlock(Object)
, is currently not available when using a transactional cache.void
update(Object oKey, Object oValue, Filter validator)
Update an existing value.-
Methods inherited from interface com.tangosol.util.ConcurrentMap
containsKey, containsValue, get, isEmpty, put, putAll, remove, size
-
Methods inherited from interface com.tangosol.util.InvocableMap
aggregate, aggregate, aggregate, compute, compute, computeIfAbsent, computeIfAbsent, computeIfPresent, computeIfPresent, getOrDefault, invoke, invokeAll, invokeAll, invokeAll, merge, merge, putIfAbsent, remove, replace, replace, replaceAll, replaceAll, replaceAll, replaceAll, stream, stream, stream, stream, stream, stream
-
Methods inherited from interface com.tangosol.net.NamedCache
as, async, async, forEach, getCacheName, getCacheService, view
-
Methods inherited from interface com.tangosol.net.NamedCollection
destroy, isDestroyed
-
Methods inherited from interface com.tangosol.net.NamedMap
clear, getAll, getName, getService, isActive, isReady, truncate
-
Methods inherited from interface com.tangosol.util.ObservableMap
addMapListener, addMapListener, addMapListener, removeMapListener, removeMapListener, removeMapListener
-
Methods inherited from interface com.tangosol.util.QueryMap
addIndex, addIndex, entrySet, entrySet, forEach, forEach, keySet, removeIndex, values, values
-
Methods inherited from interface com.tangosol.net.Releasable
close, isReleased, release
-
-
-
-
Method Detail
-
update
void update(Object oKey, Object oValue, Filter validator)
Update an existing value.- Parameters:
oKey
- identifies the entry to updateoValue
- the new valuevalidator
- predicate used to ensure that the value being updated is the expected value. A null predicate will not check the current value or even that it exists.- Throws:
PredicateFailedException
- if the predicate failsUnableToAcquireLockException
- if unable to acquire a write lock
-
delete
void delete(Object oKey, Filter validator)
Delete an existing value.- Parameters:
oKey
- identifies the entry to deletevalidator
- predicate used to ensure that the value being removed is the expected value. A null predicate will not check the current value or even that it exists.- Throws:
PredicateFailedException
- if the predicate failsUnableToAcquireLockException
- if unable to acquire a write lock
-
insert
void insert(Object oKey, Object oValue)
Insert a new value. An implicit predicate is associated with the insert operation to ensure that the entry doesn't already exist.- Parameters:
oKey
- identifies which row to insertoValue
- the value of the inserted row- Throws:
PredicateFailedException
- if the predicate failsUnableToAcquireLockException
- if unable to acquire a write lock
-
put
Object put(Object oKey, Object oValue, long cMillis)
Put with expiry,NamedCache.put(Object, Object, long)
, is currently not available when using a transactional cache.- Specified by:
put
in interfaceCacheMap
- Specified by:
put
in interfaceNamedCache
- Parameters:
oKey
- key with which the specified value is to be associatedoValue
- value to be associated with the specified keycMillis
- the number of milliseconds until the cache entry will expire, also referred to as the entry's "time to live"; passCacheMap.EXPIRY_DEFAULT
to use the cache's default time-to-live setting; passCacheMap.EXPIRY_NEVER
to indicate that the cache entry should never expire; this milliseconds value is not a date/time value, such as is returned from System.currentTimeMillis()- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values
- Throws:
UnsupportedOperationException
- always
-
lock
boolean lock(Object oKey, long cWait)
Locking,ConcurrentMap.lock(Object, long)
, is currently not available when using a transactional cache.- Specified by:
lock
in interfaceConcurrentMap
- Parameters:
oKey
- key being lockedcWait
- the number of milliseconds to continue trying to obtain a lock; pass zero to return immediately; pass -1 to block the calling thread until the lock could be obtained- Returns:
- true if the item was successfully locked within the specified time; false otherwise
- Throws:
UnsupportedOperationException
- always
-
lock
boolean lock(Object oKey)
Locking,ConcurrentMap.lock(Object)
, is currently not available when using a transactional cache.- Specified by:
lock
in interfaceConcurrentMap
- Parameters:
oKey
- key being locked- Returns:
- true if the item was successfully locked; false otherwise
- Throws:
UnsupportedOperationException
- always
-
unlock
boolean unlock(Object oKey)
Unlocking,ConcurrentMap.unlock(Object)
, is currently not available when using a transactional cache.- Specified by:
unlock
in interfaceConcurrentMap
- Parameters:
oKey
- key being unlocked- Returns:
- true if the item was successfully unlocked; false otherwise
- Throws:
UnsupportedOperationException
- always
-
-