com.atlassian.util.concurrent
Class LockManagers

java.lang.Object
  extended by com.atlassian.util.concurrent.LockManagers

public class LockManagers
extends java.lang.Object

Static factory for producing LockManager instances.


Method Summary
static
<T,D> LockManager<T>
weakLockManager(Function<T,D> stripeFunction)
          Convenience method that simply calls weakLockManager(Function, int) with a default initial capacity of 128.
static
<T,D> LockManager<T>
weakLockManager(Function<T,D> stripeFunction, int initialCapacity)
          The particular Lock is resolved using a Function that resolves to a descriptor used to look up a Lock instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

weakLockManager

public static <T,D> LockManager<T> weakLockManager(Function<T,D> stripeFunction)
Convenience method that simply calls weakLockManager(Function, int) with a default initial capacity of 128.

Type Parameters:
T - the type of the thing used to look up locks
D - the type used to map lock instances
Parameters:
stripeFunction - to convert Ts to Ds.
See Also:
weakLockManager(Function, int)

weakLockManager

public static <T,D> LockManager<T> weakLockManager(Function<T,D> stripeFunction,
                                                   int initialCapacity)
The particular Lock is resolved using a Function that resolves to a descriptor used to look up a Lock instance. This allows for a finite set of locks to be used even if the set of T is essentially unbounded.

For instance:

 LockManager<Identifiable, Integer> manager = LockManagers.weakLockManager(new Function<Identifiable, Integer>() {
     Integer get(Identifiable thing) {
         return thing.getId() % 16;
     }
 };
 
uses only 16 possible locks as the function returns the modulo 16 of the thing's id.

Type Parameters:
T - the type of the thing used to look up locks
D - the type used to map lock instances
Parameters:
stripeFunction - to convert Ts to Ds.
initialCapacity - the initial capacity of the internal map.
Returns:
a new LockManager instance that stores created Lock instances with weak references.


Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.