Class ManagedConnectionMonitor

java.lang.Object
java.lang.Thread
org.tentackle.dbms.ManagedConnectionMonitor
All Implemented Interfaces:
Runnable

@Service(ManagedConnectionMonitor.class) public class ManagedConnectionMonitor extends Thread
Maintains a set of all open managed connections.
The connections are held by a weak reference and the set is cleaned up once a minute.
Optionally, idle connections with ManagedConnection.isConnectionVerificationNecessary() == true will be verified (via dummy selects) periodically and to prevent premature closing by the database backend. This is especially useful for databases running in the cloud, where the idle connection interval cannot be deactivated or made longer than the idle times maintained by the MpxConnectionManager.

Notice: the monitor thread never stops! It is started when first referenced by getInstance().

  • Constructor Details Link icon

    • ManagedConnectionMonitor Link icon

      public ManagedConnectionMonitor()
      Creates the monitor thread.
  • Method Details Link icon

    • getInstance Link icon

      public static ManagedConnectionMonitor getInstance()
      Gets the running monitor thread.
      Returns:
      the thread (singleton)
    • isRunning Link icon

      public static boolean isRunning()
      Returns whether the monitor is running.
      Useful to avoid getInstance() since this will start it, if not running yet.
      Returns:
      true if running, false if no ManagedConnections created ever (remote server, for example)
    • registerManagedConnection Link icon

      public void registerManagedConnection(ManagedConnection managedConnection)
      Registers a managed connection.
      Parameters:
      managedConnection - the managed connection
    • getManagedConnections Link icon

      public Collection<ManagedConnection> getManagedConnections()
      Gets a list of all open managed connections.
      Returns:
      the open connections
    • run Link icon

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • pause Link icon

      protected void pause()
      Pauses the thread between loop runs.
    • loop Link icon

      protected void loop()
      A single loop run.
    • inspect Link icon

      protected void inspect(ManagedConnection managedConnection, long currentTimeMillis)
      Inspects the idle connection.
      Parameters:
      managedConnection - the connection
      currentTimeMillis - the current epochal time