public class ManagedLocks extends Object
ManagedLock
and ManagedLock.ReadWrite instances.
Also contains factory methods for getting striping functions for these as
well.
All Parameters and returns values do no allow nulls. All supplied
functions should not allow null values are permit null
returns.
Several methods take stripe functions. These functions should return the same
value for the life of their input, i.e. they should be based on immutable
properties of the input value - otherwise the stripe function might point to
a different lock depending on the state of the input. Whatever they return
will be used as a map key, so it should be a good candidate for a map key,
i.e. correctly implement Object.hashCode() and
Object.equals(Object) and be immutable.
| Modifier and Type | Method and Description |
|---|---|
static ManagedLock |
manage(Lock lock)
Get a
ManagedLock that manages the
supplied Lock. |
static ManagedLock.ReadWrite |
manageReadWrite(ReadWriteLock lock)
Get a
ManagedLock.ReadWrite that
manages the supplied ReadWriteLock. |
static ManagedLock |
newManagedLock()
Get a
ManagedLock that manages a
ReentrantLock. |
static <T> Function<T,ManagedLock> |
weakManagedLockFactory()
Convenience method that calls
weakManagedLockFactory(Function)
using the identity function
for striping, essentially meaning that unique input will have its own lock. |
static <T,D> Function<T,ManagedLock> |
weakManagedLockFactory(Function<T,D> stripeFunction)
Convenience method that simply calls
weakManagedLockFactory(Function, Supplier) with the
lockFactory default lock factory. |
static <T,D> Function<T,ManagedLock> |
weakManagedLockFactory(Function<T,D> stripeFunction,
Supplier<Lock> lockFactory)
Create a
Function for resolving
managed locks . |
static <T> Function<T,ManagedLock.ReadWrite> |
weakReadWriteManagedLockFactory()
A convenience method for calling
weakReadWriteManagedLockFactory(Function) that uses the
identity function for
striping, essentially meaning that unique input will have its own lock. |
static <T,D> Function<T,ManagedLock.ReadWrite> |
weakReadWriteManagedLockFactory(Function<T,D> stripeFunction)
A convenience method for calling
weakReadWriteManagedLockFactory(Function, Supplier) that uses
default locks |
static <T,D> Function<T,ManagedLock.ReadWrite> |
weakReadWriteManagedLockFactory(Function<T,D> stripeFunction,
Supplier<ReadWriteLock> lockFactory)
Create a
Function for resolving
managed read-write locks. |
@NotNull public static ManagedLock manage(@NotNull Lock lock)
ManagedLock that manages the
supplied Lock.lock - the lock to use.@NotNull public static ManagedLock newManagedLock()
ManagedLock that manages a
ReentrantLock.@NotNull public static ManagedLock.ReadWrite manageReadWrite(@NotNull ReadWriteLock lock)
ManagedLock.ReadWrite that
manages the supplied ReadWriteLock.lock - the lock to use.@NotNull public static <T,D> Function<T,ManagedLock> weakManagedLockFactory(@NotNull Function<T,D> stripeFunction, @NotNull Supplier<Lock> lockFactory)
Function for resolving
managed locks . The particular lock is resolved using a
striping Function that is used 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. The locks are stored using weak references
so infrequently accessed locks should not use excess memory.T - the type of the thing used to look up locksD - the type used to map lock instances, should be a good map keystripeFunction - to convert the input to the thing used to look up the
individual lockslockFactory - the factory for creating the individual locksFunction that provides
ManagedLock instances that stores
created instances with weak references.@NotNull public static <T,D> Function<T,ManagedLock> weakManagedLockFactory(@NotNull Function<T,D> stripeFunction)
weakManagedLockFactory(Function, Supplier) with the
lockFactory default lock factory.T - the type of the thing used to look up locksD - the type used to map lock instances, should be a good map keystripeFunction - to convert Ts to Ds.Function.weakManagedLockFactory(Function, Supplier)@NotNull public static <T> Function<T,ManagedLock> weakManagedLockFactory()
weakManagedLockFactory(Function)
using the identity function
for striping, essentially meaning that unique input will have its own lock.T - the type of the thing used to look up locksFunction.weakManagedLockFactory(Function, Supplier)@NotNull public static <T,D> Function<T,ManagedLock.ReadWrite> weakReadWriteManagedLockFactory(@NotNull Function<T,D> stripeFunction, @NotNull Supplier<ReadWriteLock> lockFactory)
Function for resolving
managed read-write locks. The particular lock
is resolved using a striping Function that is
used 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. The locks are stored
using weak references so infrequently accessed locks should not use excess
memory.T - the type of the thing used to look up locksD - the type used to map lock instances, should be a good map keystripeFunction - to convert the input to the thing used to look up the
individual lockslockFactory - the factory for creating the individual locksFunction that provides
ManagedLock.ReadWrite instances that
stores created instances with weak references.@NotNull public static <T,D> Function<T,ManagedLock.ReadWrite> weakReadWriteManagedLockFactory(Function<T,D> stripeFunction)
weakReadWriteManagedLockFactory(Function, Supplier) that uses
default locksT - the type of the thing used to look up locksD - the type used to map lock instances, should be a good map keystripeFunction - a Function object.Function that provides
ManagedLock.ReadWrite instances that
stores created instances with weak references.@NotNull public static <T> Function<T,ManagedLock.ReadWrite> weakReadWriteManagedLockFactory()
weakReadWriteManagedLockFactory(Function) that uses the
identity function for
striping, essentially meaning that unique input will have its own lock.T - the type of the thing used to look up locksFunction that provides the
appropriate ManagedLock.ReadWrite for
the argument ManagedLock.ReadWrite
instances that stores created instances with weak references.Copyright © 2024 Atlassian. All rights reserved.