net.dataforte.cassandra.pool
Class DataSource

java.lang.Object
  extended by net.dataforte.cassandra.pool.DataSourceProxy
      extended by net.dataforte.cassandra.pool.DataSource
All Implemented Interfaces:
MBeanRegistration, PoolConfiguration, CassandraThriftDataSource

public class DataSource
extends DataSourceProxy
implements PoolConfiguration, CassandraThriftDataSource, MBeanRegistration

A DataSource that can be instantiated through IoC and implements the CassandraThriftDataSource interface since the DataSourceProxy is used as a generic proxy. The DataSource simply wraps a ConnectionPool in order to provide a standard interface to the user.

Author:
Tristan Tarrant

Field Summary
protected  ObjectName oname
           
 
Fields inherited from class net.dataforte.cassandra.pool.DataSourceProxy
pool, poolProperties
 
Constructor Summary
DataSource()
          Constructor for reflection only.
DataSource(PoolConfiguration poolProperties)
          Constructs a DataSource object wrapping a connection
 
Method Summary
 ObjectName createObjectName(ObjectName original)
          Creates the ObjectName for the ConnectionPoolMBean object to be registered
 Object get(String name)
          Provides a generic getter for any of the declared properties of the PoolConfiguration
 int getAbandonWhenPercentageFull()
          Connections that have been abandoned (timed out) wont get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull.
 String[] getConfiguredHosts()
          Returns an array of configured hosts (may be different from the actual list if dynamic discovery is enabled)
 Object getDataSource()
          Returns a datasource, if one exists that is being used to create connections.
 String getDataSourceJNDI()
          Returns the JNDI string configured for data source usage.
 HostFailoverPolicy getFailoverPolicy()
          Returns the failover policy.
 String getHost()
          Returns the Cassandra hosts
 long getHostRetryInterval()
          Returns the interval in milliseconds before retrying a host to which a connection has failed in the past.
 int getInitialSize()
          Returns the number of connections that will be established when the connection pool is started.
 String getKeySpace()
          Returns the keyspace
 int getMaxActive()
          The maximum number of active connections that can be allocated from this pool at the same time.
 long getMaxAge()
          Time in milliseconds to keep this connection alive even when used.
 int getMaxIdle()
          The maximum number of connections that should be kept in the idle pool if PoolConfiguration.isPoolSweeperEnabled() returns false.
 int getMaxWait()
          The maximum number of milliseconds that the pool will wait (when there are no available connections and the PoolConfiguration.getMaxActive() has been reached) for a connection to be returned before throwing an exception.
 int getMinEvictableIdleTimeMillis()
          The minimum amount of time an object must sit idle in the pool before it is eligible for eviction.
 int getMinIdle()
          The minimum number of established connections that should be kept in the pool at all times.
 String getName()
          Returns the name of the connection pool.
 int getNumTestsPerEvictionRun()
          Property not used
 String getPassword()
          Returns the password used when establishing connections to the database.
 String getPoolName()
           
 int getPort()
          Returns the Cassandra port (defaults to 9160)
 int getRemoveAbandonedTimeout()
          The time in seconds before a connection can be considered abandoned.
 int getSocketTimeout()
          Returns the socket timeout in milliseconds
 int getSuspectTimeout()
          Returns the time in seconds to pass before a connection is marked an abanoned suspect.
 int getTimeBetweenEvictionRunsMillis()
          The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing.
 String getUrl()
          Returns the Cassandra connection URL
 boolean getUseLock()
          Return true if a lock should be used when operations are performed on the connection object.
 String getUsername()
          Returns the username used to establish the connection with
 long getValidationInterval()
          avoid excess validation, only run validation at most at this frequency - time in milliseconds.
 boolean isAutomaticHostDiscovery()
          Returns whether automatic host discovery is being used
 boolean isFairQueue()
          Returns true if a fair queue is being used by the connection pool
 boolean isFramed()
          Returns whether framed connection mode is being used
 boolean isJmxEnabled()
          If set to true, the connection pool creates a ConnectionPoolMBean object that can be registered with JMX to receive notifications and state about the pool.
 boolean isLogAbandoned()
          boolean flag to set if stack traces should be logged for application code which abandoned a Connection.
 boolean isPoolSweeperEnabled()
          Returns true if the pool sweeper is enabled for the connection pool.
 boolean isRemoveAbandoned()
          boolean flag to remove abandoned connections if they exceed the removeAbandonedTimout.
 boolean isTestOnBorrow()
          The indication of whether objects will be validated before being borrowed from the pool.
 boolean isTestOnConnect()
          Returns true if we should run the validation query when connecting to the database for the first time on a connection.
 boolean isTestOnReturn()
          The indication of whether objects will be validated after being returned to the pool.
 boolean isTestWhileIdle()
          Set to true if query validation should take place while the connection is idle.
 boolean isUseEquals()
          Set to true if you wish the ProxyConnection class to use String.equals instead of == when comparing method names.
 void postDeregister()
          Unregisters the underlying connection pool mbean.
 void postRegister(Boolean registrationDone)
          no-op
 void preDeregister()
          no-op
 ObjectName preRegister(MBeanServer server, ObjectName name)
          If the connection pool MBean exists, it will be registered during this operation.
