Search in sources :

Example 1 with HandshakeException

use of org.apache.ignite.internal.network.handshake.HandshakeException 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 2 with HandshakeException

use of org.apache.ignite.internal.network.handshake.HandshakeException in project ignite-3 by apache.

the class RecoveryServerHandshakeManager method onMessage.

/**
 * {@inheritDoc}
 */
@Override
public HandshakeResult onMessage(Channel channel, NetworkMessage message) {
    if (message instanceof HandshakeStartResponseMessage) {
        HandshakeStartResponseMessage msg = (HandshakeStartResponseMessage) message;
        UUID remoteLaunchId = msg.launchId();
        String remoteConsistentId = msg.consistentId();
        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 : HandshakeStartResponseMessage(org.apache.ignite.internal.network.recovery.message.HandshakeStartResponseMessage) UUID(java.util.UUID) HandshakeException(org.apache.ignite.internal.network.handshake.HandshakeException) NettySender(org.apache.ignite.internal.network.netty.NettySender)

Example 3 with HandshakeException

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

Example 4 with HandshakeException

use of org.apache.ignite.internal.network.handshake.HandshakeException in project ignite-3 by apache.

the class HandshakeHandler method channelInactive.

/**
 * {@inheritDoc}
 */
@Override
public void channelInactive(ChannelHandlerContext ctx) {
    // If this method is called that means channel has been closed before handshake has finished or handshake
    // has failed.
    manager.handshakeFuture().completeExceptionally(new HandshakeException("Channel has been closed before handshake has finished or handshake has failed"));
    ctx.fireChannelInactive();
}
Also used : HandshakeException(org.apache.ignite.internal.network.handshake.HandshakeException)

Aggregations

HandshakeException (org.apache.ignite.internal.network.handshake.HandshakeException)4 ChannelFuture (io.netty.channel.ChannelFuture)2 UUID (java.util.UUID)2 NettySender (org.apache.ignite.internal.network.netty.NettySender)2 HandshakeStartMessage (org.apache.ignite.internal.network.recovery.message.HandshakeStartMessage)2 HandshakeStartResponseMessage (org.apache.ignite.internal.network.recovery.message.HandshakeStartResponseMessage)2 OutNetworkObject (org.apache.ignite.network.OutNetworkObject)2