Search in sources :

Example 6 with OutNetworkObject

use of org.apache.ignite.network.OutNetworkObject in project ignite-3 by apache.

the class RecoveryClientHandshakeManager method onMessage.

/**
 * {@inheritDoc}
 */
@Override
public HandshakeResult onMessage(Channel channel, NetworkMessage message) {
    if (message instanceof HandshakeStartMessage) {
        HandshakeStartMessage msg = (HandshakeStartMessage) message;
        UUID remoteLaunchId = msg.launchId();
        String remoteConsistentId = msg.consistentId();
        HandshakeStartResponseMessage response = messageFactory.handshakeStartResponseMessage().launchId(launchId).consistentId(consistentId).receivedCount(0).connectionsCount(0).build();
        ChannelFuture sendFuture = channel.writeAndFlush(new OutNetworkObject(response, Collections.emptyList()));
        NettyUtils.toCompletableFuture(sendFuture).whenComplete((unused, throwable) -> {
            if (throwable != null) {
                handshakeCompleteFuture.completeExceptionally(new HandshakeException("Failed to send handshake response: " + throwable.getMessage(), throwable));
            } else {
                handshakeCompleteFuture.complete(new NettySender(channel, remoteLaunchId.toString(), remoteConsistentId));
            }
        });
        return HandshakeResult.removeHandler(remoteLaunchId, remoteConsistentId);
    }
    handshakeCompleteFuture.completeExceptionally(new HandshakeException("Unexpected message during handshake: " + message.toString()));
    return HandshakeResult.fail();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) HandshakeStartMessage(org.apache.ignite.internal.network.recovery.message.HandshakeStartMessage) HandshakeStartResponseMessage(org.apache.ignite.internal.network.recovery.message.HandshakeStartResponseMessage) UUID(java.util.UUID) OutNetworkObject(org.apache.ignite.network.OutNetworkObject) HandshakeException(org.apache.ignite.internal.network.handshake.HandshakeException) NettySender(org.apache.ignite.internal.network.netty.NettySender)

Example 7 with OutNetworkObject

use of org.apache.ignite.network.OutNetworkObject in project ignite-3 by apache.

the class RecoveryServerHandshakeManager method onConnectionOpen.

/**
 * {@inheritDoc}
 */
@Override
public HandshakeResult onConnectionOpen(Channel channel) {
    HandshakeStartMessage handshakeStartMessage = messageFactory.handshakeStartMessage().launchId(launchId).consistentId(consistentId).build();
    ChannelFuture sendFuture = channel.writeAndFlush(new OutNetworkObject(handshakeStartMessage, Collections.emptyList()));
    NettyUtils.toCompletableFuture(sendFuture).whenComplete((unused, throwable) -> {
        if (throwable != null) {
            handshakeCompleteFuture.completeExceptionally(new HandshakeException("Failed to send handshake start message: " + throwable.getMessage(), throwable));
        }
    });
    return HandshakeResult.noOp();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) HandshakeStartMessage(org.apache.ignite.internal.network.recovery.message.HandshakeStartMessage) OutNetworkObject(org.apache.ignite.network.OutNetworkObject) HandshakeException(org.apache.ignite.internal.network.handshake.HandshakeException)

Aggregations

OutNetworkObject (org.apache.ignite.network.OutNetworkObject)7 NetworkMessage (org.apache.ignite.network.NetworkMessage)4 TestMessage (org.apache.ignite.network.TestMessage)4 InetSocketAddress (java.net.InetSocketAddress)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Test (org.junit.jupiter.api.Test)3 ChannelFuture (io.netty.channel.ChannelFuture)2 HandshakeException (org.apache.ignite.internal.network.handshake.HandshakeException)2 NettySender (org.apache.ignite.internal.network.netty.NettySender)2 HandshakeStartMessage (org.apache.ignite.internal.network.recovery.message.HandshakeStartMessage)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 DecoderException (io.netty.handler.codec.DecoderException)1 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)1 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)1 IntSet (it.unimi.dsi.fastutil.ints.IntSet)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1