Class ThreadSafeClosure<T>


  • public class ThreadSafeClosure<T>
    extends java.lang.Object
    Thread safe capture of a free variable for closure state of a Function.
    Author:
    Daniel Sagenschneider
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void failure​(java.lang.Throwable cause)
      Flags a failure.
      T get()
      Obtains current value.
      void set​(T value)
      Sets the value.
      T waitAndGet()
      Convenience method to wait 3 seconds and then get value.
      T waitAndGet​(long timeout)
      Obtains the value.
      • Methods inherited from class java.lang.Object

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

      • ThreadSafeClosure

        public ThreadSafeClosure()
        Initialise with null.
      • ThreadSafeClosure

        public ThreadSafeClosure​(T initialValue)
        Initialise with initial value.
        Parameters:
        initialValue - Initial value.
    • Method Detail

      • set

        public void set​(T value)
        Sets the value.
        Parameters:
        value - Value.
      • failure

        public void failure​(java.lang.Throwable cause)
        Flags a failure.
        Parameters:
        cause - Cause of the failure.
      • get

        public T get()
        Obtains current value.
        Returns:
        Value or null.
      • waitAndGet

        public T waitAndGet()
        Convenience method to wait 3 seconds and then get value.
        Returns:
        Value.
      • waitAndGet

        public T waitAndGet​(long timeout)
        Obtains the value.
        Parameters:
        timeout - Timeout to wait for the value.
        Returns:
        Value.