Search in sources :

Example 1 with StreamingDataOutputPlus

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

the class StreamingMultiplexedChannel method sendMessage.

public Future<?> sendMessage(StreamingChannel channel, StreamMessage message) {
    if (closed)
        throw new RuntimeException("stream has been closed, cannot send " + message);
    if (message instanceof OutgoingStreamMessage) {
        if (session.isPreview())
            throw new RuntimeException("Cannot send stream data messages for preview streaming sessions");
        if (logger.isDebugEnabled())
            logger.debug("{} Sending {}", createLogTag(session), message);
        return fileTransferExecutor.submit(new FileStreamTask((OutgoingStreamMessage) message));
    }
    try {
        Future<?> promise = channel.send(outSupplier -> {
            // we anticipate that the control messages are rather small, so allocating a ByteBuf shouldn't  blow out of memory.
            long messageSize = serializedSize(message, messagingVersion);
            if (messageSize > 1 << 30) {
                throw new IllegalStateException(format("%s something is seriously wrong with the calculated stream control message's size: %d bytes, type is %s", createLogTag(session, controlChannel.id()), messageSize, message.type));
            }
            try (StreamingDataOutputPlus out = outSupplier.apply((int) messageSize)) {
                StreamMessage.serialize(message, out, messagingVersion, session);
            }
        });
        promise.addListener(future -> onMessageComplete(future, message));
        return promise;
    } catch (Exception e) {
        close();
        session.onError(e);
        return ImmediateFuture.failure(e);
    }
}
Also used : OutgoingStreamMessage(org.apache.cassandra.streaming.messages.OutgoingStreamMessage) StreamingDataOutputPlus(org.apache.cassandra.streaming.StreamingDataOutputPlus) IOException(java.io.IOException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Aggregations

IOException (java.io.IOException)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 StreamingDataOutputPlus (org.apache.cassandra.streaming.StreamingDataOutputPlus)1 OutgoingStreamMessage (org.apache.cassandra.streaming.messages.OutgoingStreamMessage)1 UncheckedInterruptedException (org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)1