Class 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 in errorTimes 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 underlying data source via reflection.
      • Methods inherited from class org.springframework.jdbc.datasource.DelegatingDataSource

        afterPropertiesSet, getLoginTimeout, getLogWriter, getParentLogger, getTargetDataSource, isWrapperFor, setLoginTimeout, setLogWriter, setTargetDataSource, unwrap
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface javax.sql.CommonDataSource

        createShardingKeyBuilder
      • Methods inherited from interface javax.sql.DataSource

        createConnectionBuilder
    • Constructor Detail

      • SelfCorrectingDataSource

        public SelfCorrectingDataSource​(javax.sql.DataSource delegate,
                                        long timeoutInMilliseconds)
      • SelfCorrectingDataSource

        public SelfCorrectingDataSource​(javax.sql.DataSource delegate,
                                        long timeoutInMilliseconds,
                                        int maxRetries,
                                        long maxBackOff)
    • Method Detail

      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Specified by:
        getConnection in interface javax.sql.DataSource
        Overrides:
        getConnection in class org.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 interface javax.sql.DataSource
        Overrides:
        getConnection in class org.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 underlying data 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 interface org.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 in errorTimes 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)