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