Skip navigation links
com.tangosol.coherence.transaction
Interface OptimisticNamedCache
- All Superinterfaces:
- CacheMap, ConcurrentMap, InvocableMap, java.util.Map, NamedCache, ObservableMap, QueryMap
-
public interface OptimisticNamedCache
- extends NamedCache
An extension to the 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 classes/interfaces inherited from interface java.util.Map |
java.util.Map.Entry |
Method Summary |
void |
delete(java.lang.Object oKey, Filter validator)
Delete an existing value. |
void |
insert(java.lang.Object oKey, java.lang.Object oValue)
Insert a new value. |
boolean |
lock(java.lang.Object oKey)
Locking, ConcurrentMap.lock(Object) , is currently not available when using a transactional cache. |
boolean |
lock(java.lang.Object oKey, long cWait)
Locking, ConcurrentMap.lock(Object, long) , is currently not available when using a transactional cache. |
java.lang.Object |
put(java.lang.Object oKey, java.lang.Object oValue, long cMillis)
Put with expiry, NamedCache.put(Object, Object, long) , is currently not available when using a transactional cache. |
boolean |
unlock(java.lang.Object oKey)
Unlocking, ConcurrentMap.unlock(Object) , is currently not available when using a transactional cache. |
void |
update(java.lang.Object oKey, java.lang.Object oValue, Filter validator)
Update an existing value. |
Methods inherited from interface java.util.Map |
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, values |
update
void update(java.lang.Object oKey,
java.lang.Object oValue,
Filter validator)
- Update an existing value.
-
- Parameters:
oKey
- identifies the entry to update
oValue
- the new value
validator
- 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 fails
UnableToAcquireLockException
- if unable to acquire a write lock
delete
void delete(java.lang.Object oKey,
Filter validator)
- Delete an existing value.
-
- Parameters:
oKey
- identifies the entry to delete
validator
- 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 fails
UnableToAcquireLockException
- if unable to acquire a write lock
insert
void insert(java.lang.Object oKey,
java.lang.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 insert
oValue
- the value of the inserted row
- Throws:
PredicateFailedException
- if the predicate fails
UnableToAcquireLockException
- if unable to acquire a write lock
put
java.lang.Object put(java.lang.Object oKey,
java.lang.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 interface CacheMap
- Specified by:
put
in interface NamedCache
-
- Parameters:
oKey
- key with which the specified value is to be associated
oValue
- value to be associated with the specified key
cMillis
- the number of milliseconds until the cache entry will expire, also referred to as the entry's "time to live"; pass CacheMap.EXPIRY_DEFAULT
to use the cache's default time-to-live setting; pass CacheMap.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:
java.lang.UnsupportedOperationException
- always
lock
boolean lock(java.lang.Object oKey,
long cWait)
- Locking,
ConcurrentMap.lock(Object, long)
, is currently not available when using a transactional cache.
-
- Specified by:
lock
in interface ConcurrentMap
-
- Parameters:
oKey
- key being locked
cWait
- 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:
java.lang.UnsupportedOperationException
- always
lock
boolean lock(java.lang.Object oKey)
- Locking,
ConcurrentMap.lock(Object)
, is currently not available when using a transactional cache.
-
- Specified by:
lock
in interface ConcurrentMap
-
- Parameters:
oKey
- key being locked
- Returns:
- true if the item was successfully locked; false otherwise
- Throws:
java.lang.UnsupportedOperationException
- always
unlock
boolean unlock(java.lang.Object oKey)
- Unlocking,
ConcurrentMap.unlock(Object)
, is currently not available when using a transactional cache.
-
- Specified by:
unlock
in interface ConcurrentMap
-
- Parameters:
oKey
- key being unlocked
- Returns:
- true if the item was successfully unlocked; false otherwise
- Throws:
java.lang.UnsupportedOperationException
- always
Skip navigation links
Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.