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 |
---|---|
void |
execute(Runnable command) |
void |
execute(SerializableRunnable command)
The same as
Executor.execute(Runnable) , except the Runnable must also implement Serializable. |
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 all current nodes.
|
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
|
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.
|
<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)
The timeout parameter is not adhered to when executing the command locally and is only for remote nodes.
|
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.
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.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.
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 result<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)
The timeout parameter is not adhered to when executing the command locally and is only for remote nodes.
time
- unit
- ClusterExecutor filterTargets(Predicate<? super Address> predicate)
filterTargets(Collection)
).predicate
- the dynamic predicate applied each time an invocation is doneClusterExecutor filterTargets(Collection<Address> addresses)
filterTargets(Predicate)
.addresses
- which nodes the executor invocations should go toClusterExecutor noFilter()
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.