Add: Make SessionManager use SessionHandle

This commit is contained in:
Lars Simon Winzer
2026-03-20 16:22:47 +01:00
parent 247f16e26e
commit 7713069496
@@ -5,7 +5,7 @@ import java.util.concurrent.ConcurrentHashMap;
/** Manages active sessions in the server. */ /** Manages active sessions in the server. */
public class SessionManager { public class SessionManager {
private Map<SessionId, Session> sessions; private Map<SessionId, SessionHandle> sessions;
/** Constructs a new SessionManager. */ /** Constructs a new SessionManager. */
public SessionManager() { public SessionManager() {
@@ -17,8 +17,8 @@ public class SessionManager {
* *
* @param session the session to add * @param session the session to add
*/ */
public void addSession(Session session) { public void addSession(SessionHandle handle) {
sessions.put(session.getId(), session); sessions.put(handle.session().getId(), handle);
} }
/** /**
@@ -28,7 +28,13 @@ public class SessionManager {
* @return the removed session, or null if not found * @return the removed session, or null if not found
*/ */
public Session removeSession(SessionId id) { public Session removeSession(SessionId id) {
return sessions.remove(id); SessionHandle handle = sessions.remove(id);
if (handle == null) {
return null;
}
return handle.session();
} }
/** /**
@@ -38,7 +44,13 @@ public class SessionManager {
* @return the removed session, or null if not found * @return the removed session, or null if not found
*/ */
public Session removeSession(Session session) { public Session removeSession(Session session) {
return sessions.remove(session.getId()); SessionHandle handle = sessions.remove(session.getId());
if (handle == null) {
return null;
}
return handle.session();
} }
/** /**
@@ -48,6 +60,12 @@ public class SessionManager {
* @return the session with the specified ID, or null if not found * @return the session with the specified ID, or null if not found
*/ */
public Session getSessionById(SessionId id) { public Session getSessionById(SessionId id) {
return sessions.get(id); SessionHandle handle = sessions.get(id);
if (handle == null) {
return null;
}
return handle.session();
} }
} }