From ce7078ecad253adc96dd58ba08737a227a38eb7f Mon Sep 17 00:00:00 2001 From: delvh Date: Thu, 2 Jul 2020 20:01:28 +0200 Subject: [PATCH] Added capability to prevent the normal stop command of the server --- src/main/java/envoy/server/Startup.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java index 9ad4bc3..9306356 100755 --- a/src/main/java/envoy/server/Startup.java +++ b/src/main/java/envoy/server/Startup.java @@ -31,7 +31,7 @@ public class Startup { /** * Initializes the logger with a new config instance. - * + * * @since Envoy Server Standalone v0.1-beta */ private static void initLogging() { @@ -51,14 +51,15 @@ public class Startup { /** * Starts the server. * - * @param args the run configuration. Currently unused. + * @param args the run configuration. If it is "no-enter-to-stop" at position 0, + * no command to read in an enter press will be generated * @throws IOException if the server crashes * @since Envoy Server Standalone v0.1-alpha */ public static void main(String[] args) throws IOException { initLogging(); - Server server = new Server(8080, ObjectMessageReader::new, + final Server server = new Server(8080, ObjectMessageReader::new, new ObjectMessageProcessor(Set.of(new LoginCredentialProcessor(), new MessageProcessor(), new GroupCreationProcessor(), @@ -69,16 +70,18 @@ public class Startup { new ContactOperationProcessor()))); // Initialize the current message ID - PersistenceManager persistenceManager = PersistenceManager.getInstance(); + final PersistenceManager persistenceManager = PersistenceManager.getInstance(); if (persistenceManager.getConfigItemByID("currentMessageId") == null) persistenceManager.addConfigItem(new envoy.server.data.ConfigItem("currentMessageId", "0")); server.start(); server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance()); - System.out.println("Press the return key to stop the server..."); - System.in.read(); - System.out.println("Stopped"); - System.exit(0); + if (args.length == 0 || !args[0].equalsIgnoreCase("no-enter-to-stop")) { + System.out.println("Press the return key to stop the server..."); + System.in.read(); + System.out.println("Stopped"); + System.exit(0); + } } }