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 manner. 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 the driver to control how many connections are kept exactly.

For each host, the driver keeps a core pool of connections open at all times determined by calling (getCoreConnectionsPerHost(com.datastax.driver.core.HostDistance)). If the use of those connections reaches a configurable threshold (getMaxSimultaneousRequestsPerConnectionThreshold(com.datastax.driver.core.HostDistance)), more connections are created up to the configurable maximum number of connections (getMaxConnectionsPerHost(com.datastax.driver.core.HostDistance)). When the pool exceeds the maximum number of connections, connections in excess are reclaimed if the use of opened connections drops below the configured threshold (getMinSimultaneousRequestsPerConnectionThreshold(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)
          Returns the core number of connections per host.
 int getMaxConnectionsPerHost(HostDistance distance)
          Returns the maximum number of connections per host.
 int getMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
          Returns the number of simultaneous requests on all connections to an host after which more connections are created.
 int getMinSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
          Returns the 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 setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance, int maxSimultaneousRequests)
          Sets number of simultaneous requests on all connections to an host after which more connections are created.
 PoolingOptions setMinSimultaneousRequestsPerConnectionThreshold(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

getMinSimultaneousRequestsPerConnectionThreshold

public int getMinSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
Returns the 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.

setMinSimultaneousRequestsPerConnectionThreshold

public PoolingOptions setMinSimultaneousRequestsPerConnectionThreshold(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.

getMaxSimultaneousRequestsPerConnectionThreshold

public int getMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
Returns the 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 getMaxConnectionsPerHost(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.

setMaxSimultaneousRequestsPerConnectionThreshold

public PoolingOptions setMaxSimultaneousRequestsPerConnectionThreshold(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)
Returns 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.

getMaxConnectionsPerHost

public int getMaxConnectionsPerHost(HostDistance distance)
Returns 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.