Commit 120e83b3 authored by Vít Kabele's avatar Vít Kabele

Session specific request processors.

parent 4680d424
Pipeline #3162 passed with stages
in 3 minutes
......@@ -220,6 +220,7 @@ __instrument_class (
// connection again.
//
ClientMessage message = CLIENT_MESSAGE__INIT;
message.session_id = session_id;
InstrumentClassRequest request = INSTRUMENT_CLASS_REQUEST__INIT;
request.flags = request_flags;
request.classname = (char *) class_name;
......
......@@ -22,6 +22,7 @@ import ch.usi.dag.dislserver.Protocol.ClientMessage;
import ch.usi.dag.dislserver.Protocol.ServerMessage;
import ch.usi.dag.dislserver.Protocol.SessionInitResponse;
import ch.usi.dag.dislserver.Protocol.InstrumentationDelivery;
import ch.usi.dag.dislserver.Protocol.InstrumentationAcceptConfirmation;
/**
......@@ -34,11 +35,6 @@ final class ConnectionHandler implements Runnable {
*/
private final SocketChannel __clientSocket;
/**
* Disl environment.
*/
private final RequestProcessor __requestProcessor;
/**
* Related server thread.
*/
......@@ -56,18 +52,15 @@ final class ConnectionHandler implements Runnable {
* Constructs new instance of class.
* @param server Related server
* @param clientSocket Socket to the client
* @param requestProcessor Disl environment
* @param serverThread Server thread
*/
ConnectionHandler (
final DiSLServer server,
final SocketChannel clientSocket,
final RequestProcessor requestProcessor,
final Thread serverThread
) {
__server = server;
__clientSocket = clientSocket;
__requestProcessor = requestProcessor;
__serverThread = serverThread;
}
......@@ -123,13 +116,21 @@ final class ConnectionHandler implements Runnable {
off += delivery.getSizes (i);
credentials.Instrumentations.add (bytes);
}
System.out.println (
String.format ("Received %d inst, of total size %d", delivery.getSizesCount (), delivery.getSizes (0))
);
credentials.Processor = RequestProcessor.newInstance ();
credentials.State = SessionCredentials.SessionState.READY;
response = ServerMessage
.newBuilder ()
.setInstrumentationAcceptConfirmation (
InstrumentationAcceptConfirmation
.newBuilder()
.setInstrumentationAccepted (true)
).build ();
sendMessage (response, timer);
break;
case INSTRUMENT_CLASS_REQUEST:
timer.mark (DiSLServer.ElapsedTime.UNPACK);
credentials = __server.getSession (request.getSessionId ());
//
// Process the request and send the response to the client.
// Update the timing stats if everything goes well.
......@@ -139,7 +140,7 @@ final class ConnectionHandler implements Runnable {
response = ServerMessage
.newBuilder ()
.setInstrumentClassResponse (
__requestProcessor.process (request.getInstrumentClassRequest ())
credentials.Processor.process (request.getInstrumentClassRequest ())
).build ();
timer.mark (DiSLServer.ElapsedTime.PROCESS);
......@@ -155,6 +156,7 @@ final class ConnectionHandler implements Runnable {
case CLOSE_CONNECTION:
int session_id = request.getSessionId ();
credentials = __server.getSession (session_id);
credentials.Processor.terminate ();
credentials.State = SessionCredentials.SessionState.CLOSED;
case REQUEST_NOT_SET:
default:
......
......@@ -65,12 +65,10 @@ public final class DiSLServer {
*
* @param serverSocket
* @param executor
* @param requestProcessor
*/
void run (
final ServerSocketChannel serverSocket,
final ExecutorService executor,
final RequestProcessor requestProcessor
final ExecutorService executor
) {
try {
final Thread serverThread = Thread.currentThread ();
......@@ -87,7 +85,6 @@ public final class DiSLServer {
executor.submit (new ConnectionHandler (
this,
clientSocket,
requestProcessor,
serverThread
));
}
......@@ -159,18 +156,16 @@ public final class DiSLServer {
//
final RequestProcessor processor = __getRequestProcessorOrDie ();
final ExecutorService executor = Executors.newCachedThreadPool ();
final DiSLServer server = new DiSLServer ();
__log.debug ("server started");
__serverStarted ();
server.run (socket, executor, processor);
server.run (socket, executor);
__log.debug ("server shutting down");
executor.shutdown ();
processor.terminate ();
__closeSocket (socket);
__log.debug ("server finished");
......
......@@ -53,9 +53,14 @@ public class SessionCredentials {
*/
List<byte[]> Instrumentations = new ArrayList<>();
/**
* A request processor to handle the instrumentation requests.
*/
RequestProcessor Processor;
/**
* Construct the class
* @param session_id
* @param session_id Session identifier.
*/
SessionCredentials(int session_id){
this.session_id = session_id;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment