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);
}
}
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);
}
}
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);
}
}
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]);
}
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;
}
}
Aggregations