use of org.jgroups.util.Rsp in project wildfly by wildfly.
the class ChannelCommandDispatcher method executeOnCluster.
@Override
public <R> Map<Node, CommandResponse<R>> executeOnCluster(Command<R, ? super C> command, Node... excludedNodes) throws CommandDispatcherException {
Message message = this.createMessage(command);
RequestOptions options = this.createRequestOptions(excludedNodes);
try {
Map<Address, Rsp<R>> responses = this.dispatcher.castMessage(null, message, options);
Map<Node, CommandResponse<R>> results = new HashMap<>();
for (Map.Entry<Address, Rsp<R>> entry : responses.entrySet()) {
Address address = entry.getKey();
Rsp<R> response = entry.getValue();
if (response.wasReceived() && !response.wasSuspected()) {
results.put(this.factory.createNode(address), createCommandResponse(response));
}
}
return results;
} catch (Exception e) {
throw new CommandDispatcherException(e);
}
}
use of org.jgroups.util.Rsp in project wildfly by wildfly.
the class ChannelCommandDispatcher method submitOnCluster.
@Override
public <R> Map<Node, Future<R>> submitOnCluster(Command<R, ? super C> command, Node... excludedNodes) throws CommandDispatcherException {
Map<Node, Future<R>> results = new ConcurrentHashMap<>();
FutureListener<RspList<R>> listener = future -> {
try {
future.get().keySet().stream().map(address -> this.factory.createNode(address)).forEach(node -> results.remove(node));
} catch (CancellationException e) {
} catch (ExecutionException e) {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
};
Message message = this.createMessage(command);
RequestOptions options = this.createRequestOptions(excludedNodes);
try {
Future<? extends Map<Address, Rsp<R>>> futureResponses = this.dispatcher.castMessageWithFuture(null, message, options, listener);
Set<Node> excluded = (excludedNodes != null) ? new HashSet<>(Arrays.asList(excludedNodes)) : Collections.<Node>emptySet();
for (Address address : this.dispatcher.getChannel().getView().getMembers()) {
Node node = this.factory.createNode(address);
if (!excluded.contains(node)) {
Future<R> future = new Future<R>() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return futureResponses.cancel(mayInterruptIfRunning);
}
@Override
public R get() throws InterruptedException, ExecutionException {
Map<Address, Rsp<R>> responses = futureResponses.get();
Rsp<R> response = responses.get(address);
if (response == null) {
throw new CancellationException();
}
return createCommandResponse(response).get();
}
@Override
public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
Map<Address, Rsp<R>> responses = futureResponses.get(timeout, unit);
Rsp<R> response = responses.get(address);
if (response == null) {
throw new CancellationException();
}
return createCommandResponse(response).get();
}
@Override
public boolean isCancelled() {
return futureResponses.isCancelled();
}
@Override
public boolean isDone() {
return futureResponses.isDone();
}
};
results.put(node, future);
}
}
return results;
} catch (Exception e) {
throw new CommandDispatcherException(e);
}
}
Aggregations