Package org.apache.groovy.internal.util
Class ReevaluatingReference<T>
java.lang.Object
org.apache.groovy.internal.util.ReevaluatingReference<T>
This class represents a reference to the most actual incarnation of a Metaclass.
INTERNAL USE ONLY.
-
Constructor Summary
ConstructorsConstructorDescriptionReevaluatingReference(Class clazz, Supplier<T> valueSupplier, Function<T, SwitchPoint> validationSupplier) Stores the suppliers and a weak reference toclazz, then loads the first payload. -
Method Summary
-
Constructor Details
-
ReevaluatingReference
public ReevaluatingReference(Class clazz, Supplier<T> valueSupplier, Function<T, SwitchPoint> validationSupplier) Stores the suppliers and a weak reference toclazz, then loads the first payload.valueSuppliersupplies it andvalidationSuppliersupplies theSwitchPointthat guards the cached handle. Invalidating that switch point makes the nextgetPayload()load a replacement.- Parameters:
clazz- payload class passed toMethodHandles.constant; held only weaklyvalueSupplier- supplies a payload, including the one loaded nowvalidationSupplier- supplies the switch point for a payload
-
-
Method Details
-
getPayload
Returns the payload from the guarded handle. When the switch point has been invalidated, the fallback loads a new payload, installs a new guarded handle, and returns that payload. A payload may benullwhen the supplier returns null. Any throwable from the handle is rethrown unchecked.- Returns:
- the current payload
-