use of org.wildfly.clustering.dispatcher.CommandDispatcherException in project wildfly by wildfly.
the class DistributedSingletonService method providersChanged.
@Override
public void providersChanged(Set<Node> nodes) {
Group group = this.registry.getValue().getGroup();
List<Node> candidates = group.getNodes();
candidates.retainAll(nodes);
// Only run election on a single node
if (candidates.isEmpty() || candidates.get(0).equals(group.getLocalNode())) {
// First validate that quorum was met
int size = candidates.size();
boolean quorumMet = size >= this.quorum;
if ((this.quorum > 1) && (size == this.quorum)) {
// Log fragility of singleton availability
ClusteringServerLogger.ROOT_LOGGER.quorumJustReached(this.serviceName.getCanonicalName(), this.quorum);
}
Node elected = quorumMet ? this.electionPolicy.elect(candidates) : null;
try {
if (elected != null) {
ClusteringServerLogger.ROOT_LOGGER.elected(elected.getName(), this.serviceName.getCanonicalName());
// Stop service on every node except elected node
this.dispatcher.executeOnCluster(new StopCommand<>(), elected);
// Start service on elected node
this.dispatcher.executeOnNode(new StartCommand<>(), elected);
} else {
if (quorumMet) {
ClusteringServerLogger.ROOT_LOGGER.noPrimaryElected(this.serviceName.getCanonicalName());
} else {
ClusteringServerLogger.ROOT_LOGGER.quorumNotReached(this.serviceName.getCanonicalName(), this.quorum);
}
// Stop service on every node
this.dispatcher.executeOnCluster(new StopCommand<>());
}
} catch (CommandDispatcherException e) {
throw new IllegalStateException(e);
}
}
}
use of org.wildfly.clustering.dispatcher.CommandDispatcherException in project wildfly by wildfly.
the class ChannelCommandDispatcher method submitOnNode.
@Override
public <R> Future<R> submitOnNode(Command<R, ? super C> command, Node node) throws CommandDispatcherException {
// Bypass MessageDispatcher if target node is local
if (this.isLocal(node)) {
return this.localDispatcher.submitOnNode(command, node);
}
Message message = this.createMessage(command, node);
RequestOptions options = this.createRequestOptions();
try {
return this.dispatcher.sendMessageWithFuture(message, options);
} catch (Exception e) {
throw new CommandDispatcherException(e);
}
}
use of org.wildfly.clustering.dispatcher.CommandDispatcherException in project wildfly by wildfly.
the class ChannelCommandDispatcher method executeOnNode.
@Override
public <R> CommandResponse<R> executeOnNode(Command<R, ? super C> command, Node node) throws CommandDispatcherException {
// Bypass MessageDispatcher if target node is local
if (this.isLocal(node)) {
return this.localDispatcher.executeOnNode(command, node);
}
Message message = this.createMessage(command, node);
RequestOptions options = this.createRequestOptions();
try {
// Use sendMessageWithFuture(...) instead of sendMessage(...) since we want to differentiate between sender exceptions and receiver exceptions
Future<R> future = this.dispatcher.sendMessageWithFuture(message, options);
return new SimpleCommandResponse<>(future.get());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return new SimpleCommandResponse<>(e);
} catch (ExecutionException e) {
return new SimpleCommandResponse<>(e);
} catch (Exception e) {
throw new CommandDispatcherException(e);
}
}
use of org.wildfly.clustering.dispatcher.CommandDispatcherException 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.wildfly.clustering.dispatcher.CommandDispatcherException in project wildfly by wildfly.
the class PrimaryOwnerScheduler method executeOnPrimaryOwner.
private CompletionStage<Void> executeOnPrimaryOwner(I id, Command<Void, Scheduler<I, M>> command) throws CommandDispatcherException {
K key = this.keyFactory.apply(id);
Function<K, Node> primaryOwnerLocator = this.primaryOwnerLocator;
CommandDispatcher<Scheduler<I, M>> dispatcher = this.dispatcher;
ExceptionSupplier<CompletionStage<Void>, CommandDispatcherException> action = new ExceptionSupplier<CompletionStage<Void>, CommandDispatcherException>() {
@Override
public CompletionStage<Void> get() throws CommandDispatcherException {
Node node = primaryOwnerLocator.apply(key);
// This should only go remote following a failover
return dispatcher.executeOnMember(command, node);
}
};
return INVOKER.invoke(action);
}
Aggregations