protected  void registerJmx()
          Registers the ConnectionPoolMBean under a unique name based on the ObjectName for the DataSource
 void set(String name, Object value)
          Properties
 void setAbandonWhenPercentageFull(int percentage)
          Connections that have been abandoned (timed out) wont get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull.
 void setAutomaticHostDiscovery(boolean autoDiscovery)
          Sets whether Cassandra hosts should be queried to automatically obtain a list of other hosts
 void setDataSource(Object ds)
          Injects a datasource that will be used to retrieve/create connections.
 void setDataSourceJNDI(String jndiDS)
          Configure the connection pool to use a DataSource according to PoolConfiguration.setDataSource(Object) But instead of injecting the object, specify the JNDI location.
 void setFailoverPolicy(HostFailoverPolicy failoverPolicy)
          Sets the host failover policy, i.e. what to do when connecting to a host fails
 void setFairQueue(boolean fairQueue)
          Set to true if you wish that calls to getConnection should be treated fairly in a true FIFO fashion.
 void setFramed(boolean framed)
          Sets whether to use framed connection mode (default false)
 void setHost(String host)
          Sets the Cassandra host.
 void setHostRetryInterval(long hostRetryInterval)
          Sets the interval in milliseconds before retrying a host to which a connection has failed in the past.
 void setInitialSize(int initialSize)
          Set the number of connections that will be established when the connection pool is started.
 void setJmxEnabled(boolean jmxEnabled)
          If set to true, the connection pool creates a ConnectionPoolMBean object that can be registered with JMX to receive notifications and state about the pool.
 void setKeySpace(String keySpace)
          Sets the keyspace
 void setLogAbandoned(boolean logAbandoned)
          boolean flag to set if stack traces should be logged for application code which abandoned a Connection.
 void setMaxActive(int maxActive)
          The maximum number of active connections that can be allocated from this pool at the same time.
 void setMaxAge(long maxAge)
          Time in milliseconds to keep this connection alive even when used.
 void setMaxIdle(int maxIdle)
          The maximum number of connections that should be kept in the idle pool if PoolConfiguration.isPoolSweeperEnabled() returns false.
 void setMaxWait(int maxWait)
          The maximum number of milliseconds that the pool will wait (when there are no available connections and the PoolConfiguration.getMaxActive() has been reached) for a connection to be returned before throwing an exception.
 void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)
          The minimum amount of time an object must sit idle in the pool before it is eligible for eviction.
 void setMinIdle(int minIdle)
          The minimum number of established connections that should be kept in the pool at all times.
 void setName(String name)
          Sets the name of the connection pool
 void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
          Property not used
 void setPassword(String password)
          Sets the password to establish the connection with.
 void setPort(int port)
          Sets the Cassandra port
 void setRemoveAbandoned(boolean removeAbandoned)
          boolean flag to remove abandoned connections if they exceed the removeAbandonedTimout.
 void setRemoveAbandonedTimeout(int removeAbandonedTimeout)
          The time in seconds before a connection can be considered abandoned.
 void setSocketTimeout(int socketTimeout)
          Sets the socket timeout in milliseconds
 void setSuspectTimeout(int seconds)
          Similar to PoolConfiguration.setRemoveAbandonedTimeout(int) but instead of treating the connection as abandoned, and potentially closing the connection, this simply logs the warning if PoolConfiguration.isLogAbandoned() returns true.
 void setTestOnBorrow(boolean testOnBorrow)
          The indication of whether objects will be validated before being borrowed from the pool.
 void setTestOnConnect(boolean testOnConnect)
          Set to true if we should run the validation query when connecting to the database for the first time on a connection.
 void setTestOnReturn(boolean testOnReturn)
          The indication of whether objects will be validated after being returned to the pool.
 void setTestWhileIdle(boolean testWhileIdle)
          Set to true if query validation should take place while the connection is idle.
 void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis)
          The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing.
 void setUrl(String url)
          Sets the Cassandra connection URL.
 void setUseEquals(boolean useEquals)
          Set to true if you wish the ProxyConnection class to use String.equals instead of == when comparing method names.
 void setUseLock(boolean useLock)
          Set to true if a lock should be used when operations are performed on the connection object.
 void setUsername(String username)
          Sets the username used to establish the connection with
 void setValidationInterval(long validationInterval)
          avoid excess validation, only run validation at most at this frequency - time in milliseconds.
protected  void unregisterJmx()
           
 
Methods inherited from class net.dataforte.cassandra.pool.DataSourceProxy
close, close, createPool, getConnection, getPool, getPoolProperties, getPoolSize, releaseConnection, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.dataforte.cassandra.thrift.CassandraThriftDataSource
getConnection, releaseConnection
 

Field Detail

oname

protected volatile ObjectName oname
Constructor Detail

DataSource

