Class PooledDb

java.lang.Object
org.tentackle.dbms.PooledDb

public class PooledDb extends Object
Session managed by the session pool.
  • Constructor Details

    • PooledDb

      public PooledDb(DbPool pool, int slotNumber)
      Creates a pooled session.
      Parameters:
      pool - the session pool
      slotNumber - the slot number within the pool
  • Method Details

    • getPool

      public DbPool getPool()
      Gets the session pool.
      Returns:
      the pool
    • getSlotNumber

      public int getSlotNumber()
      Gets the slot number.
      Returns:
      the slot number
    • getSession

      public Db getSession()
      Returns the managed session.
      Returns:
      the managed session, null if currently lent
    • getReferencedDb

      public Db getReferencedDb()
      Gets the referenced session.
      This is the value of a WeakReference.
      Returns:
      the session, null if no more referenced.
    • getFirstUse

      public long getFirstUse()
      Get epochal time of first use.
      Returns:
      the epochal time
    • getUsedSince

      public long getUsedSince()
      Gets the time lent.
      Returns:
      the epochal time since in use, 0 if not lent
    • getUnusedSince

      public long getUnusedSince()
      Gets the last return time.
      Returns:
      the epochal time last returned, 0 if lent
    • getUsingThreadStr

      public String getUsingThreadStr()
      Gets the lending thread string.
      Avoids the references to the thread.
      Returns:
      the thread name, null if in pool
    • getMdcStr

      public String getMdcStr()
      Gets the mapped diagnostic context string.
      Returns:
      the MDC
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • close

      public void close()
      Closes a pooled db.
    • use

      public void use(Thread usingThread)
      Marks a pooled db used.
      Parameters:
      usingThread - the using thread
    • unUse

      public void unUse(Db db)
      Marks a pooled db unused.
    • isUnreferenced

      public boolean isUnreferenced()
      Checks for forgotten puts.
      Returns:
      true if db has been lent but never returned and is not referenced anymore
    • idleMinutes

      public long idleMinutes(long currentTimeMillis)
      Returns the number of minutes the session has been unused.
      Parameters:
      currentTimeMillis - the current time to refer to in epochal milliseconds
      Returns:
      the idle minutes, 0 if in use or never used at all
    • usedMinutes

      public long usedMinutes(long currentTimeMillis)
      Returns the number of minutes the session has been used at all.
      Parameters:
      currentTimeMillis - the current time to refer to in epochal milliseconds
      Returns:
      the usage minutes, 0 if never used at all
    • createSession

      protected Db createSession(int slotNumber)
      Creates a new session.
      Parameters:
      slotNumber - the slot number
      Returns:
      the open session