Class Driver.ConnectTask

  • All Implemented Interfaces:
    java.lang.Runnable
    Enclosing class:
    Driver

    private static class Driver.ConnectTask
    extends java.lang.Object
    implements java.lang.Runnable
    Perform a connect in a separate thread; supports getting the results from the original thread while enforcing a login timeout.

    If the caller times out or is interrupted, we mark the attempt as abandoned and try to cancel the worker thread. Cancellation is best-effort: if the connection attempt does not stop immediately, the worker closes any connection it manages to establish after abandonment so that it does not leak.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean abandoned  
      private java.util.concurrent.atomic.AtomicReference<java.sql.Connection> establishedConnection  
      private java.util.concurrent.FutureTask<java.sql.Connection> futureTask  
    • Constructor Summary

      Constructors 
      Constructor Description
      ConnectTask​(java.lang.String url, java.util.Properties props)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void abandon()  
      private static void closeConnection​(java.sql.Connection conn)  
      (package private) java.sql.Connection getResult​(long timeout)
      Get the connection result from this (assumed running) task.
      void run()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • abandoned

        private volatile boolean abandoned
      • establishedConnection

        private final java.util.concurrent.atomic.AtomicReference<java.sql.Connection> establishedConnection
      • futureTask

        private final java.util.concurrent.FutureTask<java.sql.Connection> futureTask
    • Constructor Detail

      • ConnectTask

        ConnectTask​(java.lang.String url,
                    java.util.Properties props)
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • getResult

        java.sql.Connection getResult​(long timeout)
                               throws java.sql.SQLException
        Get the connection result from this (assumed running) task. If the timeout is reached without a result being available, a SQLException is thrown.
        Parameters:
        timeout - timeout in milliseconds
        Returns:
        the new connection, if successful
        Throws:
        java.sql.SQLException - if a connection error occurs or the timeout is reached
      • abandon

        private void abandon()
      • closeConnection

        private static void closeConnection​(java.sql.Connection conn)