Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *      Copyright (C) 2012 DataStax Inc.
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  *   Unless required by applicable law or agreed to in writing, software
  *   distributed under the License is distributed on an "AS IS" BASIS,
  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *   See the License for the specific language governing permissions and
  *   limitations under the License.
  */
 package com.datastax.driver.core;

Options to configure low-level socket options for the connections kept to the Cassandra hosts.
 
 public class SocketOptions {

    
The default connection timeout in milliseconds if none is set explicitly using setConnectTimeoutMillis(int).

That default is of 5 seconds.

 
     public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 5000;

    
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:
getReadTimeoutMillis() for more details on this timeout.
 
     public static final int DEFAULT_READ_TIMEOUT_MILLIS = 12000;
 
     private volatile int connectTimeoutMillis = ;
     private volatile int readTimeoutMillis = ;
     private volatile Boolean keepAlive;
     private volatile Boolean reuseAddress;
     private volatile Integer soLinger;
     private volatile Boolean tcpNoDelay;
     private volatile Integer receiveBufferSize;
     private volatile Integer sendBufferSize;

    
Creates a new SocketOptions instance with default values.
 
     public SocketOptions() {}

    
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
 
     public int getConnectTimeoutMillis() {
         return ;
     }

    
Sets the connection timeout in milliseconds.

Parameters:
connectTimeoutMillis the timeout to set.
Returns:
this SocketOptions.
 
     public SocketOptions setConnectTimeoutMillis(int connectTimeoutMillis) {
         this. = connectTimeoutMillis;
         return this;
     }

    
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 com.datastax.driver.core.policies.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.
    public int getReadTimeoutMillis() {
        return ;
    }

    
Sets the per-host read timeout in milliseconds.

When setting this value, keep in mind the following:

  • the timeout settings used on the Cassandra side (*_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.
  • 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 ResultSetFuture#get(long , TimeUnit ) method.

Setting a value of 0 disables read timeouts.

Parameters:
readTimeoutMillis the timeout to set.
Returns:
this SocketOptions.
    public SocketOptions setReadTimeoutMillis(int readTimeoutMillis) {
        this. = readTimeoutMillis;
        return this;
    }
    public Boolean getKeepAlive() {
        return ;
    }
    public SocketOptions setKeepAlive(boolean keepAlive) {
        this. = keepAlive;
        return this;
    }
    public Boolean getReuseAddress() {
        return ;
    }
    public SocketOptions setReuseAddress(boolean reuseAddress) {
        this. = reuseAddress;
        return this;
    }
    public Integer getSoLinger() {
        return ;
    }
    public SocketOptions setSoLinger(int soLinger) {
        this. = soLinger;
        return this;
    }
    public Boolean getTcpNoDelay() {
        return ;
    }
    public SocketOptions setTcpNoDelay(boolean tcpNoDelay) {
        this. = tcpNoDelay;
        return this;
    }
    public Integer getReceiveBufferSize() {
        return ;
    }
    public SocketOptions setReceiveBufferSize(int receiveBufferSize) {
        this. = receiveBufferSize;
        return this;
    }
    public Integer getSendBufferSize() {
        return ;
    }
    public SocketOptions setSendBufferSize(int sendBufferSize) {
        this. = sendBufferSize;
        return this;
    }
New to GrepCode? Check out our FAQ X