Package org.apache.sis.util.collection
Class Cache.Work
java.lang.Object
org.apache.sis.internal.system.DelayedRunnable
org.apache.sis.internal.system.DelayedRunnable.Immediate
org.apache.sis.util.collection.Cache.Work
- All Implemented Interfaces:
Comparable<Delayed>
,Runnable
,Delayed
,Supplier<V>
,Cache.Handler<V>
A handler implementation used for telling to other threads that the current thread is
computing a value.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) final class
A handler implementation used when the value is in process of being computed in another thread.Nested classes/interfaces inherited from class org.apache.sis.internal.system.DelayedRunnable
DelayedRunnable.Immediate
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionget()
Waits for the completion of the value computation and returns this result.peek()
Usually returnsnull
since the value is not yet computed.void
putAndUnlock
(V result) Stores the result and release the lock.void
run()
Invoked in a background thread after a value has been set in the map.Methods inherited from class org.apache.sis.internal.system.DelayedRunnable.Immediate
compareTo, getDelay
-
Field Details
-
lock
The synchronization lock. -
key
The key to use for storing the result in the map. -
value
The result. This is initially null, as we expect since the value has not yet been created. When it will get a value, this value should not change anymore.
-
-
Constructor Details
-
Work
Work(K key) Creates a new handler which will store the result in the given map at the given key.
-
-
Method Details
-
get
Waits for the completion of the value computation and returns this result. This method should be invoked only from another thread than the one doing the computation. -
peek
Usually returnsnull
since the value is not yet computed. May returns the result if this method is invoked again after the computation, but this is not the typical use case.- Specified by:
peek
in interfaceCache.Handler<V>
- Returns:
- the value from the cache, or
null
if none.
-
putAndUnlock
Stores the result and release the lock.- 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
- if the current thread does not hold the lock.
-
run
public void run()Invoked in a background thread after a value has been set in the map. This method computes a cost estimation of the new value. If the total cost is greater than the cost limit, then oldest strong references are replaced by weak references.
-