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() |
int |
getReadTimeoutMillis()
The per-host read timeout in milliseconds.
|
Integer |
getReceiveBufferSize() |
Boolean |
getReuseAddress() |
Integer |
getSendBufferSize() |
Integer |
getSoLinger() |
Boolean |
getTcpNoDelay() |
SocketOptions |
setConnectTimeoutMillis(int connectTimeoutMillis)
Sets the connection timeout in milliseconds.
|
SocketOptions |
setKeepAlive(boolean keepAlive) |
SocketOptions |
setReadTimeoutMillis(int readTimeoutMillis)
Sets the per-host read timeout in milliseconds.
|
SocketOptions |
setReceiveBufferSize(int receiveBufferSize) |
SocketOptions |
setReuseAddress(boolean reuseAddress) |
SocketOptions |
setSendBufferSize(int sendBufferSize) |
SocketOptions |
setSoLinger(int soLinger) |
SocketOptions |
setTcpNoDelay(boolean tcpNoDelay) |
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()
As the name implies, the connection timeout defines how long the driver waits to etablish a new connection to a Cassandra node before giving up.
public SocketOptions setConnectTimeoutMillis(int connectTimeoutMillis)
connectTimeoutMillis
- the timeout to set.SocketOptions
.public int getReadTimeoutMillis()
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 call will wait for one particular
Cassandra host, but other hosts will be tried if one of them timeout. 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)
When setting this value, keep in mind the following:
*_request_timeout_in_ms
in cassandra.yaml
) should be taken into account when picking a value for this
read timeout. In particular, if this read timeout option is lower than Cassandra's
timeout, the driver will try another host before it has had the time to receive the
Cassandra timeout. This might be counter-productive.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, TimeUnit)
method.
Setting a value of 0 disables read timeouts.
readTimeoutMillis
- the timeout to set.SocketOptions
.public Boolean getKeepAlive()
public SocketOptions setKeepAlive(boolean keepAlive)
public Boolean getReuseAddress()
public SocketOptions setReuseAddress(boolean reuseAddress)
public Integer getSoLinger()
public SocketOptions setSoLinger(int soLinger)
public Boolean getTcpNoDelay()
public SocketOptions setTcpNoDelay(boolean tcpNoDelay)
public Integer getReceiveBufferSize()
public SocketOptions setReceiveBufferSize(int receiveBufferSize)
public Integer getSendBufferSize()
public SocketOptions setSendBufferSize(int sendBufferSize)
Copyright © 2014. All Rights Reserved.