Package org.codehaus.groovy.util
Class LazyReference<T>
java.lang.Object
java.util.concurrent.locks.AbstractOwnableSynchronizer
java.util.concurrent.locks.AbstractQueuedSynchronizer
org.codehaus.groovy.util.LockableObject
org.codehaus.groovy.util.LazyReference<T>
- All Implemented Interfaces:
Serializable
Soft reference with lazy initialization under lock
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer
AbstractQueuedSynchronizer.ConditionObject -
Constructor Summary
ConstructorsConstructorDescriptionLazyReference(ReferenceBundle bundle) Creates a lazily initialized reference that stores computed values using the supplied bundle. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Discards the cached state so the nextget()call recomputes it.get()Returns the current value, initializing or recreating it when necessary.abstract TComputes the value to cache for futureget()calls.toString()Returns the current cached value as a string, or<null>when no value is available.Methods inherited from class org.codehaus.groovy.util.LockableObject
isHeldExclusively, lock, tryAcquire, tryRelease, unlockMethods inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer
acquire, acquireInterruptibly, acquireShared, acquireSharedInterruptibly, compareAndSetState, getExclusiveQueuedThreads, getFirstQueuedThread, getQueuedThreads, getQueueLength, getSharedQueuedThreads, getState, getWaitingThreads, getWaitQueueLength, hasContended, hasQueuedPredecessors, hasQueuedThreads, hasWaiters, isQueued, owns, release, releaseShared, setState, tryAcquireNanos, tryAcquireShared, tryAcquireSharedNanos, tryReleaseSharedMethods inherited from class java.util.concurrent.locks.AbstractOwnableSynchronizer
getExclusiveOwnerThread, setExclusiveOwnerThread
-
Constructor Details
-
LazyReference
Creates a lazily initialized reference that stores computed values using the supplied bundle.- Parameters:
bundle- the reference strategy to use after initialization
-
-
Method Details
-
get
Returns the current value, initializing or recreating it when necessary.- Returns:
- the current value, which may be
null
-
clear
public void clear()Discards the cached state so the nextget()call recomputes it. -
initValue
Computes the value to cache for futureget()calls.- Returns:
- the value to cache, or
nullto cache a null result
-
toString
Returns the current cached value as a string, or<null>when no value is available.- Overrides:
toStringin classAbstractQueuedSynchronizer- Returns:
- a string form of the cached value
-