at.molindo.utils.concurrent
Class KeyLock<K,V>

java.lang.Object
  extended by at.molindo.utils.concurrent.KeyLock<K,V>

public class KeyLock<K,V>
extends Object


Constructor Summary
KeyLock()
           
 
Method Summary
 int activeCount()
           
 List<K> activeKeys()
           
static
<K,V> KeyLock<K,V>
newKeyLock()
           
protected  void onExisting(K key)
          hook that's called if key is already known.
protected  V replace(V result, Exception ex)
          how to replace already computed results.
 V withLock(K key, Callable<V> callable)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyLock

public KeyLock()
Method Detail

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.