use of org.apache.ignite.internal.network.message.InvokeRequest in project ignite-3 by apache.
the class DefaultMessagingService method onMessage.
/**
* Handles an incoming messages.
*
* @param obj Incoming message wrapper.
*/
private void onMessage(InNetworkObject obj) {
if (isInNetworkThread()) {
inboundService.submit(() -> onMessage(obj));
return;
}
NetworkMessage msg = obj.message();
DescriptorRegistry registry = obj.registry();
String consistentId = obj.consistentId();
try {
msg.unmarshal(marshaller, registry);
} catch (Exception e) {
throw new IgniteException("Failed to unmarshal message: " + e.getMessage(), e);
}
if (msg instanceof InvokeResponse) {
InvokeResponse response = (InvokeResponse) msg;
onInvokeResponse(response.message(), response.correlationId());
return;
}
Long correlationId = null;
NetworkMessage message = msg;
if (msg instanceof InvokeRequest) {
// Unwrap invocation request
InvokeRequest messageWithCorrelation = (InvokeRequest) msg;
correlationId = messageWithCorrelation.correlationId();
message = messageWithCorrelation.message();
}
ClusterNode sender = topologyService.getByConsistentId(consistentId);
NetworkAddress senderAddress;
if (sender != null) {
senderAddress = sender.address();
} else {
// TODO: IGNITE-16373 Use fake address if sender is not in cluster yet. For the response, consistentId from this address will
// be used
senderAddress = new NetworkAddress(UNKNOWN_HOST, UNKNOWN_HOST_PORT, consistentId);
}
for (NetworkMessageHandler networkMessageHandler : getMessageHandlers(message.groupType())) {
// TODO: IGNITE-16373 We should pass ClusterNode and not the address
networkMessageHandler.onReceived(message, senderAddress, correlationId);
}
}
use of org.apache.ignite.internal.network.message.InvokeRequest in project ignite-3 by apache.
the class DefaultMessagingService method invoke0.
/**
* Sends an invocation request. If the target is the current node, then message will be delivered immediately.
*
* @param recipient Target cluster node. TODO: Maybe {@code null} due to IGNITE-16373.
* @param addr Target address.
* @param msg Message.
* @param timeout Invocation timeout.
* @return A future holding the response or error if the expected response was not received.
*/
private CompletableFuture<NetworkMessage> invoke0(@Nullable ClusterNode recipient, NetworkAddress addr, NetworkMessage msg, long timeout) {
if (connectionManager.isStopped()) {
return failedFuture(new NodeStoppingException());
}
long correlationId = createCorrelationId();
CompletableFuture<NetworkMessage> responseFuture = new CompletableFuture<NetworkMessage>().orTimeout(timeout, TimeUnit.MILLISECONDS);
requestsMap.put(correlationId, responseFuture);
InetSocketAddress address = new InetSocketAddress(addr.host(), addr.port());
if (isSelf(recipient, addr.consistentId(), address)) {
sendToSelf(msg, correlationId);
return responseFuture;
}
InvokeRequest message = requestFromMessage(msg, correlationId);
String recipientConsistentId = recipient != null ? recipient.name() : addr.consistentId();
return sendMessage0(message, recipientConsistentId, address).thenCompose(unused -> responseFuture);
}
Aggregations