public DataSource()
Constructor for reflection only. A default set of pool properties will be created.


DataSource

public DataSource(PoolConfiguration poolProperties)
Constructs a DataSource object wrapping a connection

Parameters:
poolProperties -
Method Detail

postDeregister

public void postDeregister()
Unregisters the underlying connection pool mbean.

Specified by:
postDeregister in interface MBeanRegistration

postRegister

public void postRegister(Boolean registrationDone)
no-op

Specified by:
postRegister in interface MBeanRegistration

preDeregister

public void preDeregister()
                   throws Exception
no-op

Specified by:
preDeregister in interface MBeanRegistration
Throws:
Exception

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws Exception
If the connection pool MBean exists, it will be registered during this operation.

Specified by:
preRegister in interface MBeanRegistration
Throws:
Exception

createObjectName

public ObjectName createObjectName(ObjectName original)
                            throws MalformedObjectNameException
Creates the ObjectName for the ConnectionPoolMBean object to be registered

Parameters:
original - the ObjectName for the DataSource
Returns:
the ObjectName for the ConnectionPoolMBean
Throws:
MalformedObjectNameException

registerJmx

protected void registerJmx()
Registers the ConnectionPoolMBean under a unique name based on the ObjectName for the DataSource


unregisterJmx

protected void unregisterJmx()

set

public void set(String name,
                Object value)
Properties

Specified by:
set in interface PoolConfiguration
Parameters:
name - the name of the property
value - the new value of the property

get

public Object get(String name)
Description copied from interface: PoolConfiguration
Provides a generic getter for any of the declared properties of the PoolConfiguration

Specified by:
get in interface PoolConfiguration
Parameters:
name - the name of the property
Returns:
the value of the property

setHost

public void setHost(String host)
Description copied from interface: PoolConfiguration
Sets the Cassandra host. May be a comma-separated list of addresses

Specified by:
setHost in interface PoolConfiguration

getHost

public String getHost()
Description copied from interface: PoolConfiguration
Returns the Cassandra hosts

Specified by:
getHost in interface PoolConfiguration
Returns:
a single string representing the Cassandra host addresses separated by commas

setPort

public void setPort(int port)
Description copied from interface: PoolConfiguration
Sets the Cassandra port

Specified by:
setPort in interface PoolConfiguration

getPort

public int getPort()
Description copied from interface: PoolConfiguration
Returns the Cassandra port (defaults to 9160)

Specified by:
getPort in interface PoolConfiguration
Returns:
the Cassandra port

setUrl

public void setUrl(String url)
Description copied from interface: PoolConfiguration
Sets the Cassandra connection URL. The url is in the form cassandra:thrift://[host]:[port]

Specified by:
setUrl in interface PoolConfiguration

getUrl

public String getUrl()
Description copied from interface: PoolConfiguration
Returns the Cassandra connection URL

Specified by:
getUrl in interface PoolConfiguration
Returns:

setFramed

public void setFramed(boolean framed)
Description copied from interface: PoolConfiguration
Sets whether to use framed connection mode (default false)

Specified by:
setFramed in interface PoolConfiguration

isFramed

public boolean isFramed()
Description copied from interface: PoolConfiguration
Returns whether framed connection mode is being used

Specified by:
isFramed in interface PoolConfiguration
Returns:
whether framed connection mode is being used

setAutomaticHostDiscovery

public void setAutomaticHostDiscovery(boolean autoDiscovery)
Description copied from interface: PoolConfiguration
Sets whether Cassandra hosts should be queried to automatically obtain a list of other hosts

Specified by:
setAutomaticHostDiscovery in interface PoolConfiguration

isAutomaticHostDiscovery

public boolean isAutomaticHostDiscovery()
Description copied from interface: PoolConfiguration
Returns whether automatic host discovery is being used

Specified by:
isAutomaticHostDiscovery in interface PoolConfiguration
Returns:
whether automatic host discovery is being used

setFailoverPolicy

public void setFailoverPolicy(HostFailoverPolicy failoverPolicy)
Description copied from interface: PoolConfiguration
Sets the host failover policy, i.e. what to do when connecting to a host fails

Specified by:
setFailoverPolicy in interface PoolConfiguration

getFailoverPolicy

public HostFailoverPolicy getFailoverPolicy()
Description copied from interface: PoolConfiguration
Returns the failover policy.

Specified by:
getFailoverPolicy in interface PoolConfiguration
Returns:
the failover policy

setAbandonWhenPercentageFull

public void setAbandonWhenPercentageFull(int percentage)
Description copied from interface: PoolConfiguration
Connections that have been abandoned (timed out) wont get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull. The value should be between 0-100. The default value is 0, which implies that connections are eligible for closure as soon as removeAbandonedTimeout has been reached.

Specified by:
setAbandonWhenPercentageFull in interface PoolConfiguration
Parameters:
percentage - a value between 0 and 100 to indicate when connections that have been abandoned/timed out are considered abandoned

getAbandonWhenPercentageFull

