Class SocketOptions
- java.lang.Object
-
- com.datastax.driver.core.SocketOptions
-
public class SocketOptions extends Object
Options to configure low-level socket options for the connections kept to the Cassandra hosts.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CONNECT_TIMEOUT_MILLISThe default connection timeout in milliseconds if none is set explicitly usingsetConnectTimeoutMillis(int).static intDEFAULT_READ_TIMEOUT_MILLISThe default read timeout in milliseconds if none is set explicitly usingsetReadTimeoutMillis(int).
-
Constructor Summary
Constructors Constructor Description SocketOptions()Creates a newSocketOptionsinstance with default values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetConnectTimeoutMillis()The connection timeout in milliseconds.BooleangetKeepAlive()Returns whether TCP keepalive is enabled.intgetReadTimeoutMillis()The per-host read timeout in milliseconds.IntegergetReceiveBufferSize()Returns the hint to the size of the underlying buffers for incoming network I/O.BooleangetReuseAddress()Returns whether reuse-address is enabled.IntegergetSendBufferSize()Returns the hint to the size of the underlying buffers for outgoing network I/O.IntegergetSoLinger()Returns the linger-on-close timeout.BooleangetTcpNoDelay()Returns whether Nagle's algorithm is disabled.SocketOptionssetConnectTimeoutMillis(int connectTimeoutMillis)Sets the connection timeout in milliseconds.SocketOptionssetKeepAlive(boolean keepAlive)Sets whether to enable TCP keepalive.SocketOptionssetReadTimeoutMillis(int readTimeoutMillis)Sets the per-host read timeout in milliseconds.SocketOptionssetReceiveBufferSize(int receiveBufferSize)Sets a hint to the size of the underlying buffers for incoming network I/O.SocketOptionssetReuseAddress(boolean reuseAddress)Sets whether to enable reuse-address.SocketOptionssetSendBufferSize(int sendBufferSize)Sets a hint to the size of the underlying buffers for outgoing network I/O.SocketOptionssetSoLinger(int soLinger)Sets the linger-on-close timeout.SocketOptionssetTcpNoDelay(boolean tcpNoDelay)Sets whether to disable Nagle's algorithm.
-
-
-
Field Detail
-
DEFAULT_CONNECT_TIMEOUT_MILLIS
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS
The default connection timeout in milliseconds if none is set explicitly usingsetConnectTimeoutMillis(int).That default is of 5 seconds.
- See Also:
- Constant Field Values
-
DEFAULT_READ_TIMEOUT_MILLIS
public static final int DEFAULT_READ_TIMEOUT_MILLIS
The default read timeout in milliseconds if none is set explicitly usingsetReadTimeoutMillis(int).That default is of 12 seconds so as to be slightly bigger that the default Cassandra timeout.
-
-
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 theRetryPolicyin use. In other words, aSession.execute(java.lang.String)call may theoretically wait up togetReadTimeoutMillis() * <number_of_cassandra_hosts>(though the total number of hosts tried for a given query also depends on theLoadBalancingPolicyin use). If you want to control how long to wait for a query, useSession.executeAsync(java.lang.String)and theResultSetFuture#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_msincassandra.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 theFuture.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.
- it should be higher than the timeout settings used on the Cassandra side (
-
getKeepAlive
public Boolean getKeepAlive()
Returns whether TCP keepalive is enabled.- Returns:
- the value of the option, or
nullif 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
nullif 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
nullif 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 (
truemeans Nagle is disabled), ornullif 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
nullif 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
nullif 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
-
-