Search in sources :

Example 11 with Message

use of org.jgroups.Message 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 12 with Message

use of org.jgroups.Message 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 13 with Message

use of org.jgroups.Message 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 14 with Message

use of org.jgroups.Message in project camel by apache.

the class JGroupsProducer method process.

// Processing logic
@Override
public void process(Exchange exchange) throws Exception {
    Object body = exchange.getIn().getBody();
    if (body != null) {
        Address destinationAddress = exchange.getIn().getHeader(JGroupsEndpoint.HEADER_JGROUPS_DEST, Address.class);
        Address sourceAddress = exchange.getIn().getHeader(JGroupsEndpoint.HEADER_JGROUPS_SRC, Address.class);
        log.debug("Posting: {} to cluster: {}", body, clusterName);
        if (destinationAddress != null) {
            log.debug("Posting to custom destination address: {}", destinationAddress);
        }
        if (sourceAddress != null) {
            log.debug("Posting from custom source address: {}", sourceAddress);
        }
        Message message = new Message(destinationAddress, body);
        message.setSrc(sourceAddress);
        channel.send(message);
    } else {
        log.debug("Body is null, cannot post to channel.");
    }
}
Also used : Address(org.jgroups.Address) Message(org.jgroups.Message)

Example 15 with Message

use of org.jgroups.Message in project camel by apache.

the class CamelJGroupsReceiverTest method shouldHandleProcessingException.

// Tests
@Test(expected = JGroupsException.class)
public void shouldHandleProcessingException() throws Exception {
    // Given
    willThrow(Exception.class).given(processor).process(any(Exchange.class));
    Message message = new Message(null, "someMessage");
    message.setSrc(null);
    // When
    receiver.receive(message);
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.jgroups.Message) Test(org.junit.Test)

Aggregations

Message (org.jgroups.Message)26 Test (org.junit.Test)11 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)7 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)7 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)7 Event (org.jgroups.Event)7 IOException (java.io.IOException)6 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)6 SerialAckedMessage (org.apache.geode.distributed.internal.SerialAckedMessage)5 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)5 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)5 LeaveRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage)5 CancellationException (java.util.concurrent.CancellationException)4 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 NetView (org.apache.geode.distributed.internal.membership.NetView)4 RequestOptions (org.jgroups.blocks.RequestOptions)3 CommandDispatcherException (org.wildfly.clustering.dispatcher.CommandDispatcherException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 UnknownHostException (java.net.UnknownHostException)2