java.lang.Object
net.i2p.sam.SessionsDB

class SessionsDBextends Object
A database of SAM sessions, mapping nicknames to SessionRecords. Provides synchronized access for concurrent SAM handlers.
  • Field Details

  • Constructor Details

    • SessionsDB

      public SessionsDB()
      Create a new empty sessions database.
  • Method Details

    • put

      Store a session record. Both the nick and destination must be unique.
      Parameters:
      nick - the session nickname
      session - the SessionRecord to store under nick, whose destination must also be unique
      Throws:
      SessionsDB.ExistingIdException - if a session with this nick already exists
      SessionsDB.ExistingDestException - if a session with this destination already exists
    • putDupDestOK

      public void putDupDestOK(String nick, SessionRecord session) throws SessionsDB.ExistingIdException
      Store a session record, allowing duplicate destinations. Only the nick must be unique.
      Parameters:
      nick - the session nickname
      session - the SessionRecord to store under nick; its destination may repeat
      Throws:
      SessionsDB.ExistingIdException - if a session with this nick already exists
    • del

      public boolean del(String nick)
      Remove a session record by nickname.
      Parameters:
      nick - the session nickname
      Returns:
      true if removed, false if not found
    • get

      public SessionRecord get(String nick)
      Get a session record by nickname. Updates the last-accessed timestamp.
      Parameters:
      nick - the session nickname
      Returns:
      the session record, or null if not found
    • containsKey

      public boolean containsKey(String nick)
      Check if a session with the given nickname exists.
      Parameters:
      nick - the session nickname
      Returns:
      true if a session with this nick exists
    • size

      public int size()
      Get the number of registered sessions.
      Returns:
      the count of entries currently held in the session map
    • getAllEntries

      public Map<String, SessionRecord> getAllEntries()
      Return a snapshot of all entries (nick -> SessionRecord).
      Returns:
      a new map holding a copy of every session, keyed by nick
    • removeStale

      public int removeStale(long maxAgeMs)
      Remove sessions that have not been accessed for longer than maxAgeMs. This handles zombie sessions left by clients that disconnect without sending SESSION DESTROY.
      Parameters:
      maxAgeMs - maximum age in milliseconds since last access
      Returns:
      number of sessions removed