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 Lockacquire()static final voidstatic final booleanCallsacquire(), thenget()on the suppliedBooleanSupplier, thenrelease()in afinallyblock, and returns the result of thegetAsBoolean()invocation.static final <T> Tstatic final Lockrelease()
-
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 afinallyblock, 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- ifsisnull
-
guard
Callsacquire(), thenget()on the suppliedBooleanSupplier, thenrelease()in afinallyblock, 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- ifsisnull
-
guard
- Parameters:
r- aRunnable; must not benull- Throws:
NullPointerException- ifrisnull
-