com.datastax.driver.core
Class PoolingOptions

java.lang.Object
  extended by com.datastax.driver.core.PoolingOptions

public class PoolingOptions
extends Object

Options related to connection pooling.

The driver uses connections in an asynchronous way. Meaning that multiple requests can be submitted on the same connection at the same time. This means that the driver only needs to maintain a relatively small number of connections to each Cassandra host. These options allow to control how many connections are kept exactly.

For each host, the driver keeps a core amount of connections open at all time (getCoreConnectionsPerHost(com.datastax.driver.core.HostDistance)). If the utilisation of those connections reaches a configurable threshold (getMaxSimultaneousRequestsPerConnectionTreshold(com.datastax.driver.core.HostDistance)), more connections are created up to a configurable maximum number of connections (getMaxConnectionPerHost(com.datastax.driver.core.HostDistance)). Once more than core connections have been created, connections in excess are reclaimed if the utilisation of opened connections drops below the configured threshold (getMinSimultaneousRequestsPerConnectionTreshold(com.datastax.driver.core.HostDistance)).

Each of these parameters can be separately set for LOCAL and REMOTE hosts (HostDistance). For IGNORED hosts, the default for all those settings is 0 and cannot be changed.


Constructor Summary
PoolingOptions()
           
 
Method Summary
 int getCoreConnectionsPerHost(HostDistance distance)
          The core number of connections per host.
 int getMaxConnectionPerHost(HostDistance distance)
          The maximum number of connections per host.
 int getMaxSimultaneousRequestsPerConnectionTreshold(HostDistance distance)
          Number of simultaneous requests on all connections to an host after which more connections are created.
 int getMinSimultaneousRequestsPerConnectionTreshold(HostDistance distance)
          Number of simultaneous requests on a connection below which connections in excess are reclaimed.
 PoolingOptions setCoreConnectionsPerHost(HostDistance distance, int coreConnections)
          Sets the core number of connections per host.
 PoolingOptions setMaxConnectionsPerHost(HostDistance distance, int maxConnections)
          Sets the maximum number of connections per host.
 PoolingOptions setMaxSimultaneousRequestsPerConnectionTreshold(HostDistance distance, int maxSimultaneousRequests)
          Sets number of simultaneous requests on all connections to an host after which more connections are created.
 PoolingOptions setMinSimultaneousRequestsPerConnectionTreshold(HostDistance distance, int minSimultaneousRequests)
          Sets the number of simultaneous requests on a connection below which connections in excess are reclaimed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PoolingOptions

public PoolingOptions()
Method Detail

getMinSimultaneousRequestsPerConnectionTreshold

public int getMinSimultaneousRequestsPerConnectionTreshold(HostDistance distance)
Number of simultaneous requests on a connection below which connections in excess are reclaimed.

If an opened connection to an host at distance distance handles less than this number of simultaneous requests and there is more than getCoreConnectionsPerHost(com.datastax.driver.core.HostDistance) connections open to this host, the connection is closed.

The default value for this option is 25 for LOCAL and REMOTE hosts.

Parameters:
distance - the HostDistance for which to return this threshold.
Returns:
the configured threshold, or the default one if none have been set.

setMinSimultaneousRequestsPerConnectionTreshold

public PoolingOptions setMinSimultaneousRequestsPerConnectionTreshold(HostDistance distance,
                                                                      int minSimultaneousRequests)
Sets the number of simultaneous requests on a connection below which connections in excess are reclaimed.

Parameters:
distance - the HostDistance for which to configure this threshold.
minSimultaneousRequests - the value to set.
Returns:
this PoolingOptions.
Throws:
IllegalArgumentException - if distance == HostDistance.IGNORED.

getMaxSimultaneousRequestsPerConnectionTreshold

public int getMaxSimultaneousRequestsPerConnectionTreshold(HostDistance distance)
Number of simultaneous requests on all connections to an host after which more connections are created.

If all the connections opened to an host at distance distance connection are handling more than this number of simultaneous requests and there is less than getMaxConnectionPerHost(com.datastax.driver.core.HostDistance) connections open to this host, a new connection is open.

Note that a given connection cannot handle more than 128 simultaneous requests (protocol limitation).

The default value for this option is 100 for LOCAL and REMOTE hosts.

Parameters:
distance - the HostDistance for which to return this threshold.
Returns:
the configured threshold, or the default one if none have been set.

setMaxSimultaneousRequestsPerConnectionTreshold

public PoolingOptions setMaxSimultaneousRequestsPerConnectionTreshold(HostDistance distance,
                                                                      int maxSimultaneousRequests)
Sets number of simultaneous requests on all connections to an host after which more connections are created.

Parameters:
distance - the HostDistance for which to configure this threshold.
maxSimultaneousRequests - the value to set.
Returns:
this PoolingOptions.
Throws:
IllegalArgumentException - if distance == HostDistance.IGNORED.

getCoreConnectionsPerHost

public int getCoreConnectionsPerHost(HostDistance distance)
The core number of connections per host.

For the provided distance, this correspond to the number of connections initially created and kept open to each host of that distance.

Parameters:
distance - the HostDistance for which to return this threshold.
Returns:
the core number of connections per host at distance distance.

setCoreConnectionsPerHost

public PoolingOptions setCoreConnectionsPerHost(HostDistance distance,
                                                int coreConnections)
Sets the core number of connections per host.

Parameters:
distance - the HostDistance for which to set this threshold.
coreConnections - the value to set
Returns:
this PoolingOptions.
Throws:
IllegalArgumentException - if distance == HostDistance.IGNORED.

getMaxConnectionPerHost

public int getMaxConnectionPerHost(HostDistance distance)
The maximum number of connections per host.

For the provided distance, this correspond to the maximum number of connections that can be created per host at that distance.

Parameters:
distance - the HostDistance for which to return this threshold.
Returns:
the maximum number of connections per host at distance distance.

setMaxConnectionsPerHost

public PoolingOptions setMaxConnectionsPerHost(HostDistance distance,
                                               int maxConnections)
Sets the maximum number of connections per host.

Parameters:
distance - the HostDistance for which to set this threshold.
maxConnections - the value to set
Returns:
this PoolingOptions.
Throws:
IllegalArgumentException - if distance == HostDistance.IGNORED.


Copyright © 2013. All Rights Reserved.