Class Memoized<T,E extends Exception>

java.lang.Object
com.yahoo.yolean.concurrent.Memoized<T,E>
All Implemented Interfaces:
AutoCloseable, Supplier<T>

public class Memoized<T,E extends Exception> extends Object implements Supplier<T>, AutoCloseable
Wraps a lazily initialised resource which needs to be shut down. The wrapped supplier may not return null, and should be retryable on failure. If it throws, it will be retried if get() is retried. A supplier that fails to clean up partial state on failure may cause a resource leak.
Author:
jonmv
  • Constructor Details

    • Memoized

      public Memoized(Supplier<T> factory)
      Returns a new Memoized which has no close method.
    • Memoized

      public Memoized(Supplier<T> factory, Memoized.Closer<T,E> closer)
      Returns a new Memoized with the given factory and closer.
  • Method Details

    • of

      public static <T extends AutoCloseable> Memoized<T,?> of(Supplier<T> factory)
      Returns a generic AutoCloseable Memoized with the given AutoCloseable-supplier.
    • combine

      public static <T, U, E extends Exception> Memoized<U,E> combine(Memoized<T,? extends E> inner, Function<T,U> outer, Memoized.Closer<U,? extends E> closer)
      Composes the given memoized with a function taking its output as an argument to produce a new Memoized, with the given closer.
    • get

      public T get()
      Specified by:
      get in interface Supplier<T>
    • close

      public void close() throws E
      Specified by:
      close in interface AutoCloseable
      Throws:
      E extends Exception