Search in sources :

Example 1 with Result

use of org.apache.cassandra.net.OutboundConnectionInitiator.Result in project cassandra by apache.

the class NettyStreamingConnectionFactory method connect.

public static NettyStreamingChannel connect(OutboundConnectionSettings template, int messagingVersion, StreamingChannel.Kind kind) throws IOException {
    EventLoop eventLoop = MessagingService.instance().socketFactory.outboundStreamingGroup().next();
    int attempts = 0;
    while (true) {
        Future<Result<StreamingSuccess>> result = initiateStreaming(eventLoop, template.withDefaults(ConnectionCategory.STREAMING), messagingVersion);
        // initiate has its own timeout, so this is "guaranteed" to return relatively promptly
        result.awaitUninterruptibly();
        if (result.isSuccess()) {
            Channel channel = result.getNow().success().channel;
            NettyStreamingChannel streamingChannel = new NettyStreamingChannel(messagingVersion, channel, kind);
            if (kind == StreamingChannel.Kind.CONTROL) {
                ChannelPipeline pipeline = channel.pipeline();
                pipeline.addLast("stream", streamingChannel);
            }
            return streamingChannel;
        }
        if (++attempts == MAX_CONNECT_ATTEMPTS)
            throw new IOException("failed to connect to " + template.to + " for streaming data", result.cause());
    }
}
Also used : EventLoop(io.netty.channel.EventLoop) Channel(io.netty.channel.Channel) StreamingChannel(org.apache.cassandra.streaming.StreamingChannel) IOException(java.io.IOException) ChannelPipeline(io.netty.channel.ChannelPipeline) Result(org.apache.cassandra.net.OutboundConnectionInitiator.Result)

Aggregations

Channel (io.netty.channel.Channel)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 EventLoop (io.netty.channel.EventLoop)1 IOException (java.io.IOException)1 Result (org.apache.cassandra.net.OutboundConnectionInitiator.Result)1 StreamingChannel (org.apache.cassandra.streaming.StreamingChannel)1