public class SocketOptions extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CONNECT_TIMEOUT_MILLIS
The default connection timeout in milliseconds if none is set explicitly
using
setConnectTimeoutMillis(int) . |
static int |
DEFAULT_READ_TIMEOUT_MILLIS
The default read timeout in milliseconds if none is set explicitly
using
setReadTimeoutMillis(int) . |
Constructor and Description |
---|
SocketOptions()
Creates a new
SocketOptions instance with default values. |
Modifier and Type | Method and Description |
---|---|
int |
getConnectTimeoutMillis()
The connection timeout in milliseconds.
|
Boolean |
getKeepAlive()
Returns whether TCP keepalive is enabled.
|
int |
getReadTimeoutMillis()
The per-host read timeout in milliseconds.
|
Integer |
getReceiveBufferSize()
Returns the hint to the size of the underlying buffers for incoming network I/O.
|
Boolean |
getReuseAddress()
Returns whether reuse-address is enabled.
|
Integer |
getSendBufferSize()
Returns the hint to the size of the underlying buffers for outgoing network I/O.
|
Integer |
getSoLinger()
Returns the linger-on-close timeout.
|
Boolean |
getTcpNoDelay()
Returns whether Nagle's algorithm is disabled.
|
SocketOptions |
setConnectTimeoutMillis(int connectTimeoutMillis)
Sets the connection timeout in milliseconds.
|
SocketOptions |
setKeepAlive(boolean keepAlive)
Sets whether to enable TCP keepalive.
|
SocketOptions |
setReadTimeoutMillis(int readTimeoutMillis)
Sets the per-host read timeout in milliseconds.
|
SocketOptions |
setReceiveBufferSize(int receiveBufferSize)
Sets a hint to the size of the underlying buffers for incoming network I/O.
|
SocketOptions |
setReuseAddress(boolean reuseAddress)
Sets whether to enable reuse-address.
|
SocketOptions |
setSendBufferSize(int sendBufferSize)
Sets a hint to the size of the underlying buffers for outgoing network I/O.
|
SocketOptions |
setSoLinger(int soLinger)
Sets the linger-on-close timeout.
|
SocketOptions |
setTcpNoDelay(boolean tcpNoDelay)
Sets whether to disable Nagle's algorithm.
|
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS
setConnectTimeoutMillis(int)
.
That default is of 5 seconds.public static final int DEFAULT_READ_TIMEOUT_MILLIS
setReadTimeoutMillis(int)
.
That default is of 12 seconds so as to be slightly bigger that the
default Cassandra timeout.public SocketOptions()
SocketOptions
instance with default values.public int getConnectTimeoutMillis()
public SocketOptions setConnectTimeoutMillis(int connectTimeoutMillis)
DEFAULT_CONNECT_TIMEOUT_MILLIS
.connectTimeoutMillis
- the timeout to set.SocketOptions
.public int getReadTimeoutMillis()
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.
public SocketOptions setReadTimeoutMillis(int readTimeoutMillis)
*_request_timeout_in_ms
in cassandra.yaml
).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.
DEFAULT_READ_TIMEOUT_MILLIS
.readTimeoutMillis
- the timeout to set. If it is less than or equal to 0, read timeouts are disabled.SocketOptions
.public Boolean getKeepAlive()
null
if it is not set.setKeepAlive(boolean)
public SocketOptions setKeepAlive(boolean keepAlive)
keepAlive
- whether to enable or disable the option.SocketOptions
.SocketOptions.TCP_NODELAY
public Boolean getReuseAddress()
null
if it is not set.setReuseAddress(boolean)
public SocketOptions setReuseAddress(boolean reuseAddress)
reuseAddress
- whether to enable or disable the option.SocketOptions
.SocketOptions.SO_REUSEADDR
public Integer getSoLinger()
null
if it is not set.setSoLinger(int)
public SocketOptions setSoLinger(int soLinger)
soLinger
- the new value.SocketOptions
.SocketOptions.SO_LINGER
public Boolean getTcpNoDelay()
true
means Nagle is disabled), or null
if it is not set.setTcpNoDelay(boolean)
public SocketOptions setTcpNoDelay(boolean tcpNoDelay)
true
(Nagle disabled).tcpNoDelay
- whether to enable or disable the option.SocketOptions
.SocketOptions.TCP_NODELAY
public Integer getReceiveBufferSize()
null
if it is not set.setReceiveBufferSize(int)
public SocketOptions setReceiveBufferSize(int receiveBufferSize)
receiveBufferSize
- the new value.SocketOptions
.SocketOptions.SO_RCVBUF
public Integer getSendBufferSize()
null
if it is not set.setSendBufferSize(int)
public SocketOptions setSendBufferSize(int sendBufferSize)
sendBufferSize
- the new value.SocketOptions
.SocketOptions.SO_SNDBUF
Copyright © 2012–2017. All rights reserved.