Added capability to prevent the normal stop command of the server

This commit is contained in:
delvh 2020-07-02 20:01:28 +02:00
parent 8bd5dd7d35
commit 495f5a67df

View File

@ -31,7 +31,7 @@ public class Startup {
/** /**
* Initializes the logger with a new config instance. * Initializes the logger with a new config instance.
* *
* @since Envoy Server Standalone v0.1-beta * @since Envoy Server Standalone v0.1-beta
*/ */
private static void initLogging() { private static void initLogging() {
@ -51,14 +51,15 @@ public class Startup {
/** /**
* Starts the server. * 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 * @throws IOException if the server crashes
* @since Envoy Server Standalone v0.1-alpha * @since Envoy Server Standalone v0.1-alpha
*/ */
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
initLogging(); initLogging();
Server server = new Server(8080, ObjectMessageReader::new, final Server server = new Server(8080, ObjectMessageReader::new,
new ObjectMessageProcessor(Set.of(new LoginCredentialProcessor(), new ObjectMessageProcessor(Set.of(new LoginCredentialProcessor(),
new MessageProcessor(), new MessageProcessor(),
new GroupCreationProcessor(), new GroupCreationProcessor(),
@ -69,16 +70,18 @@ public class Startup {
new ContactOperationProcessor()))); new ContactOperationProcessor())));
// Initialize the current message ID // Initialize the current message ID
PersistenceManager persistenceManager = PersistenceManager.getInstance(); final PersistenceManager persistenceManager = PersistenceManager.getInstance();
if (persistenceManager.getConfigItemByID("currentMessageId") == null) if (persistenceManager.getConfigItemByID("currentMessageId") == null)
persistenceManager.addConfigItem(new envoy.server.data.ConfigItem("currentMessageId", "0")); persistenceManager.addConfigItem(new envoy.server.data.ConfigItem("currentMessageId", "0"));
server.start(); server.start();
server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance()); server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
System.out.println("Press the return key to stop the server..."); if (args.length == 0 || !args[0].equalsIgnoreCase("no-enter-to-stop")) {
System.in.read(); System.out.println("Press the return key to stop the server...");
System.out.println("Stopped"); System.in.read();
System.exit(0); System.out.println("Stopped");
System.exit(0);
}
} }
} }