Add: lastActivity field to Session and update from SessionReader
This commit is contained in:
@@ -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.transport.TransportLayer;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
/** Represents a client session in the network server. */
|
||||
public class Session {
|
||||
private final SessionId id;
|
||||
private Instant lastActivity;
|
||||
private final TransportLayer transport;
|
||||
private final BlockingQueue<PrimitiveResponse> responseQueue;
|
||||
private final CommandParserDispatcher dispatcher;
|
||||
@@ -31,6 +33,7 @@ public class Session {
|
||||
CommandParserDispatcher dispatcher,
|
||||
CommandRouter router) {
|
||||
this.id = new SessionId();
|
||||
this.lastActivity = Instant.now();
|
||||
this.transport = transport;
|
||||
this.dispatcher = dispatcher;
|
||||
this.router = router;
|
||||
@@ -46,6 +49,14 @@ public class Session {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Instant getLastInboundActivity() {
|
||||
return lastActivity;
|
||||
}
|
||||
|
||||
public void updateLastInboundActivity() {
|
||||
this.lastActivity = Instant.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TransportLayer of this session
|
||||
*
|
||||
|
||||
+1
@@ -43,6 +43,7 @@ public class SessionReader implements Runnable {
|
||||
RawPacket rawPacket = null;
|
||||
try {
|
||||
rawPacket = transport.read();
|
||||
session.updateLastInboundActivity();
|
||||
logger.debug("Recieved: {}", rawPacket);
|
||||
|
||||
RawRequest rawRequest = ProtocolParser.parse(rawPacket.payload());
|
||||
|
||||
Reference in New Issue
Block a user