Package org.apache.sis.util.collection
Class Cache.Simple<V>
java.lang.Object
org.apache.sis.util.collection.Cache.Simple<V>
- All Implemented Interfaces:
Cache.Handler<V>
A simple handler implementation wrapping an existing value. This implementation
is used when the value has been fully computed in another thread before this
thread could start its work.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionpeek()
Returns the computed value.void
putAndUnlock
(V result) Do nothing (except checking for programming error), since we don't hold any lock.
-
Field Details
-
value
The result computed in another thread.
-
-
Constructor Details
-
Simple
Simple(V value) Creates a new handler wrapping the given value.
-
-
Method Details
-
peek
Returns the computed value.- Specified by:
peek
in interfaceCache.Handler<V>
- Returns:
- the value from the cache, or
null
if none.
-
putAndUnlock
Do nothing (except checking for programming error), since we don't hold any lock.Implementation note: An alternative would have been to store the result in the map anyway. But doing so is unsafe because we have no lock; we have no guarantee that nothing has happened in another thread betweenpeek
andputAndUnlock
.- Specified by:
putAndUnlock
in interfaceCache.Handler<V>
- Parameters:
result
- the result to store in the cache, ornull
for removing the entry from the cache. If an entry is removed, a new computation will be attempted the next time a handler is created for the same key.- Throws:
IllegalStateException
- may be thrown if this method is not invoked in the pattern described in class javadoc, or if a key collision occurs.
-