Commit 7985b098 authored by Lubomir Bulej's avatar Lubomir Bulej

Remove the --instrumentation and --analysis flags from server CLI

This simplifies the server command line interface a bit. If a client
asks for unsupported function, the server can send a negative response
to the session init request.
parent aae4d5ef
......@@ -18,19 +18,12 @@ OPTIONS
Listen for connections on the given port.
-d|--debug Enable server debugging.
-c|--continuous Enable continuous operation (server does not exit when the last session ends).
--instrumentation Enable instrumentation-server mode.
--analysis Enable analysis-server mode.
--startup-file=<FILE>
Delete the given file when the server starts listening.
Useful for synchronization in scripts.
--shutdown-file=<FILE>
Delete the given file when the server VM terminates.
Useful for synchronization in scripts.
DiSL Specific options
The following options are ignored if the instrumentation-server
mode is not active.
-e|--exclusion-list=<FILE>
Use the given file as a global exclusion list for instrumentation.
--dump-original=<DIR>
......
......@@ -19,7 +19,7 @@ public final class SessionManagerTest {
@Test
public final void canCreateSession () {
final SessionManager sessionManager = new SessionManager ();
final Session session = sessionManager.createSession ();
final Session session = sessionManager.createSession (false, null);
Assert.assertNotNull (session);
}
......@@ -32,7 +32,7 @@ public final class SessionManagerTest {
@Test
public final void createdSessionExists () {
final SessionManager sessionManager = new SessionManager ();
final Session session = sessionManager.createSession ();
final Session session = sessionManager.createSession (false, null);
Assert.assertTrue (sessionManager.sessionExists (session.id ()));
}
......@@ -48,7 +48,7 @@ public final class SessionManagerTest {
public final void createdSessionCanBeRetrived ()
throws RequestErrorException {
final SessionManager sessionManager = new SessionManager ();
final Session session = sessionManager.createSession ();
final Session session = sessionManager.createSession (false, null);
Assert.assertSame (session, sessionManager.getSession (session.id ()));
}
......@@ -75,7 +75,7 @@ public final class SessionManagerTest {
throws RequestErrorException {
final SessionManager sessionManager = new SessionManager ();
final Session session = sessionManager.createSession ();
final Session session = sessionManager.createSession (false, null);
final int sessionId = session.id ();
Assert.assertTrue (sessionManager.sessionExists (sessionId));
......
......@@ -13,7 +13,7 @@ public final class SessionTest {
@Test
public final void canCreateEmptySession () {
final Session session = new Session (42);
final Session session = new Session (42, false, null);
Assert.assertEquals (42, session.id ());
}
......
......@@ -82,20 +82,6 @@ final class Config {
boolean continuousModeEnabled = false;
@Parameter (
names = { "--instrumentation" },
description = "Enable instrumentation-server mode."
)
boolean instrumentationEnabled = false;
@Parameter (
names = { "--analysis" },
description = "Enable analysis-server mode (requires analysis classes in the class path)."
)
boolean analysisEnabled = false;
static final class OptionalRegularReadableFileConverter
implements IStringConverter <Optional <File>> {
@Override
......
......@@ -49,11 +49,6 @@ public final class Main {
System.exit (STATUS_OK);
}
if (!config.instrumentationEnabled && !config.analysisEnabled) {
System.err.println ("error: At least one of {instrumentation,analysis} modes must be enabled!");
System.exit (STATUS_ERROR_CONFIG);
}
//
final Logger log = Logging.getPackageInstance ();
......
......@@ -5,6 +5,7 @@ import ch.usi.dag.dislre.protocol.Main.ClientMessage;
import ch.usi.dag.dislre.protocol.Main.ServerMessage;
import ch.usi.dag.dislre.protocol.Main.SessionInitRequest;
import ch.usi.dag.dislre.protocol.Main.SessionInitResponse;
import ch.usi.dag.shvm.SHVM;
import ch.usi.dag.shvm.SHVMImpl;
......@@ -102,40 +103,26 @@ final class RequestDispatcher {
final Server.Context context,
final ServerMessage.Builder builder
) throws RequestErrorException {
final Session session = context.sessionManager.createSession ();
// Client requires the ShadowVM functionality
final boolean analysisRequired = request.getRequireShvm();
session.setShadowVMRequested (analysisRequired);
if (analysisRequired) {
// Server is able to provide such functionality
if (context.isShvm) {
session.setShadowVM (new SHVMImpl (context.log));
} else {
context.log.info (
"Client requested analysis functionality. "+
"To enable it, run the server with the --analysis option."
);
throw new RequestErrorException (
"Server does not provide analysis services"
);
}
}
// Client requires the DiSL functionality
final boolean instrumentationRequired = request.getRequireDisl();
session.setDiSLRequested (instrumentationRequired);
if (instrumentationRequired && !context.isDisl) {
context.log.info(
"Client requested instrumentation functionality. "+
"To enable it, run the server with the --instrumentation option."
);
throw new RequestErrorException (
"Server does not provide instrumentation services"
);
}
context.log.debug (
"session init request: instrumentation=%s, analysis=%s",
request.getRequireDisl (), request.getRequireShvm ()
);
//
// If the client requires instrumentation functionality, we make note of
// it, but because we need the instrumentation to initialize DiSL, we
// delay creating a DiSL instance until we receive it.
//
// If the client requires the analysis functionality, we can create a
// Shadow VM immediately, because we don't need any other information.
// We do it now instead of lazily (with first Shadow VM request).
//
final SHVM shadowVm = request.getRequireShvm ()
? new SHVMImpl (context.log) : null;
final Session session = context.sessionManager.createSession (
request.getRequireDisl(), shadowVm
);
return builder.setSessionInitResponse (
SessionInitResponse.newBuilder ().setSessionId (session.id ()).build ()
......
......@@ -26,8 +26,6 @@ final class Server {
static Server createWithConfig (final Config config)
throws ServerInitializationException {
final Context context = new Context (
config.instrumentationEnabled,
config.analysisEnabled,
new SessionManager (),
config.exclusionListFile
);
......@@ -47,10 +45,6 @@ final class Server {
final SessionManager sessionManager;
final boolean isDisl;
final boolean isShvm;
/**
* This is the name of file containing the DiSL exclusion list.
*/
......@@ -59,13 +53,9 @@ final class Server {
final Logger log = Logging.getPackageInstance ();
private Context (
final boolean disl,
final boolean shvm,
final SessionManager sessionManager,
final Optional <File> exclusionListFile
) {
isDisl = disl;
isShvm = shvm;
this.sessionManager = sessionManager;
this.exclusionListFile = exclusionListFile;
}
......
......@@ -22,19 +22,19 @@ final class Session {
//
private boolean __disl_requested;
private final boolean __dislRequested;
private DiSL __disl;
private boolean __shvm_requested;
private SHVM __shvm;
private final SHVM __shvm;
//
Session (final int id) {
Session (final int id, final boolean dislRequested, final SHVM shvm) {
__id = id;
__dislRequested = dislRequested;
__shvm = shvm;
}
......@@ -44,13 +44,8 @@ final class Session {
//
void setDiSLRequested (final boolean requested) {
__disl_requested = requested;
}
boolean getDiSLRequested () {
return __disl_requested;
return __dislRequested;
}
......@@ -65,18 +60,8 @@ final class Session {
//
void setShadowVMRequested (final boolean requested) {
__shvm_requested = requested;
}
boolean getShadowVMRequested () {
return __shvm_requested;
}
void setShadowVM (final SHVM shvm) {
__shvm = shvm;
return __shvm != null;
}
......
......@@ -3,6 +3,8 @@ package ch.usi.dag.server;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import ch.usi.dag.shvm.SHVM;
/**
* Session manager which keeps track of sessions. Provides an interface to
......@@ -21,10 +23,13 @@ final class SessionManager {
/**
* Creates a new (empty) session with a unique identifier.
* @param instrumentationRequested
* @param shadowVm
*/
Session createSession () {
Session createSession (final boolean instrumentationRequested, final SHVM shadowVm) {
return __sessionsById.computeIfAbsent (
__lastSessionId.incrementAndGet (), Session::new
__lastSessionId.incrementAndGet (),
id -> new Session (id, instrumentationRequested, shadowVm)
);
}
......
......@@ -69,8 +69,6 @@ public class ClientEvaluationRunner extends Runner {
command.addAll (propertiesStartingWith ("dislreserver."));
command.add (_SERVER_CLASS_.getName ());
command.add("--analysis");
if (statusFile != null) {
command.add("--startup-file");
command.add(statusFile.getCanonicalPath());
......
......@@ -80,9 +80,6 @@ public class ClientServerEvaluationRunner extends Runner {
command.addAll (propertiesStartingWith ("dislreserver."));
command.add (_SERVER_CLASS_.getName ());
command.add("--instrumentation");
command.add("--analysis");
if (statusFile != null) {
command.add("--startup-file");
command.add(statusFile.getCanonicalPath());
......
......@@ -68,7 +68,6 @@ public class ClientServerRunner extends Runner {
command.addAll (propertiesStartingWith ("dislserver."));
command.addAll (propertiesStartingWith ("disl."));
command.add (_SERVER_CLASS_.getName ());
command.add ("--instrumentation");
if (statusFile != null) {
command.add("--startup-file");
......
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