Search in sources :

Example 1 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 2 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 3 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 4 with Message

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

the class JGroupsMessengerJUnitTest method doTestBigMessageIsFragmented.

public void doTestBigMessageIsFragmented(boolean mcastEnabled, boolean mcastMsg) throws Exception {
    initMocks(mcastEnabled);
    MessageHandler mh = mock(MessageHandler.class);
    messenger.addHandler(JoinRequestMessage.class, mh);
    InternalDistributedMember sender = messenger.getMemberID();
    NetView v = new NetView(sender);
    when(joinLeave.getView()).thenReturn(v);
    messenger.installView(v);
    JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0);
    if (mcastMsg) {
        msg.setMulticast(true);
    }
    messenger.send(msg);
    int sentMessages = (mcastEnabled && mcastMsg) ? interceptor.mcastSentDataMessages : interceptor.unicastSentDataMessages;
    assertTrue("expected 1 message to be sent but found " + sentMessages, sentMessages == 1);
    // send a big message and expect fragmentation
    msg = new JoinRequestMessage(messenger.localAddress, sender, new byte[(int) (services.getConfig().getDistributionConfig().getUdpFragmentSize() * (1.5))], -1, 0);
    // configure an incoming message handler for JoinRequestMessage
    final DistributionMessage[] messageReceived = new DistributionMessage[1];
    MessageHandler handler = new MessageHandler() {

        @Override
        public void processMessage(DistributionMessage m) {
            messageReceived[0] = m;
        }
    };
    messenger.addHandler(JoinRequestMessage.class, handler);
    // configure the outgoing message interceptor
    interceptor.unicastSentDataMessages = 0;
    interceptor.collectMessages = true;
    interceptor.collectedMessages.clear();
    messenger.send(msg);
    assertTrue("expected 2 messages to be sent but found " + interceptor.unicastSentDataMessages, interceptor.unicastSentDataMessages == 2);
    List<Message> messages = new ArrayList<>(interceptor.collectedMessages);
    UUID fakeMember = new UUID(50, 50);
    short unicastHeaderId = ClassConfigurator.getProtocolId(UNICAST3.class);
    int seqno = 1;
    for (Message m : messages) {
        m.setSrc(fakeMember);
        UNICAST3.Header oldHeader = (UNICAST3.Header) m.getHeader(unicastHeaderId);
        if (oldHeader == null)
            continue;
        UNICAST3.Header newHeader = UNICAST3.Header.createDataHeader(seqno, oldHeader.connId(), seqno == 1);
        seqno += 1;
        m.putHeader(unicastHeaderId, newHeader);
        interceptor.up(new Event(Event.MSG, m));
    }
    Thread.sleep(5000);
    System.out.println("received message = " + messageReceived[0]);
}
Also used : MessageHandler(org.apache.geode.distributed.internal.membership.gms.interfaces.MessageHandler) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) NetView(org.apache.geode.distributed.internal.membership.NetView) ArrayList(java.util.ArrayList) UNICAST3(org.jgroups.protocols.UNICAST3) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) Event(org.jgroups.Event) UUID(org.jgroups.util.UUID) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)

Example 5 with Message

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

the class JGroupsMessengerJUnitTest method testReceiver.

@Test
public void testReceiver() throws Exception {
    try {
        DistributionStats.enableClockStats = true;
        initMocks(false);
        JGroupsReceiver receiver = (JGroupsReceiver) messenger.myChannel.getReceiver();
        // a zero-length message is ignored
        Message msg = new Message(new JGAddress(messenger.getMemberID()));
        Object result = messenger.readJGMessage(msg);
        assertNull(result);
        // for code coverage we need to pump this message through the receiver
        receiver.receive(msg);
        // for more code coverage we need to actually set a buffer in the message
        msg.setBuffer(new byte[0]);
        result = messenger.readJGMessage(msg);
        assertNull(result);
        receiver.receive(msg);
        // now create a view and a real distribution-message
        InternalDistributedMember myAddress = messenger.getMemberID();
        InternalDistributedMember other = createAddress(8888);
        NetView v = new NetView(myAddress);
        v.add(other);
        when(joinLeave.getView()).thenReturn(v);
        messenger.installView(v);
        List<InternalDistributedMember> recipients = v.getMembers();
        SerialAckedMessage dmsg = new SerialAckedMessage();
        dmsg.setRecipients(recipients);
        // a message is ignored during manager shutdown
        msg = messenger.createJGMessage(dmsg, new JGAddress(other), Version.CURRENT_ORDINAL);
        when(manager.shutdownInProgress()).thenReturn(Boolean.TRUE);
        receiver.receive(msg);
        verify(manager, never()).processMessage(isA(DistributionMessage.class));
        assertTrue("There should be UDPDispatchRequestTime stats", services.getStatistics().getUDPDispatchRequestTime() > 0);
    } finally {
        DistributionStats.enableClockStats = false;
    }
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JGroupsReceiver(org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessenger.JGroupsReceiver) NetView(org.apache.geode.distributed.internal.membership.NetView) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Message (org.jgroups.Message)245 Address (org.jgroups.Address)50 MessageBatch (org.jgroups.util.MessageBatch)37 BytesMessage (org.jgroups.BytesMessage)31 NioMessage (org.jgroups.NioMessage)14 ObjectMessage (org.jgroups.ObjectMessage)14 EmptyMessage (org.jgroups.EmptyMessage)12 Test (org.testng.annotations.Test)12 ToaHeader (org.jgroups.protocols.tom.ToaHeader)11 Test (org.junit.Test)11 Event (org.jgroups.Event)10 IOException (java.io.IOException)8 JChannel (org.jgroups.JChannel)8 MessageID (org.jgroups.protocols.tom.MessageID)8 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 TimeoutException (java.util.concurrent.TimeoutException)6 Collectors (java.util.stream.Collectors)6 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)6