| Modifier and Type | Class and Description |
|---|---|
| public static interface | Cache.
Key type. K>Should a cycle be detected during computation of a value for given key, this interface allows client code to register a callback that would get invoked in such a case. |
| private class | Cache.
Helper class, that remembers the future task origin thread, so that cycles could be detected. |
| Modifier and Type | Field and Description |
|---|---|
| private final ConcurrentHashMap | |
| private final Computable | |
| private final Cache. | |
| private static final Cache. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | Cache(Computable<K, V> computable, Cache.
Create new cache with given computable and cycle handler. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public V | compute(final K key)
Implements org. Defines an expensive computation to retrieve value V from key K. |
| public boolean | Returns: true if given key is present in the cache.Returns true if the key has already been cached. |
| public void | |
| public int |
| cache | back to summary |
|---|---|
| private final ConcurrentHashMap<K, Cache<K, V>. | |
| computable | back to summary |
|---|---|
| private final Computable<K, V> computable | |
| cycleHandler | back to summary |
|---|---|
| private final Cache. | |
| EMPTY_HANDLER | back to summary |
|---|---|
| private static final Cache. | |
| Cache | back to summary |
|---|---|
| public Cache(Computable<K, V> computable) Create new cache with given computable to compute values. Detected cycles will be ignored as there is a no-op cycle handler registered by default.
| |
| Cache | back to summary |
|---|---|
| public Cache(Computable<K, V> computable, Cache. Create new cache with given computable and cycle handler. | |
| clear | back to summary |
|---|---|
| public void clear() Empty cache. | |
| compute | back to summary |
|---|---|
| public V compute(final K key) Implements org. Doc from org. Defines an expensive computation to retrieve value V from key K.
| |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(final K key) Returns true if the key has already been cached.
| |
| remove | back to summary |
|---|---|
| public void remove(final K key) Remove item from the cache.
| |
| size | back to summary |
|---|---|
| public int size() Returns the size of the cache
| |
| Modifier and Type | Method and Description |
|---|---|
| public void | handleCycle(K
instance that caused the cycle. key)Handle cycle that was detected while computing a cache value for given key. |
| handleCycle | back to summary |
|---|---|
| public void handleCycle(K key) Handle cycle that was detected while computing a cache value for given key. This method would typically just throw a runtime exception.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final FutureTask | |
| private volatile long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | cancel(boolean mayInterruptIfRunning)
Implements java. Attempts to cancel execution of this task. |
| public boolean | equals(Object obj)
Overrides java. Indicates whether some other object is "equal to" this one. |
| public V | get()
Implements java. Waits if necessary for the computation to complete, and then retrieves its result. |
| public V | get(long timeout, TimeUnit unit)
Implements java. Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available. |
| public int | |
| public boolean | isCancelled()
Implements java. Returns |
| public boolean | |
| public void |
| future | back to summary |
|---|---|
| private final FutureTask<V> future | |
| threadId | back to summary |
|---|---|
| private volatile long threadId | |
| OriginThreadAwareFuture | back to summary |
|---|---|
| pack-priv OriginThreadAwareFuture(Cache<K, V> cache, final K key) | |
| cancel | back to summary |
|---|---|
| public boolean cancel(boolean mayInterruptIfRunning) Implements java. Doc from java. Attempts to cancel execution of this task. This method has no
effect if the task is already completed or cancelled, or could
not be cancelled for some other reason. Otherwise, if this
task has not started when The return value from this method does not necessarily
indicate whether the task is now cancelled; use
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| |
| get | back to summary |
|---|---|
| public V get() throws InterruptedException, ExecutionException Implements java. Doc from java. Waits if necessary for the computation to complete, and then retrieves its result.
| |
| get | back to summary |
|---|---|
| public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Implements java. Doc from java. Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isCancelled | back to summary |
|---|---|
| public boolean isCancelled() Implements java. Doc from java. Returns
| |
| isDone | back to summary |
|---|---|
| public boolean isDone() Implements java. Doc from java. Returns
| |
| run | back to summary |
|---|---|
| public void run() | |