Class Cache.Simple<V>

java.lang.Object
org.apache.sis.util.collection.Cache.Simple<V>
All Implemented Interfaces:
Cache.Handler<V>
Enclosing class:
Cache<K,V>

private final class Cache.Simple<V> extends Object implements 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
    Modifier and Type
    Field
    Description
    private final V
    The result computed in another thread.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Simple(V value)
    Creates a new handler wrapping the given value.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the computed value.
    void
    putAndUnlock(V result)
    Do nothing (except checking for programming error), since we don't hold any lock.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • value

      private final V value
      The result computed in another thread.
  • Constructor Details

    • Simple

      Simple(V value)
      Creates a new handler wrapping the given value.
  • Method Details

    • peek

      public V peek()
      Returns the computed value.
      Specified by:
      peek in interface Cache.Handler<V>
      Returns:
      the value from the cache, or null if none.
    • putAndUnlock

      public void putAndUnlock(V result) throws IllegalStateException
      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 between peek and putAndUnlock.
      Specified by:
      putAndUnlock in interface Cache.Handler<V>
      Parameters:
      result - the result to store in the cache, or null 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.