Package ome.services.db
Class SelfCorrectingDataSource
- java.lang.Object
-
- org.springframework.jdbc.datasource.DelegatingDataSource
-
- ome.services.db.SelfCorrectingDataSource
-
- All Implemented Interfaces:
java.sql.Wrapper,java.util.EventListener,javax.sql.CommonDataSource,javax.sql.DataSource,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationListener<ome.util.messages.UserSignalMessage>
public class SelfCorrectingDataSource extends org.springframework.jdbc.datasource.DelegatingDataSource implements org.springframework.context.ApplicationListener<ome.util.messages.UserSignalMessage>DataSourcedelegate which wraps the
-
-
Constructor Summary
Constructors Constructor Description SelfCorrectingDataSource(javax.sql.DataSource delegate, long timeoutInMilliseconds)SelfCorrectingDataSource(javax.sql.DataSource delegate, long timeoutInMilliseconds, int maxRetries, long maxBackOff)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected longcalculateBackOff(int numberOfErrors)protected java.sql.Connectioncall(java.lang.String username, java.lang.String password, boolean useArgs)protected java.sql.ConnectioncallWithRetries(java.lang.String username, java.lang.String password, boolean useArgs)java.sql.ConnectiongetConnection()java.sql.ConnectiongetConnection(java.lang.String username, java.lang.String password)protected longmarkAndSweep()First removes all entries inerrorTimesthat are older than some given time and then uses the remaining number of errors to determine the backoff : (#^1/2)*1000 milliseconds.voidonApplicationEvent(ome.util.messages.UserSignalMessage usm)Handles the USR1 posix signal by calling close on the underlyingdata sourcevia reflection.-
Methods inherited from class org.springframework.jdbc.datasource.DelegatingDataSource
afterPropertiesSet, getLoginTimeout, getLogWriter, getParentLogger, getTargetDataSource, isWrapperFor, setLoginTimeout, setLogWriter, setTargetDataSource, unwrap
-
-
-
-
Method Detail
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException- Specified by:
getConnectionin interfacejavax.sql.DataSource- Overrides:
getConnectionin classorg.springframework.jdbc.datasource.DelegatingDataSource- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException- Specified by:
getConnectionin interfacejavax.sql.DataSource- Overrides:
getConnectionin classorg.springframework.jdbc.datasource.DelegatingDataSource- Throws:
java.sql.SQLException
-
onApplicationEvent
public void onApplicationEvent(ome.util.messages.UserSignalMessage usm)
Handles the USR1 posix signal by calling close on the underlyingdata sourcevia reflection. The assumption is that the next call to any methods will re-initialize the data source. This is the case with bitronix.tm.resource.jdbc.PoolingDataSource- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<ome.util.messages.UserSignalMessage>- See Also:
- ticket:4210
-
callWithRetries
protected java.sql.Connection callWithRetries(java.lang.String username, java.lang.String password, boolean useArgs) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
call
protected java.sql.Connection call(java.lang.String username, java.lang.String password, boolean useArgs) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
markAndSweep
protected long markAndSweep()
First removes all entries inerrorTimesthat are older than some given time and then uses the remaining number of errors to determine the backoff : (#^1/2)*1000 milliseconds.
-
calculateBackOff
protected long calculateBackOff(int numberOfErrors)
-
-