Search in sources :

Example 1 with DescriptorRegistry

use of org.apache.ignite.internal.network.serialization.DescriptorRegistry 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)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)1 InvokeRequest (org.apache.ignite.internal.network.message.InvokeRequest)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 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)1