Interface OptimisticNamedCache
- All Superinterfaces:
AutoCloseable,CacheMap,ConcurrentMap,InvocableMap,Map,NamedCache,NamedCollection,NamedMap,ObservableMap,QueryMap,Releasable
NamedCache 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 a UnableToAcquireLockException 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 com.tangosol.net.NamedMap
NamedMap.OptionNested 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_NEVERFields inherited from interface com.tangosol.util.ConcurrentMap
LOCK_ALL -
Method Summary
Modifier and TypeMethodDescriptionvoidDelete an existing value.voidInsert a new value.booleanLocking,ConcurrentMap.lock(Object), is currently not available when using a transactional cache.booleanLocking,ConcurrentMap.lock(Object, long), is currently not available when using a transactional cache.Put with expiry,NamedCache.put(Object, Object, long), is currently not available when using a transactional cache.booleanUnlocking,ConcurrentMap.unlock(Object), is currently not available when using a transactional cache.voidUpdate an existing value.Methods inherited from interface com.tangosol.util.ConcurrentMap
containsKey, containsValue, get, isEmpty, put, putAll, remove, sizeMethods 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, streamMethods inherited from interface com.tangosol.net.NamedCache
as, async, async, forEach, getCacheName, getCacheService, viewMethods inherited from interface com.tangosol.net.NamedCollection
destroy, isDestroyedMethods inherited from interface com.tangosol.net.NamedMap
clear, getAll, getName, getService, isActive, isReady, truncateMethods inherited from interface com.tangosol.util.ObservableMap
addMapListener, addMapListener, addMapListener, removeMapListener, removeMapListener, removeMapListenerMethods inherited from interface com.tangosol.util.QueryMap
addIndex, addIndex, entrySet, entrySet, forEach, forEach, keySet, removeIndex, values, valuesMethods inherited from interface com.tangosol.net.Releasable
close, isReleased, release
-
Method Details
-
update
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
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
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
Put with expiry,NamedCache.put(Object, Object, long), is currently not available when using a transactional cache.- Specified by:
putin interfaceCacheMap- Specified by:
putin 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_DEFAULTto use the cache's default time-to-live setting; passCacheMap.EXPIRY_NEVERto 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
Locking,ConcurrentMap.lock(Object, long), is currently not available when using a transactional cache.- Specified by:
lockin 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
Locking,ConcurrentMap.lock(Object), is currently not available when using a transactional cache.- Specified by:
lockin interfaceConcurrentMap- Parameters:
oKey- key being locked- Returns:
- true if the item was successfully locked; false otherwise
- Throws:
UnsupportedOperationException- always
-
unlock
Unlocking,ConcurrentMap.unlock(Object), is currently not available when using a transactional cache.- Specified by:
unlockin interfaceConcurrentMap- Parameters:
oKey- key being unlocked- Returns:
- true if the item was successfully unlocked; false otherwise
- Throws:
UnsupportedOperationException- always
-