Class SequentialContext

  • All Implemented Interfaces:
    Context

    public class SequentialContext
    extends java.lang.Object
    implements Context
    A simple Context to use for belt calculations. Executes single-threaded in the current thread. The execution of tasks can be stopped by calling stop().
    Since:
    1.0.1
    Author:
    Gisa Meier
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> java.util.List<T> call​(java.util.List<java.util.concurrent.Callable<T>> callables)
      Executes the given Callables in parallel, returning their results upon completion.
      int getParallelism()
      Returns the targeted parallelism level of this execution context.
      boolean isActive()
      Returns true if the execution context is active.
      void stop()
      Stops the execution for this context.
      • Methods inherited from class java.lang.Object

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

      • SequentialContext

        public SequentialContext()
    • Method Detail

      • isActive

        public boolean isActive()
        Description copied from interface: Context
        Returns true if the execution context is active. Inactive contexts may reject new jobs.
        Specified by:
        isActive in interface Context
        Returns:
        true if the execution context is active
      • getParallelism

        public int getParallelism()
        Description copied from interface: Context
        Returns the targeted parallelism level of this execution context.
        Specified by:
        getParallelism in interface Context
        Returns:
        the targeted parallelism level
      • call

        public <T> java.util.List<T> call​(java.util.List<java.util.concurrent.Callable<T>> callables)
                                   throws java.util.concurrent.ExecutionException
        Description copied from interface: Context
        Executes the given Callables in parallel, returning their results upon completion.

        If one of the Callables encounters an exception, the context attempts to cancel the other Callables and throws an ExecutionException that wraps the exception. If more than one Callable encounters an exception, only the first observed exception is reported.

        The method blocks until all Callables have completed.

        Note that the cancellation of one of the Callables might not interrupt the execution of other Callables that have already been started. As a consequence, it is recommended that all long-running Callables periodically check for the cancellation of the computation via Context.requireActive().

        Specified by:
        call in interface Context
        Type Parameters:
        T - the type of the values returned from the callables
        Parameters:
        callables - the Callables to execute in parallel
        Returns:
        a list containing the results of the callables
        Throws:
        java.util.concurrent.ExecutionException - if the computation threw an exception
      • stop

        public void stop()
        Stops the execution for this context.