java.lang.Object
org.microbean.lang.CompletionLock
A utility class logically containing a single
Lock
that is used to guard against concurrent symbol
completion.
The javax.lang.model.*
classes make no guarantees about thread safety. Certain operations on TypeMirror
and Element
, particularly TypeMirror.getKind()
and Element.getKind()
operations, will
result in symbol completion, which may involve modification of the TypeMirror
or Element
in question. It is imperative that this modification be performed under global lock
if thread safety is to be preserved, and that is the function of this class.
Note that DelegatingTypeMirror
and DelegatingElement
automatically perform such locking, and all operations in Lang
that could result in symbol completion also perform such locking.
- Author:
- Laird Nelson
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic final Lock
acquire()
static final void
static final boolean
Callsacquire()
, thenget()
on the suppliedBooleanSupplier
, thenrelease()
in afinally
block, and returns the result of thegetAsBoolean()
invocation.static final <T> T
static final Lock
release()
-
Method Details
-
acquire
- Returns:
- the locked
Lock
; nevernull
- See Also:
-
release
- Returns:
- the unlocked
Lock
; nevernull
- See Also:
-
guard
Callsacquire()
, thenget()
on the suppliedSupplier
, thenrelease()
in afinally
block, and returns the result of theget()
invocation.- Type Parameters:
T
- the type of the object this method will return- Parameters:
s
- aSupplier
; must not benull
- Returns:
- the result of an invocation of the supplied
Supplier
'sget()
method, which may benull
- Throws:
NullPointerException
- ifs
isnull
-
guard
Callsacquire()
, thenget()
on the suppliedBooleanSupplier
, thenrelease()
in afinally
block, and returns the result of thegetAsBoolean()
invocation.- Parameters:
s
- aBooleanSupplier
; must not benull
- Returns:
- the result of an invocation of the supplied
BooleanSupplier
'sgetAsBoolean()
method - Throws:
NullPointerException
- ifs
isnull
-
guard
- Parameters:
r
- aRunnable
; must not benull
- Throws:
NullPointerException
- ifr
isnull
-