Class Syndicate<T>

  • Type Parameters:
    T - the type of the values from the tasks.
    All Implemented Interfaces:
    AutoCloseable

    public final class Syndicate<T>
    extends Object
    implements AutoCloseable
    Syndicate simplifies and represent a specific operation of the Executor Service, InvokeAll. Use this class when you need to invoke a group of processes in parallel and expect some results in the future.

    Ideally, use Syndicated within the try-with-resources statement, to ensure the current Executor Service is shut down when all operations are completed. Otherwise, the close method has to be called manually to shutdown.

    try(final Syndicate syndicate = Syndicate.init()){

    } catch (Exception e) {

    }

    Since:
    1.0
    Author:
    Bobai Kato
    • Method Detail

      • init

        @Contract("_ -> new")
        @NotNull
        public static <T> @NotNull Syndicate<T> init​(ExecutorService executorService)
        Creates a new instance of Syndicate with your preferred instance of ExecutorService to power the Syndicate ops.
        Type Parameters:
        T - the type of the values from the tasks
        Parameters:
        executorService - instance of ExecutorService
        Returns:
        new instance of Syndicate
      • add

        @Contract("_ -> this")
        public Syndicate<T> add​(Callable<T> callableTask)
        Use to add a task of Callable type
        Parameters:
        callableTask - instance of a Callable, the task to be executed as part of the Syndicate
        Returns:
        existing instance of Syndicate
      • apply

        @Contract(value="_, _ -> new",
                  pure=true)
        @NotNull
        public @NotNull Syndicate.Conductor<T> apply​(long timeout,
                                                     TimeUnit unit)
        Created the Syndicate.Conductor to initiate the processing of task in the Syndicate
        Parameters:
        timeout - the maximum time to wait for the tasks to complete
        unit - the time unit of the timeout argument
        Returns:
        new instance of a Syndicate.Conductor
      • close

        public void close()
        Shuts down ExecutorService, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.
        Specified by:
        close in interface AutoCloseable
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • equals

        @Contract(value="null -> false",
                  pure=true)
        public boolean equals​(Object o)
        Overrides:
        equals in class Object