Add: lastActivity field to Session and update from SessionReader

This commit is contained in:
Lars Simon Winzer
2026-03-28 13:01:13 +01:00
parent 4b187fac27
commit 8313a3b777
2 changed files with 12 additions and 0 deletions
@@ -6,12 +6,14 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.parser.CommandParserDispat
import ch.unibas.dmi.dbis.cs108.casono.server.network.response.PrimitiveResponse; import ch.unibas.dmi.dbis.cs108.casono.server.network.response.PrimitiveResponse;
import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TransportLayer; import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TransportLayer;
import java.io.IOException; import java.io.IOException;
import java.time.Instant;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
/** Represents a client session in the network server. */ /** Represents a client session in the network server. */
public class Session { public class Session {
private final SessionId id; private final SessionId id;
private Instant lastActivity;
private final TransportLayer transport; private final TransportLayer transport;
private final BlockingQueue<PrimitiveResponse> responseQueue; private final BlockingQueue<PrimitiveResponse> responseQueue;
private final CommandParserDispatcher dispatcher; private final CommandParserDispatcher dispatcher;
@@ -31,6 +33,7 @@ public class Session {
CommandParserDispatcher dispatcher, CommandParserDispatcher dispatcher,
CommandRouter router) { CommandRouter router) {
this.id = new SessionId(); this.id = new SessionId();
this.lastActivity = Instant.now();
this.transport = transport; this.transport = transport;
this.dispatcher = dispatcher; this.dispatcher = dispatcher;
this.router = router; this.router = router;
@@ -46,6 +49,14 @@ public class Session {
return this.id; return this.id;
} }
public Instant getLastInboundActivity() {
return lastActivity;
}
public void updateLastInboundActivity() {
this.lastActivity = Instant.now();
}
/** /**
* Returns the TransportLayer of this session * Returns the TransportLayer of this session
* *
@@ -43,6 +43,7 @@ public class SessionReader implements Runnable {
RawPacket rawPacket = null; RawPacket rawPacket = null;
try { try {
rawPacket = transport.read(); rawPacket = transport.read();
session.updateLastInboundActivity();
logger.debug("Recieved: {}", rawPacket); logger.debug("Recieved: {}", rawPacket);
RawRequest rawRequest = ProtocolParser.parse(rawPacket.payload()); RawRequest rawRequest = ProtocolParser.parse(rawPacket.payload());