use of org.wildfly.clustering.dispatcher.CommandDispatcherException in project wildfly by wildfly.
the class ChannelCommandDispatcher method executeOnGroup.
@Override
public <R> Map<Node, CompletionStage<R>> executeOnGroup(Command<R, ? super CC> command, Node... excludedMembers) throws CommandDispatcherException {
Set<Node> excluded = (excludedMembers != null) ? new HashSet<>(Arrays.asList(excludedMembers)) : Collections.emptySet();
Map<Node, CompletionStage<R>> results = new ConcurrentHashMap<>();
Buffer buffer = this.createBuffer(command);
for (Node member : this.group.getMembership().getMembers()) {
if (!excluded.contains(member)) {
Address address = this.group.getAddress(member);
if (this.localAddress.equals(address)) {
results.put(member, this.localDispatcher.executeOnMember(command, member));
} else {
try {
ServiceRequest<R, MC> request = new ServiceRequest<>(this.dispatcher.getCorrelator(), this.group.getAddress(member), this.options, this.context);
CompletionStage<R> future = request.send(buffer);
results.put(member, future);
future.whenComplete(new PruneCancellationTask<>(results, member));
} catch (CommandDispatcherException e) {
// Cancel previously dispatched messages
for (CompletionStage<R> result : results.values()) {
result.toCompletableFuture().cancel(true);
}
throw e;
}
}
}
}
return results;
}
use of org.wildfly.clustering.dispatcher.CommandDispatcherException in project wildfly by wildfly.
the class CommandDispatcherTransport method sendMessage.
@Override
protected Serializable sendMessage(Node physicalAddress, Request request, Serializable... parameters) throws WorkException {
Command<?, CommandDispatcherTransport> command = createCommand(request, parameters);
CommandDispatcher<CommandDispatcherTransport> dispatcher = this.dispatcher;
ExceptionSupplier<Optional<Serializable>, WorkException> task = new ExceptionSupplier<Optional<Serializable>, WorkException>() {
@Override
public Optional<Serializable> get() throws WorkException {
try {
CompletionStage<?> response = dispatcher.executeOnMember(command, physicalAddress);
return Optional.ofNullable((Serializable) response.toCompletableFuture().join());
} catch (CancellationException e) {
return Optional.empty();
} catch (CommandDispatcherException | CompletionException e) {
throw new WorkException(e);
}
}
};
Optional<Serializable> val = this.executor.execute(task).orElse(null);
return val != null ? val.orElse(null) : null;
}
Aggregations