use of org.apache.cassandra.io.util.NIODataInputStream in project cassandra by apache.
the class IncomingTcpConnection method receiveMessages.
// Not closing constructed DataInputPlus's as the stream needs to remain open.
@SuppressWarnings("resource")
private void receiveMessages() throws IOException {
// handshake (true) endpoint versions
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
// if this version is < the MS version the other node is trying
// to connect with, the other node will disconnect
out.writeInt(MessagingService.current_version);
out.flush();
DataInputPlus in = new DataInputStreamPlus(socket.getInputStream());
int maxVersion = in.readInt();
// outbound side will reconnect if necessary to upgrade version
assert version <= MessagingService.current_version;
from = CompactEndpointSerializationHelper.deserialize(in);
// record the (true) version of the endpoint
MessagingService.instance().setVersion(from, maxVersion);
logger.trace("Set version for {} to {} (will use {})", from, maxVersion, MessagingService.instance().getVersion(from));
if (compressed) {
logger.trace("Upgrading incoming connection to be compressed");
LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
Checksum checksum = XXHashFactory.fastestInstance().newStreamingHash32(OutboundTcpConnection.LZ4_HASH_SEED).asChecksum();
in = new DataInputStreamPlus(new LZ4BlockInputStream(socket.getInputStream(), decompressor, checksum));
} else {
ReadableByteChannel channel = socket.getChannel();
in = new NIODataInputStream(channel != null ? channel : Channels.newChannel(socket.getInputStream()), BUFFER_SIZE);
}
while (true) {
MessagingService.validateMagic(in.readInt());
receiveMessage(in, version);
}
}
Aggregations