Example usage for org.apache.cassandra.net MessagingService current_version

List of usage examples for org.apache.cassandra.net MessagingService current_version

Introduction

In this page you can find the example usage for org.apache.cassandra.net MessagingService current_version.

Prototype

int current_version

To view the source code for org.apache.cassandra.net MessagingService current_version.

Click Source Link

Usage

From source file:com.csforge.sstable.StorageConnection.java

License:Apache License

public boolean connect() {
    long start = System.nanoTime();
    long timeout = TimeUnit.MILLISECONDS.toNanos(DatabaseDescriptor.getRpcTimeout());
    while (System.nanoTime() - start < timeout) {
        targetVersion = 10;//from   www  .j  a v a2 s  .c  o  m
        try {
            SocketChannel channel = SocketChannel.open();
            if (!Config.getOutboundBindAny())
                channel.bind(new InetSocketAddress(FBUtilities.getLocalAddress(), 0));
            channel.connect(new InetSocketAddress(host, DatabaseDescriptor.getStoragePort()));
            socket = channel.socket();
            socket.setTcpNoDelay(true);
            if (DatabaseDescriptor.getInternodeSendBufferSize() != null) {
                try {
                    socket.setSendBufferSize(DatabaseDescriptor.getInternodeSendBufferSize());
                } catch (SocketException se) {
                    System.err.println("Failed to set send buffer size on internode socket." + se);
                }
            }

            // SocketChannel may be null when using SSL
            WritableByteChannel ch = socket.getChannel();
            out = new BufferedDataOutputStreamPlus(
                    ch != null ? ch : Channels.newChannel(socket.getOutputStream()), BUFFER_SIZE);

            out.writeInt(MessagingService.PROTOCOL_MAGIC);
            writeHeader(out, targetVersion, false);
            out.flush();

            DataInputStream in = new DataInputStream(socket.getInputStream());
            int maxTargetVersion = in.readInt();
            MessagingService.instance().setVersion(host, maxTargetVersion);

            out.writeInt(MessagingService.current_version);
            CompactEndpointSerializationHelper.serialize(FBUtilities.getBroadcastAddress(), out);
            out.flush();
            return true;
        } catch (IOException e) {
            socket = null;
            e.printStackTrace();
            System.err.println("unable to connect to " + host + e);
            Uninterruptibles.sleepUninterruptibly(OPEN_RETRY_DELAY, TimeUnit.MILLISECONDS);
        }
    }
    return false;
}