Package art.cutils.value
Class Syndicate<T>
- java.lang.Object
-
- art.cutils.value.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Syndicate.Close<T>
Represent the operation used to shutdown the currentExecutorService
running the Syndicate.static class
Syndicate.Conductor<T>
Represents the actor to process task within the syndicates
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Syndicate<T>
add(Callable<T> callableTask)
Use to add a task of Callable type@NotNull Syndicate.Conductor<T>
apply()
Created theSyndicate.Conductor
to initiate the processing of task in the Syndicate@NotNull Syndicate.Conductor<T>
apply(long timeout, TimeUnit unit)
Created theSyndicate.Conductor
to initiate the processing of task in the Syndicatevoid
close()
Shuts downExecutorService
, relinquishing any underlying resources.boolean
equals(Object o)
int
hashCode()
static <T> @NotNull Syndicate<T>
init()
Creates a new instance ofSyndicate
with defaultExecutors.newCachedThreadPool()
static <T> @NotNull Syndicate<T>
init(ExecutorService executorService)
Creates a new instance ofSyndicate
with your preferred instance ofExecutorService
to power the Syndicate ops.String
toString()
-
-
-
Method Detail
-
init
@Contract("_ -> new") @NotNull public static <T> @NotNull Syndicate<T> init(ExecutorService executorService)
Creates a new instance ofSyndicate
with your preferred instance ofExecutorService
to power the Syndicate ops.- Type Parameters:
T
- the type of the values from the tasks- Parameters:
executorService
- instance ofExecutorService
- Returns:
- new instance of
Syndicate
-
init
@Contract(" -> new") @NotNull public static <T> @NotNull Syndicate<T> init()
Creates a new instance ofSyndicate
with defaultExecutors.newCachedThreadPool()
- Type Parameters:
T
- the type of the values from the tasks- Returns:
- new instance of
Syndicate
-
add
@Contract("_ -> this") public Syndicate<T> add(Callable<T> callableTask)
Use to add a task of Callable type
-
apply
@Contract(value=" -> new", pure=true) @NotNull public @NotNull Syndicate.Conductor<T> apply()
Created theSyndicate.Conductor
to initiate the processing of task in the Syndicate- Returns:
- new instance of a
Syndicate.Conductor
-
apply
@Contract(value="_, _ -> new", pure=true) @NotNull public @NotNull Syndicate.Conductor<T> apply(long timeout, TimeUnit unit)
Created theSyndicate.Conductor
to initiate the processing of task in the Syndicate- Parameters:
timeout
- the maximum time to wait for the tasks to completeunit
- the time unit of the timeout argument- Returns:
- new instance of a
Syndicate.Conductor
-
close
public void close()
Shuts downExecutorService
, relinquishing any underlying resources. This method is invoked automatically on objects managed by thetry
-with-resources statement.- Specified by:
close
in interfaceAutoCloseable
-
equals
@Contract(value="null -> false", pure=true) public boolean equals(Object o)
-
-