Class ContextSampler


  • public class ContextSampler
    extends java.lang.Object
    A facility that samples the contexts that are current at creation time and make them available later.
    Author:
    Fabrizio Giudici
    • Constructor Summary

      Constructors 
      Constructor Description
      ContextSampler​(java.lang.Object owner)
      Creates a new instance and samples the currently available contexts.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<java.lang.Object> getContexts()
      Returns the previously sampled contexts.
      <V,​T extends java.lang.Throwable>
      V
      runWithContexts​(Task<V,​T> task)
      Runs a Task associated with the sampled contexts.
      • Methods inherited from class java.lang.Object

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

      • ContextSampler

        public ContextSampler​(@Nonnull
                              java.lang.Object owner)
        Creates a new instance and samples the currently available contexts.
        Parameters:
        owner - the owner
    • Method Detail

      • getContexts

        @Nonnull
        public java.util.List<java.lang.Object> getContexts()
        Returns the previously sampled contexts.
        Returns:
        the contexts
      • runWithContexts

        public <V,​T extends java.lang.Throwable> V runWithContexts​(@Nonnull
                                                                         Task<V,​T> task)
                                                                  throws T extends java.lang.Throwable
        Runs a Task associated with the sampled contexts.
        Type Parameters:
        V - the type of the result value
        T - the type of the exception
        Parameters:
        task - the task
        Returns:
        the value produced by the task
        Throws:
        T - the exception(s) thrown by the task
        T extends java.lang.Throwable