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