public int getAbandonWhenPercentageFull()
Description copied from interface: PoolConfiguration
Connections that have been abandoned (timed out) wont get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull. The value should be between 0-100. The default value is 0, which implies that connections are eligible for closure as soon as removeAbandonedTimeout has been reached.

Specified by:
getAbandonWhenPercentageFull in interface PoolConfiguration
Returns:
percentage - a value between 0 and 100 to indicate when connections that have been abandoned/timed out are considered abandoned

isFairQueue

public boolean isFairQueue()
Description copied from interface: PoolConfiguration
Returns true if a fair queue is being used by the connection pool

Specified by:
isFairQueue in interface PoolConfiguration
Returns:
true if a fair waiting queue is being used

setFairQueue

public void setFairQueue(boolean fairQueue)
Description copied from interface: PoolConfiguration
Set to true if you wish that calls to getConnection should be treated fairly in a true FIFO fashion. This uses the FairBlockingQueue implementation for the list of the idle connections. The default value is true. This flag is required when you want to use asynchronous connection retrieval.

Specified by:
setFairQueue in interface PoolConfiguration

getInitialSize

public int getInitialSize()
Description copied from interface: PoolConfiguration
Returns the number of connections that will be established when the connection pool is started. Default value is 10

Specified by:
getInitialSize in interface PoolConfiguration
Returns:
number of connections to be started when pool is started

setInitialSize

public void setInitialSize(int initialSize)
Description copied from interface: PoolConfiguration
Set the number of connections that will be established when the connection pool is started. Default value is 10. If this value exceeds PoolConfiguration.setMaxActive(int) it will automatically be lowered.

Specified by:
setInitialSize in interface PoolConfiguration
Parameters:
initialSize - the number of connections to be established.

isLogAbandoned

public boolean isLogAbandoned()
Description copied from interface: PoolConfiguration
boolean flag to set if stack traces should be logged for application code which abandoned a Connection. Logging of abandoned Connections adds overhead for every Connection borrow because a stack trace has to be generated. The default value is false.

Specified by:
isLogAbandoned in interface PoolConfiguration
Returns:
true if the connection pool logs stack traces when connections are borrowed from the pool.

setLogAbandoned

public void setLogAbandoned(boolean logAbandoned)
Description copied from interface: PoolConfiguration
boolean flag to set if stack traces should be logged for application code which abandoned a Connection. Logging of abandoned Connections adds overhead for every Connection borrow because a stack trace has to be generated. The default value is false.

Specified by:
setLogAbandoned in interface PoolConfiguration
Parameters:
logAbandoned - set to true if stack traces should be recorded when DataSourceProxy.getConnection() is called.

getMaxActive

public int getMaxActive()
Description copied from interface: PoolConfiguration
The maximum number of active connections that can be allocated from this pool at the same time. The default value is 100

Specified by:
getMaxActive in interface PoolConfiguration
Returns:
the maximum number of connections used by this pool

setMaxActive

public void setMaxActive(int maxActive)
Description copied from interface: PoolConfiguration
The maximum number of active connections that can be allocated from this pool at the same time. The default value is 100

Specified by:
setMaxActive in interface PoolConfiguration
Parameters:
maxActive - hard limit for number of managed connections by this pool

getMaxIdle

public int getMaxIdle()
Description copied from interface: PoolConfiguration
The maximum number of connections that should be kept in the idle pool if PoolConfiguration.isPoolSweeperEnabled() returns false. If the If PoolConfiguration.isPoolSweeperEnabled() returns true, then the idle pool can grow up to PoolConfiguration.getMaxActive() and will be shrunk according to PoolConfiguration.getMinEvictableIdleTimeMillis() setting. Default value is maxActive:100

Specified by:
getMaxIdle in interface PoolConfiguration
Returns:
the maximum number of idle connections.

setMaxIdle

public void setMaxIdle(int maxIdle)
Description copied from interface: PoolConfiguration
The maximum number of connections that should be kept in the idle pool if PoolConfiguration.isPoolSweeperEnabled() returns false. If the If PoolConfiguration.isPoolSweeperEnabled() returns true, then the idle pool can grow up to PoolConfiguration.getMaxActive() and will be shrunk according to PoolConfiguration.getMinEvictableIdleTimeMillis() setting. Default value is maxActive:100

Specified by:
setMaxIdle in interface PoolConfiguration
Parameters:
maxIdle - the maximum size of the idle pool

getMaxWait

public int getMaxWait()
Description copied from interface: PoolConfiguration
The maximum number of milliseconds that the pool will wait (when there are no available connections and the PoolConfiguration.getMaxActive() has been reached) for a connection to be returned before throwing an exception. Default value is 30000 (30 seconds)

Specified by:
getMaxWait in interface PoolConfiguration
Returns:
the number of milliseconds to wait for a connection to become available if the pool is maxed out.

setMaxWait

public void setMaxWait(int maxWait)
Description copied from interface: PoolConfiguration
The maximum number of milliseconds that the pool will wait (when there are no available connections and the PoolConfiguration.getMaxActive() has been reached) for a connection to be returned before throwing an exception. Default value is 30000 (30 seconds)

