at.molindo.utils.concurrent
Class KeyLock<K,V>
java.lang.Object
at.molindo.utils.concurrent.KeyLock<K,V>
public class KeyLock<K,V>
- extends Object
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
KeyLock
public KeyLock()
newKeyLock
public static <K,V> KeyLock<K,V> newKeyLock()
withLock
public V withLock(K key,
Callable<V> callable)
throws Exception
- Throws:
Exception
onExisting
protected void onExisting(K key)
throws Exception
- hook that's called if key is already known. does nothing by default
- Throws:
Exception - throw an exception to prevent waiting
replace
protected V replace(V result,
Exception ex)
throws Exception
- how to replace already computed results. by default it's null, as users
might not want to get concurrency issues on shared results. As a
replacement, one could perform a DB lookup if the task is to
create/update a DB entity or do a deep clone of the object.
- Parameters:
result - ex -
- Returns:
-
- Throws:
Exception
activeCount
public int activeCount()
- Returns:
- number of active keys
activeKeys
public List<K> activeKeys()
- Returns:
- a newly created
List of all active keys. Changes to this
list don't have any effect to this KeyLock (changes to the
values will have an undefined effect though).
Copyright © 2011 Molindo GmbH. All Rights Reserved.