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());
}
}
Aggregations