Specified by:
setMaxWait in interface PoolConfiguration
Parameters:
maxWait - the maximum number of milliseconds to wait.

getMinEvictableIdleTimeMillis

public int getMinEvictableIdleTimeMillis()
Description copied from interface: PoolConfiguration
The minimum amount of time an object must sit idle in the pool before it is eligible for eviction. The default value is 60000 (60 seconds).

Specified by:
getMinEvictableIdleTimeMillis in interface PoolConfiguration
Returns:
the minimum amount of idle time in milliseconds before a connection is considered idle and eligible for eviction.

setMinEvictableIdleTimeMillis

public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)
Description copied from interface: PoolConfiguration
The minimum amount of time an object must sit idle in the pool before it is eligible for eviction. The default value is 60000 (60 seconds).

Specified by:
setMinEvictableIdleTimeMillis in interface PoolConfiguration
Parameters:
minEvictableIdleTimeMillis - the number of milliseconds a connection must be idle to be eligible for eviction.

getMinIdle

public int getMinIdle()
Description copied from interface: PoolConfiguration
The minimum number of established connections that should be kept in the pool at all times. The connection pool can shrink below this number if validation queries fail and connections get closed. Default value is derived from PoolConfiguration.getInitialSize() (also see PoolConfiguration.setTestWhileIdle(boolean) The idle pool will not shrink below this value during an eviction run, hence the number of actual connections can be between PoolConfiguration.getMinIdle() and somewhere between PoolConfiguration.getMaxIdle() and PoolConfiguration.getMaxActive()

Specified by:
getMinIdle in interface PoolConfiguration
Returns:
the minimum number of idle or established connections

setMinIdle

public void setMinIdle(int minIdle)
Description copied from interface: PoolConfiguration
The minimum number of established connections that should be kept in the pool at all times. The connection pool can shrink below this number if validation queries fail and connections get closed. Default value is derived from PoolConfiguration.getInitialSize() (also see PoolConfiguration.setTestWhileIdle(boolean) The idle pool will not shrink below this value during an eviction run, hence the number of actual connections can be between PoolConfiguration.getMinIdle() and somewhere between PoolConfiguration.getMaxIdle() and PoolConfiguration.getMaxActive()

Specified by:
setMinIdle in interface PoolConfiguration
Parameters:
minIdle - the minimum number of idle or established connections

getName

public String getName()
Description copied from interface: PoolConfiguration
Returns the name of the connection pool. By default a JVM unique random name is assigned.

Specified by:
getName in interface PoolConfiguration
Returns:
the name of the pool, should be unique in a JVM

setName

public void setName(String name)
Description copied from interface: PoolConfiguration
Sets the name of the connection pool

Specified by:
setName in interface PoolConfiguration
Parameters:
name - the name of the pool, should be unique in a runtime JVM

getNumTestsPerEvictionRun

public int getNumTestsPerEvictionRun()
Description copied from interface: PoolConfiguration
Property not used

Specified by:
getNumTestsPerEvictionRun in interface PoolConfiguration
Returns:
unknown value

setNumTestsPerEvictionRun

public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Description copied from interface: PoolConfiguration
Property not used

Specified by:
setNumTestsPerEvictionRun in interface PoolConfiguration
Parameters:
numTestsPerEvictionRun - parameter ignored.

getPassword

public String getPassword()
Description copied from interface: PoolConfiguration
Returns the password used when establishing connections to the database.

Specified by:
getPassword in interface PoolConfiguration
Returns:
the password in string format

setPassword

public void setPassword(String password)
Description copied from interface: PoolConfiguration
Sets the password to establish the connection with.

Specified by:
setPassword in interface PoolConfiguration

getPoolName

public String getPoolName()
Specified by:
getPoolName in interface PoolConfiguration
Returns:
name
See Also:
PoolConfiguration.getName()

getKeySpace

public String getKeySpace()
Description copied from interface: PoolConfiguration
Returns the keyspace

Specified by:
getKeySpace in interface PoolConfiguration

setKeySpace

public void setKeySpace(String keySpace)
Description copied from interface: PoolConfiguration
Sets the keyspace

Specified by:
setKeySpace in interface PoolConfiguration

getUsername

public String getUsername()
Description copied from interface: PoolConfiguration
Returns the username used to establish the connection with

Specified by:
getUsername in interface PoolConfiguration
Returns:
the username used to establish the connection with

setUsername

public void setUsername(String username)
Description copied from interface: PoolConfiguration
Sets the username used to establish the connection with

Specified by:
setUsername in interface PoolConfiguration

isRemoveAbandoned

public boolean isRemoveAbandoned()
Description copied from interface: PoolConfiguration
boolean flag to remove abandoned connections if they exceed the removeAbandonedTimout. If set to true a connection is considered abandoned and eligible for removal if it has been in use longer than the PoolConfiguration.getRemoveAbandonedTimeout() and the condition for PoolConfiguration.getAbandonWhenPercentageFull() is met. Setting this to true can recover db connections from applications that fail to close a connection. See also PoolConfiguration.isLogAbandoned() The default value is false.

Specified by:
isRemoveAbandoned in interface PoolConfiguration
Returns:
true if abandoned connections can be closed and expelled out of the pool

setRemoveAbandoned

public void setRemoveAbandoned(boolean removeAbandoned)
Description copied from interface: PoolConfiguration
boolean flag to remove abandoned connections if they exceed the removeAbandonedTimout. If set to true a connection is considered abandoned and eligible for removal if it has been in use longer than the PoolConfiguration.getRemoveAbandonedTimeout() and the condition for PoolConfiguration.getAbandonWhenPercentageFull() is met. Setting this to true can recover db connections from applications that fail to close a connection. See also PoolConfiguration.isLogAbandoned() The default value is false.

Specified by:
setRemoveAbandoned in interface PoolConfiguration
Parameters:
removeAbandoned - set to true if abandoned connections can be closed and expelled out of the pool

setRemoveAbandonedTimeout

public void setRemoveAbandonedTimeout(int removeAbandonedTimeout)
Description copied from interface: PoolConfiguration
The time in seconds before a connection can be considered abandoned. The timer can be reset upon queries using an interceptor.

Specified by:
setRemoveAbandonedTimeout in interface PoolConfiguration
Parameters:
removeAbandonedTimeout - the time in seconds before a used connection can be considered abandoned *

getRemoveAbandonedTimeout

public int getRemoveAbandonedTimeout()
Description copied from interface: PoolConfiguration
The time in seconds before a connection can be considered abandoned. The timer can be reset upon queries using an interceptor.

Specified by:
getRemoveAbandonedTimeout in interface PoolConfiguration
Returns:
the time in seconds before a used connection can be considered abandoned

isTestOnBorrow

public boolean isTestOnBorrow()
Description copied from interface: PoolConfiguration
The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. Default value is false In order to have a more efficient validation, see PoolConfiguration.setValidationInterval(long)

Specified by:
isTestOnBorrow in interface PoolConfiguration
Returns:
true if the connection is to be validated upon borrowing a connection from the pool
See Also:
PoolConfiguration.getValidationInterval()

setTestOnBorrow

public void setTestOnBorrow(boolean testOnBorrow)
Description copied from interface: PoolConfiguration
The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. Default value is false In order to have a more efficient validation, see PoolConfiguration.setValidationInterval(long)

Specified by:
setTestOnBorrow in interface PoolConfiguration
Parameters:
testOnBorrow - set to true if validation should take place before a connection is handed out to the application
See Also:
PoolConfiguration.getValidationInterval()

isTestOnReturn

public boolean isTestOnReturn()
Description copied from interface: PoolConfiguration
The indication of whether objects will be validated after being returned to the pool. If the object fails to validate, it will be dropped from the pool. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. Default value is false In order to have a more efficient validation, see PoolConfiguration.setValidationInterval(long)

Specified by:
isTestOnReturn in interface PoolConfiguration
Returns:
true if validation should take place after a connection is returned to the pool
See Also:
PoolConfiguration.getValidationInterval()

setTestOnReturn

public void setTestOnReturn(boolean testOnReturn)
Description copied from interface: PoolConfiguration
The indication of whether objects will be validated after being returned to the pool. If the object fails to validate, it will be dropped from the pool. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. Default value is false In order to have a more efficient validation, see PoolConfiguration.setValidationInterval(long)

Specified by:
setTestOnReturn in interface PoolConfiguration
Parameters:
testOnReturn - true if validation should take place after a connection is returned to the pool
See Also:
PoolConfiguration.getValidationInterval()

isTestWhileIdle

public boolean isTestWhileIdle()
Description copied from interface: PoolConfiguration
Set to true if query validation should take place while the connection is idle.

Specified by:
isTestWhileIdle in interface PoolConfiguration
Returns:
true if validation should take place during idle checks
See Also:
PoolConfiguration.setTimeBetweenEvictionRunsMillis(int)

setTestWhileIdle

public void setTestWhileIdle(boolean testWhileIdle)
Description copied from interface: PoolConfiguration
Set to true if query validation should take place while the connection is idle.

Specified by:
setTestWhileIdle in interface PoolConfiguration
Parameters:
testWhileIdle - true if validation should take place during idle checks
See Also:
PoolConfiguration.setTimeBetweenEvictionRunsMillis(int)

getTimeBetweenEvictionRunsMillis

public int getTimeBetweenEvictionRunsMillis()
Description copied from interface: PoolConfiguration
The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing. This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often we validate idle connection and resize the idle pool. The default value is 5000 (5 seconds)

Specified by:
getTimeBetweenEvictionRunsMillis in interface PoolConfiguration
Returns:
the sleep time in between validations in milliseconds

setTimeBetweenEvictionRunsMillis

public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis)
Description copied from interface: PoolConfiguration
The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing. This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often we validate idle connection and resize the idle pool. The default value is 5000 (5 seconds)

Specified by:
setTimeBetweenEvictionRunsMillis in interface PoolConfiguration
Parameters:
timeBetweenEvictionRunsMillis - the sleep time in between validations in milliseconds

getValidationInterval

public long getValidationInterval()
Description copied from interface: PoolConfiguration
avoid excess validation, only run validation at most at this frequency - time in milliseconds. If a connection is due for validation, but has been validated previously within this interval, it will not be validated again. The default value is 30000 (30 seconds).

Specified by:
getValidationInterval in interface PoolConfiguration
Returns:
the validation interval in milliseconds

setValidationInterval

public void setValidationInterval(long validationInterval)
Description copied from interface: PoolConfiguration
avoid excess validation, only run validation at most at this frequency - time in milliseconds. If a connection is due for validation, but has been validated previously within this interval, it will not be validated again. The default value is 30000 (30 seconds).

Specified by:
setValidationInterval in interface PoolConfiguration
Parameters:
validationInterval - the validation interval in milliseconds

isTestOnConnect

public boolean isTestOnConnect()
Description copied from interface: PoolConfiguration
Returns true if we should run the validation query when connecting to the database for the first time on a connection. Normally this is always set to false.

Specified by:
isTestOnConnect in interface PoolConfiguration
Returns:
true if we should run the validation query upon connect

setTestOnConnect

public void setTestOnConnect(boolean testOnConnect)
Description copied from interface: PoolConfiguration
Set to true if we should run the validation query when connecting to the database for the first time on a connection. Normally this is always set to false.

Specified by:
setTestOnConnect in interface PoolConfiguration
Parameters:
testOnConnect - set to true if we should run the validation query upon connect

isJmxEnabled

public boolean isJmxEnabled()
Description copied from interface: PoolConfiguration
If set to true, the connection pool creates a ConnectionPoolMBean object that can be registered with JMX to receive notifications and state about the pool. The ConnectionPool object doesn't register itself, as there is no way to keep a static non changing ObjectName across JVM restarts.

Specified by:
isJmxEnabled in interface PoolConfiguration
Returns:
true if the mbean object will be created upon startup.

setJmxEnabled

public void setJmxEnabled(boolean jmxEnabled)
Description copied from interface: PoolConfiguration
If set to true, the connection pool creates a ConnectionPoolMBean object that can be registered with JMX to receive notifications and state about the pool. The ConnectionPool object doesn't register itself, as there is no way to keep a static non changing ObjectName across JVM restarts.

Specified by:
setJmxEnabled in interface PoolConfiguration
Parameters:
jmxEnabled - set to to if the mbean object should be created upon startup.

isPoolSweeperEnabled

public boolean isPoolSweeperEnabled()
Description copied from interface: PoolConfiguration
Returns true if the pool sweeper is enabled for the connection pool. The pool sweeper is enabled if any settings that require async intervention in the pool are turned on boolean result = getTimeBetweenEvictionRunsMillis()>0; result = result && (isRemoveAbandoned() && getRemoveAbandonedTimeout()>0); result = result || (isTestWhileIdle() && getValidationQuery()!=null); return result;

Specified by:
isPoolSweeperEnabled in interface PoolConfiguration
Returns:
true if a background thread is or will be enabled for this pool

isUseEquals

public boolean isUseEquals()
Description copied from interface: PoolConfiguration
Set to true if you wish the ProxyConnection class to use String.equals instead of == when comparing method names. This property does not apply to added interceptors as those are configured individually. The default value is false.

Specified by:
isUseEquals in interface PoolConfiguration
Returns:
true if pool uses String.equals(Object) instead of == when comparing method names on Connection methods

setUseEquals

public void setUseEquals(boolean useEquals)
Description copied from interface: PoolConfiguration
Set to true if you wish the ProxyConnection class to use String.equals instead of == when comparing method names. This property does not apply to added interceptors as those are configured individually. The default value is false.

Specified by:
setUseEquals in interface PoolConfiguration
Parameters:
useEquals - set to true if the pool should use String.equals(Object) instead of == when comparing method names on Connection methods

getMaxAge

public long getMaxAge()
Description copied from interface: PoolConfiguration
Time in milliseconds to keep this connection alive even when used. When a connection is returned to the pool, the pool will check to see if the ((now - time-when-connected) > maxAge) has been reached, and if so, it closes the connection rather than returning it to the pool. The default value is 0, which implies that connections will be left open and no age check will be done upon returning the connection to the pool. This is a useful setting for database sessions that leak memory as it ensures that the session will have a finite life span.

Specified by:
getMaxAge in interface PoolConfiguration
Returns:
the time in milliseconds a connection will be open for when used

setMaxAge

public void setMaxAge(long maxAge)
Description copied from interface: PoolConfiguration
Time in milliseconds to keep this connection alive even when used. When a connection is returned to the pool, the pool will check to see if the ((now - time-when-connected) > maxAge) has been reached, and if so, it closes the connection rather than returning it to the pool. The default value is 0, which implies that connections will be left open and no age check will be done upon returning the connection to the pool. This is a useful setting for database sessions that leak memory as it ensures that the session will have a finite life span.

Specified by:
setMaxAge in interface PoolConfiguration
Parameters:
maxAge - the time in milliseconds a connection will be open for when used

getUseLock

public boolean getUseLock()
Description copied from interface: PoolConfiguration
Return true if a lock should be used when operations are performed on the connection object. Should be set to false unless you plan to have a background thread of your own doing idle and abandon checking such as JMX clients. If the pool sweeper is enabled, then the lock will automatically be used regardless of this setting.

Specified by:
getUseLock in interface PoolConfiguration
Returns:
true if a lock is used.

setUseLock

public void setUseLock(boolean useLock)
Description copied from interface: PoolConfiguration
Set to true if a lock should be used when operations are performed on the connection object. Should be set to false unless you plan to have a background thread of your own doing idle and abandon checking such as JMX clients. If the pool sweeper is enabled, then the lock will automatically be used regardless of this setting.

Specified by:
setUseLock in interface PoolConfiguration
Parameters:
useLock - set to true if a lock should be used on connection operations

setSuspectTimeout

public void setSuspectTimeout(int seconds)
Description copied from interface: PoolConfiguration
Similar to PoolConfiguration.setRemoveAbandonedTimeout(int) but instead of treating the connection as abandoned, and potentially closing the connection, this simply logs the warning if PoolConfiguration.isLogAbandoned() returns true. If this value is equal or less than 0, no suspect checking will be performed. Suspect checking only takes place if the timeout value is larger than 0 and the connection was not abandoned or if abandon check is disabled. If a connection is suspect a WARN message gets logged and a JMX notification gets sent once.

Specified by:
setSuspectTimeout in interface PoolConfiguration
Parameters:
seconds - - the amount of time in seconds that has to pass before a connection is marked suspect.

getSuspectTimeout

public int getSuspectTimeout()
Description copied from interface: PoolConfiguration
Returns the time in seconds to pass before a connection is marked an abanoned suspect. Any value lesser than or equal to 0 means the check is disabled.

Specified by:
getSuspectTimeout in interface PoolConfiguration
Returns:
Returns the time in seconds to pass before a connection is marked an abanoned suspect.

getSocketTimeout

public int getSocketTimeout()
Description copied from interface: PoolConfiguration
Returns the socket timeout in milliseconds

Specified by:
getSocketTimeout in interface PoolConfiguration
Returns:
the socket timeout in milliseconds

setSocketTimeout

public void setSocketTimeout(int socketTimeout)
Description copied from interface: PoolConfiguration
Sets the socket timeout in milliseconds

Specified by:
setSocketTimeout in interface PoolConfiguration

getConfiguredHosts

public String[] getConfiguredHosts()
Description copied from interface: PoolConfiguration
Returns an array of configured hosts (may be different from the actual list if dynamic discovery is enabled)

Specified by:
getConfiguredHosts in interface PoolConfiguration
Returns:
an array of strings representing the addresses of the configured Cassandra hosts

getHostRetryInterval

public long getHostRetryInterval()
Description copied from interface: PoolConfiguration
Returns the interval in milliseconds before retrying a host to which a connection has failed in the past. Default is 300000 (5 minutes)

Specified by:
getHostRetryInterval in interface PoolConfiguration
Returns:
milliseconds before host retry

setHostRetryInterval

public void setHostRetryInterval(long hostRetryInterval)
Description copied from interface: PoolConfiguration
Sets the interval in milliseconds before retrying a host to which a connection has failed in the past.

Specified by:
setHostRetryInterval in interface PoolConfiguration
Parameters:
hostRetryInterval - number of millieseconds before retrying a host

setDataSourceJNDI

public void setDataSourceJNDI(String jndiDS)
Description copied from interface: PoolConfiguration
Configure the connection pool to use a DataSource according to PoolConfiguration.setDataSource(Object) But instead of injecting the object, specify the JNDI location. After a successful JNDI look, the PoolConfiguration.getDataSource() will not return null.

Specified by:
setDataSourceJNDI in interface PoolConfiguration
Parameters:
jndiDS - -the JNDI string @TODO specify the rules here.

getDataSourceJNDI

public String getDataSourceJNDI()
Description copied from interface: PoolConfiguration
Returns the JNDI string configured for data source usage.

Specified by:
getDataSourceJNDI in interface PoolConfiguration
Returns:
the JNDI string or null if not set

setDataSource

public void setDataSource(Object ds)
Description copied from interface: PoolConfiguration
Injects a datasource that will be used to retrieve/create connections.

Specified by:
setDataSource in interface PoolConfiguration
Parameters:
ds - the DataSource to be used for creating connections to be pooled.

getDataSource

public Object getDataSource()
Description copied from interface: PoolConfiguration
Returns a datasource, if one exists that is being used to create connections.

Specified by:
getDataSource in interface PoolConfiguration
Returns:
the datasource object


Copyright © 2011. All Rights Reserved.