com.datastax.driver.core
Class SocketOptions

java.lang.Object
  extended by 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
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 Summary
SocketOptions()
          Creates a new SocketOptions instance with default values.
 
Method Summary
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 using setConnectTimeoutMillis(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 using setReadTimeoutMillis(int).

That default is of 12 seconds so as to be slightly bigger that the default Cassandra timeout.

See Also:
for more details on this timeout., Constant Field Values
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 etablish 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.

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 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.

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:

Setting a value of 0 disables read timeouts.

Parameters:
readTimeoutMillis - the timeout to set.
Returns:
this SocketOptions.

getKeepAlive

public Boolean getKeepAlive()

setKeepAlive

public SocketOptions setKeepAlive(boolean keepAlive)

getReuseAddress

public Boolean getReuseAddress()

setReuseAddress

public SocketOptions setReuseAddress(boolean reuseAddress)

getSoLinger

public Integer getSoLinger()

setSoLinger

public SocketOptions setSoLinger(int soLinger)

getTcpNoDelay

public Boolean getTcpNoDelay()

setTcpNoDelay

public SocketOptions setTcpNoDelay(boolean tcpNoDelay)

getReceiveBufferSize

public Integer getReceiveBufferSize()

setReceiveBufferSize

public SocketOptions setReceiveBufferSize(int receiveBufferSize)

getSendBufferSize

public Integer getSendBufferSize()

setSendBufferSize

public SocketOptions setSendBufferSize(int sendBufferSize)


Copyright © 2013. All rights reserved.