java.lang.Object
net.i2p.sam.SessionsDB
A database of SAM sessions, mapping nicknames to
SessionRecords. Provides synchronized access for concurrent SAM handlers.Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classException thrown when attempting to create a session with an existing destination.(package private) static classException thrown when attempting to create a session with an existing ID.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HashMap<String, SessionRecord> Session records by session name.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionbooleancontainsKey(String nick) Check if a session with the given nickname exists.booleanRemove a session record by nickname.Get a session record by nickname.Return a snapshot of all entries (nick -> SessionRecord).voidput(String nick, SessionRecord session) Store a session record.voidputDupDestOK(String nick, SessionRecord session) Store a session record, allowing duplicate destinations.intremoveStale(long maxAgeMs) Remove sessions that have not been accessed for longer than maxAgeMs.intsize()Get the number of registered sessions.
Field Details
map
Session records by session name.
Constructor Details
SessionsDB
public SessionsDB()Create a new empty sessions database.
Method Details
put
public void put(String nick, SessionRecord session) throws SessionsDB.ExistingIdException, SessionsDB.ExistingDestException Store a session record. Both the nick and destination must be unique.- Parameters:
nick- the session nicknamesession- the SessionRecord to store under nick, whose destination must also be unique- Throws:
SessionsDB.ExistingIdException- if a session with this nick already existsSessionsDB.ExistingDestException- if a session with this destination already exists
putDupDestOK
Store a session record, allowing duplicate destinations. Only the nick must be unique.- Parameters:
nick- the session nicknamesession- the SessionRecord to store under nick; its destination may repeat- Throws:
SessionsDB.ExistingIdException- if a session with this nick already exists
del
Remove a session record by nickname.- Parameters:
nick- the session nickname- Returns:
- true if removed, false if not found
get
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
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
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