Search in sources :

Example 1 with InvokeRequest

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);
    }
}
Also used : InvokeResponse(org.apache.ignite.internal.network.message.InvokeResponse) DescriptorRegistry(org.apache.ignite.internal.network.serialization.DescriptorRegistry) ClassDescriptorRegistry(org.apache.ignite.internal.network.serialization.ClassDescriptorRegistry) IgniteException(org.apache.ignite.lang.IgniteException) AtomicLong(java.util.concurrent.atomic.AtomicLong) InvokeRequest(org.apache.ignite.internal.network.message.InvokeRequest) IgniteException(org.apache.ignite.lang.IgniteException) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException)

Example 2 with InvokeRequest

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);
}
Also used : NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) InetSocketAddress(java.net.InetSocketAddress) InvokeRequest(org.apache.ignite.internal.network.message.InvokeRequest)

Aggregations

InvokeRequest (org.apache.ignite.internal.network.message.InvokeRequest)2 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)2 InetSocketAddress (java.net.InetSocketAddress)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 InvokeResponse (org.apache.ignite.internal.network.message.InvokeResponse)1 ClassDescriptorRegistry (org.apache.ignite.internal.network.serialization.ClassDescriptorRegistry)1 DescriptorRegistry (org.apache.ignite.internal.network.serialization.DescriptorRegistry)1 IgniteException (org.apache.ignite.lang.IgniteException)1