Class Memoizer<A,​V>

  • All Implemented Interfaces:
    LowLevelProcessor<A,​V>

    public class Memoizer<A,​V>
    extends java.lang.Object
    implements LowLevelProcessor<A,​V>
    Memoizer for computing resource expensive tasks asynchronously & concurrently. Inspired by D. Lea. JCiP, 2nd edition. Addison-Wesley, 2006. pp.109
    Since:
    2.6
    Author:
    Marcel Valovy - [email protected]
    • Constructor Summary

      Constructors 
      Constructor Description
      Memoizer()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      V compute​(ComputableTask<A,​V> c, A taskArg)
      Waits if necessary for the computation to complete, and then retrieves its result.
      void forget​(ComputableTask<A,​V> task, A key)
      Forgets result of the specified task.
      void forgetAll()
      Forgets all cached results.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Memoizer

        public Memoizer()
    • Method Detail

      • compute

        public V compute​(ComputableTask<A,​V> c,
                         A taskArg)
                  throws java.lang.InterruptedException
        Description copied from interface: LowLevelProcessor
        Waits if necessary for the computation to complete, and then retrieves its result.
        Specified by:
        compute in interface LowLevelProcessor<A,​V>
        taskArg - argument for computation
        Throws:
        java.lang.InterruptedException - if the current thread was interrupted while waiting
      • forget

        public void forget​(ComputableTask<A,​V> task,
                           A key)
        Forgets result of the specified task. This allows to manually control size of internal cache.
        Parameters:
        task - computable task, forming part of result key
        key - argument of computation
      • forgetAll

        public void forgetAll()
        Forgets all cached results.