public interface ClusterExecutor extends Executor
This executor also implements Executor
so that it may be used with methods such as
CompletableFuture.runAsync(Runnable, Executor)
or CompletableFuture.supplyAsync(Supplier, Executor)
.
Unfortunately though these invocations do not have explicitly defined Serializable Runnable
or
Supplier
arguments and manual casting is required when using a lambda.
Something like the following:
CompletableFuture.runAsync((Serializable && Runnable)() -> doSomething(), clusterExecutor)
. Although note
that the submit(SerializableRunnable)
does this automatically for you.
Any method that returns a value should make sure the returned value is properly serializable or else it will
be replaced with a NotSerializableException
Modifier and Type | Method and Description |
---|---|
ClusterExecutor |
allNodeSubmission()
When a command is submitted it will submit this command to all of the available nodes that pass the provided
filter.
|
default void |
execute(Runnable command) |
default void |
execute(SerializableRunnable command)
The same as
Executor.execute(Runnable) , except the Runnable must also implement Serializable. |
ClusterExecutor |
filterTargets(ClusterExecutionPolicy policy)
Allows for filtering of address nodes by only allowing addresses that match the given execution policy to be used.
|
ClusterExecutor |
filterTargets(ClusterExecutionPolicy policy,
Predicate<? super Address> predicate)
Allows for filtering of address nodes dynamically per invocation.
|
ClusterExecutor |
filterTargets(Collection<Address> addresses)
Allows for filtering of address nodes by only allowing addresses in this collection from being contacted.
|
ClusterExecutor |
filterTargets(Predicate<? super Address> predicate)
Allows for filtering of address nodes dynamically per invocation.
|
ClusterExecutor |
noFilter()
Applies no filtering and will send any invocations to any/all current nodes.
|
ClusterExecutor |
singleNodeSubmission()
When a command is submitted it will only be submitted to one node of the available nodes, there is no strict
requirements as to which node is chosen and is implementation specific.
|
ClusterExecutor |
singleNodeSubmission(int failOverCount)
When a command is submitted it will only be submitted to one node of the available nodes, there is no strict
requirements as to which node is chosen and is implementation specific.
|
CompletableFuture<Void> |
submit(Runnable command)
Submits the runnable to the desired nodes and returns a CompletableFuture that will be completed when
all desired nodes complete the given command
|
default CompletableFuture<Void> |
submit(SerializableRunnable command)
The same as
submit(Runnable) , except the Runnable must also implement Serializable. |
<V> CompletableFuture<Void> |
submitConsumer(Function<? super EmbeddedCacheManager,? extends V> callable,
TriConsumer<? super Address,? super V,? super Throwable> triConsumer)
Submits the given command to the desired nodes and allows for handling of results as they return.
|
default <V> CompletableFuture<Void> |
submitConsumer(SerializableFunction<? super EmbeddedCacheManager,? extends V> callable,
TriConsumer<? super Address,? super V,? super Throwable> triConsumer)
The same as
submitConsumer(Function, TriConsumer) , except the Callable must also implement
Serializable. |
ClusterExecutor |
timeout(long time,
TimeUnit unit)
Sets a duration after which a command will timeout.
|
default void execute(Runnable command)
This command will be ran in the desired nodes, but no result is returned to notify the user of completion or failure. This command will return immediately while the runnable is processed asynchronously.
default void execute(SerializableRunnable command)
Executor.execute(Runnable)
, except the Runnable must also implement Serializable.
This method will be used automatically by lambdas, which prevents users from having to manually cast to a Serializable lambda.
command
- the command to executeCompletableFuture<Void> submit(Runnable command)
If a node encounters an exception, the first one to respond with such an exception will set the responding future to an exceptional state passing the given exception.
command
- the command to execute.default CompletableFuture<Void> submit(SerializableRunnable command)
submit(Runnable)
, except the Runnable must also implement Serializable.
This method will be used automatically by lambdas, which prevents users from having to manually cast to a Serializable lambda.
command
- the command to execute<V> CompletableFuture<Void> submitConsumer(Function<? super EmbeddedCacheManager,? extends V> callable, TriConsumer<? super Address,? super V,? super Throwable> triConsumer)
TriConsumer
which will be called back each time for each desired node. Note that these callbacks
can be called from different threads at the same time. A completable future is returned to the caller used
for the sole purpose of being completed when all nodes have sent responses back.
If this cluster executor is running in failover mode via singleNodeSubmission(int)
the
triConsumer will be called back each time a failure occurs as well. To satisfy ordering a retry is not resubmitted
until after the callback has completed.
Note the TriConsumer
is only ran on the node where the task was submitted and thus doesn't need to be
serialized.
V
- the type of the task's resultcallable
- the task to executetriConsumer
- the tri-consumer to be called back upon for each node's resultdefault <V> CompletableFuture<Void> submitConsumer(SerializableFunction<? super EmbeddedCacheManager,? extends V> callable, TriConsumer<? super Address,? super V,? super Throwable> triConsumer)
submitConsumer(Function, TriConsumer)
, except the Callable must also implement
Serializable.
This method will be used automatically by lambdas, which prevents users from having to manually cast to a Serializable lambda.
V
- the type of the task's resultcallable
- the task to executetriConsumer
- the tri-consumer to be called back upon for each node's resultClusterExecutor timeout(long time, TimeUnit unit)
TimeoutException
as the throwable.
The timeout parameter is used for both local and remote nodes. There are no guarantees as to whether the timed out command is interrupted.
time
- the duration for the timeoutunit
- what unit the duration is inClusterExecutor singleNodeSubmission()
singleNodeSubmission(int)
instead.ClusterExecutor singleNodeSubmission(int failOverCount)
TimeoutException
is throwing, this will not
be retried as this is the same exception that is thrown when using
timeout(long, TimeUnit)
. Each time the
fail over occurs any available node is chosen, there is no requirement as to which can be chosen and is left up
to the implementation to decide.failOverCount
- how many times this executor will attempt a failoverClusterExecutor allNodeSubmission()
ClusterExecutor filterTargets(Predicate<? super Address> predicate)
filterTargets(Collection)
).predicate
- the dynamic predicate applied each time an invocation is doneClusterExecutor filterTargets(ClusterExecutionPolicy policy) throws IllegalStateException
filterTargets(Collection)
).
The execution policy is only used if the addresses are configured to be topology aware. That is that the
TransportConfiguration.hasTopologyInfo()
method returns true. If this is false this method will throw
an IllegalStateException
.
policy
- the policy to determine which nodes can be usedIllegalStateException
- thrown if topology info isn't availableClusterExecutor filterTargets(ClusterExecutionPolicy policy, Predicate<? super Address> predicate) throws IllegalStateException
filterTargets(Collection)
).
The execution policy is only used if the addresses are configured to be topology aware. That is that the
TransportConfiguration.hasTopologyInfo()
method returns true. If this is false this method will throw
an IllegalStateException
.
policy
- the execution policy applied before predicate to allow only nodes in that grouppredicate
- the dynamic predicate applied each time an invocation is doneIllegalStateException
- thrown if topology info isn't availableClusterExecutor filterTargets(Collection<Address> addresses)
filterTargets(Predicate)
.addresses
- which nodes the executor invocations should go toClusterExecutor noFilter()
Copyright © 2021 JBoss by Red Hat. All rights reserved.