Class SocketOptions


  • public class SocketOptions
    extends Object
    Options to configure low-level socket options for the connections kept to the Cassandra hosts.
    • Constructor Detail

      • SocketOptions

        public SocketOptions()
        Creates a new SocketOptions instance with default values.
    • Method Detail

      • getConnectTimeoutMillis

        public int getConnectTimeoutMillis()
        The connection timeout in milliseconds.

        As the name implies, the connection timeout defines how long the driver waits to establish a new connection to a Cassandra node before giving up.

        Returns:
        the connection timeout in milliseconds
      • setConnectTimeoutMillis

        public SocketOptions setConnectTimeoutMillis​(int connectTimeoutMillis)
        Sets the connection timeout in milliseconds.

        The default value is DEFAULT_CONNECT_TIMEOUT_MILLIS.

        Parameters:
        connectTimeoutMillis - the timeout to set.
        Returns:
        this SocketOptions.
      • getReadTimeoutMillis

        public int getReadTimeoutMillis()
        The per-host read timeout in milliseconds.

        This defines how long the driver will wait for a given Cassandra node to answer a query.

        Please note that this is not the maximum time a call to Session.execute(java.lang.String) may block; this is the maximum time that a call will wait for one particular Cassandra host, but other hosts could be tried if one of them times out, depending on the RetryPolicy in use. In other words, a Session.execute(java.lang.String) call may theoretically wait up to getReadTimeoutMillis() * <number_of_cassandra_hosts> (though the total number of hosts tried for a given query also depends on the LoadBalancingPolicy in use). If you want to control how long to wait for a query, use Session.executeAsync(java.lang.String) and the ResultSetFuture#get(long, TimeUnit) method.

        Also note that for efficiency reasons, this read timeout is approximate: it has an accuracy of up to 100 milliseconds (i.e. it may fire up to 100 milliseconds late). It is not meant to be used for precise timeout, but rather as a protection against misbehaving Cassandra nodes.

        Returns:
        the read timeout in milliseconds.
      • setReadTimeoutMillis

        public SocketOptions setReadTimeoutMillis​(int readTimeoutMillis)
        Sets the per-host read timeout in milliseconds.

        When setting this value, keep in mind the following:

        • it should be higher than the timeout settings used on the Cassandra side ( *_request_timeout_in_ms in cassandra.yaml).
        • the read timeout is only approximate and only control the timeout to one Cassandra host, not the full query (see getReadTimeoutMillis() for more details). If a high level of precision on the timeout to a request is required, you should use the Future.get(long, java.util.concurrent.TimeUnit) method.

        If you don't call this method, the default value is DEFAULT_READ_TIMEOUT_MILLIS.

        Parameters:
        readTimeoutMillis - the timeout to set. If it is less than or equal to 0, read timeouts are disabled.
        Returns:
        this SocketOptions.
      • getKeepAlive

        public Boolean getKeepAlive()
        Returns whether TCP keepalive is enabled.
        Returns:
        the value of the option, or null if it is not set.
        See Also:
        setKeepAlive(boolean)
      • setKeepAlive

        public SocketOptions setKeepAlive​(boolean keepAlive)
        Sets whether to enable TCP keepalive.

        By default, this option is not set by the driver. The actual value will be the default from the underlying Netty transport (Java NIO or native epoll).

        Parameters:
        keepAlive - whether to enable or disable the option.
        Returns:
        this SocketOptions.
        See Also:
        SocketOptions.TCP_NODELAY
      • getReuseAddress

        public Boolean getReuseAddress()
        Returns whether reuse-address is enabled.
        Returns:
        the value of the option, or null if it is not set.
        See Also:
        setReuseAddress(boolean)
      • setReuseAddress

        public SocketOptions setReuseAddress​(boolean reuseAddress)
        Sets whether to enable reuse-address.

        By default, this option is not set by the driver. The actual value will be the default from the underlying Netty transport (Java NIO or native epoll).

        Parameters:
        reuseAddress - whether to enable or disable the option.
        Returns:
        this SocketOptions.
        See Also:
        SocketOptions.SO_REUSEADDR
      • getSoLinger

        public Integer getSoLinger()
        Returns the linger-on-close timeout.
        Returns:
        the value of the option, or null if it is not set.
        See Also:
        setSoLinger(int)
      • setSoLinger

        public SocketOptions setSoLinger​(int soLinger)
        Sets the linger-on-close timeout.

        By default, this option is not set by the driver. The actual value will be the default from the underlying Netty transport (Java NIO or native epoll).

        Parameters:
        soLinger - the new value.
        Returns:
        this SocketOptions.
        See Also:
        SocketOptions.SO_LINGER
      • getTcpNoDelay

        public Boolean getTcpNoDelay()
        Returns whether Nagle's algorithm is disabled.
        Returns:
        the value of the option (true means Nagle is disabled), or null if it is not set.
        See Also:
        setTcpNoDelay(boolean)
      • setTcpNoDelay

        public SocketOptions setTcpNoDelay​(boolean tcpNoDelay)
        Sets whether to disable Nagle's algorithm.

        By default, this option is set to true (Nagle disabled).

        Parameters:
        tcpNoDelay - whether to enable or disable the option.
        Returns:
        this SocketOptions.
        See Also:
        SocketOptions.TCP_NODELAY
      • getReceiveBufferSize

        public Integer getReceiveBufferSize()
        Returns the hint to the size of the underlying buffers for incoming network I/O.
        Returns:
        the value of the option, or null if it is not set.
        See Also:
        setReceiveBufferSize(int)
      • setReceiveBufferSize

        public SocketOptions setReceiveBufferSize​(int receiveBufferSize)
        Sets a hint to the size of the underlying buffers for incoming network I/O.

        By default, this option is not set by the driver. The actual value will be the default from the underlying Netty transport (Java NIO or native epoll).

        Parameters:
        receiveBufferSize - the new value.
        Returns:
        this SocketOptions.
        See Also:
        SocketOptions.SO_RCVBUF
      • getSendBufferSize

        public Integer getSendBufferSize()
        Returns the hint to the size of the underlying buffers for outgoing network I/O.
        Returns:
        the value of the option, or null if it is not set.
        See Also:
        setSendBufferSize(int)
      • setSendBufferSize

        public SocketOptions setSendBufferSize​(int sendBufferSize)
        Sets a hint to the size of the underlying buffers for outgoing network I/O.

        By default, this option is not set by the driver. The actual value will be the default from the underlying Netty transport (Java NIO or native epoll).

        Parameters:
        sendBufferSize - the new value.
        Returns:
        this SocketOptions.
        See Also:
        SocketOptions.SO_SNDBUF