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>
DataSource
delegate 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 long
calculateBackOff(int numberOfErrors)
protected java.sql.Connection
call(java.lang.String username, java.lang.String password, boolean useArgs)
protected java.sql.Connection
callWithRetries(java.lang.String username, java.lang.String password, boolean useArgs)
java.sql.Connection
getConnection()
java.sql.Connection
getConnection(java.lang.String username, java.lang.String password)
protected long
markAndSweep()
First removes all entries inerrorTimes
that are older than some given time and then uses the remaining number of errors to determine the backoff : (#^1/2)*1000 milliseconds.void
onApplicationEvent(ome.util.messages.UserSignalMessage usm)
Handles the USR1 posix signal by calling close on the underlyingdata source
via 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:
getConnection
in interfacejavax.sql.DataSource
- Overrides:
getConnection
in 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:
getConnection
in interfacejavax.sql.DataSource
- Overrides:
getConnection
in 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 source
via 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:
onApplicationEvent
in 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 inerrorTimes
that 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)
-
-