Search in sources :

Example 1 with CommandDispatcherException

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);
        }
    }
}
Also used : Group(org.wildfly.clustering.group.Group) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) Node(org.wildfly.clustering.group.Node)

Example 2 with CommandDispatcherException

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);
    }
}
Also used : Message(org.jgroups.Message) RequestOptions(org.jgroups.blocks.RequestOptions) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException)

Example 3 with CommandDispatcherException

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);
    }
}
Also used : Message(org.jgroups.Message) RequestOptions(org.jgroups.blocks.RequestOptions) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException)

Example 4 with CommandDispatcherException

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);
    }
}
Also used : Message(org.jgroups.Message) Address(org.jgroups.Address) RequestOptions(org.jgroups.blocks.RequestOptions) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) Node(org.wildfly.clustering.group.Node) CommandResponse(org.wildfly.clustering.dispatcher.CommandResponse) Rsp(org.jgroups.util.Rsp) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with CommandDispatcherException

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);
}
Also used : ExceptionSupplier(org.wildfly.common.function.ExceptionSupplier) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) Node(org.wildfly.clustering.group.Node) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

CommandDispatcherException (org.wildfly.clustering.dispatcher.CommandDispatcherException)12 CancellationException (java.util.concurrent.CancellationException)9 Node (org.wildfly.clustering.group.Node)9 CompletionStage (java.util.concurrent.CompletionStage)6 Map (java.util.Map)5 CompletionException (java.util.concurrent.CompletionException)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 Message (org.jgroups.Message)4 RequestOptions (org.jgroups.blocks.RequestOptions)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Address (org.jgroups.Address)3 ArrayList (java.util.ArrayList)2 WorkException (javax.resource.spi.work.WorkException)2 Rsp (org.jgroups.util.Rsp)2 CommandResponse (org.wildfly.clustering.dispatcher.CommandResponse)2 Group (org.wildfly.clustering.group.Group)2 ExceptionSupplier (org.wildfly.common.function.ExceptionSupplier)2