Search in sources :

Example 1 with StreamingChannel

use of org.apache.cassandra.streaming.StreamingChannel in project cassandra by apache.

the class StreamingMultiplexedChannel method createChannel.

private StreamingChannel createChannel(StreamingChannel.Kind kind) throws IOException {
    logger.debug("Creating stream session to {} as {}", to, session.isFollower() ? "follower" : "initiator");
    StreamingChannel channel = factory.create(to, messagingVersion, kind);
    if (kind == StreamingChannel.Kind.CONTROL) {
        executorFactory().startThread(String.format("Stream-Deserializer-%s-%s", to.toString(), channel.id()), new StreamDeserializingTask(session, channel, messagingVersion));
        session.attachInbound(channel);
    }
    session.attachOutbound(channel);
    logger.debug("Creating {}", channel.description());
    return channel;
}
Also used : StreamingChannel(org.apache.cassandra.streaming.StreamingChannel) StreamDeserializingTask(org.apache.cassandra.streaming.StreamDeserializingTask)

Example 2 with StreamingChannel

use of org.apache.cassandra.streaming.StreamingChannel 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

StreamingChannel (org.apache.cassandra.streaming.StreamingChannel)2 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 StreamDeserializingTask (org.apache.cassandra.streaming.StreamDeserializingTask)1