From 170b537a57bc82978faf0429d7cb54cfa3558262 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 12 Apr 2017 10:24:23 +0300 Subject: [PATCH] Servlet terminate handler --- .../java/inr/numass/server/ServerRunner.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/numass-storage/numass-server/src/main/java/inr/numass/server/ServerRunner.java b/numass-storage/numass-server/src/main/java/inr/numass/server/ServerRunner.java index 29acf7fd..a9f38c90 100644 --- a/numass-storage/numass-server/src/main/java/inr/numass/server/ServerRunner.java +++ b/numass-storage/numass-server/src/main/java/inr/numass/server/ServerRunner.java @@ -7,12 +7,9 @@ import hep.dataforge.storage.filestorage.FileStorage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStreamReader; import java.text.ParseException; -import java.util.Objects; /** * Created by darksnake on 11-Apr-17. @@ -22,7 +19,7 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable { private static final String NUMASS_REPO_ELEMENT = "numass.repository"; private static final String LISTENER_ELEMENT = "listener"; private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path"; - private final Logger logger = LoggerFactory.getLogger("NUMASS-SERVER"); + private final static Logger logger = LoggerFactory.getLogger("NUMASS-SERVER"); FileStorage root; NumassServer listener; @@ -39,10 +36,14 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable { public static void main(String[] args) { try (ServerRunner r = new ServerRunner()) { r.start(); - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - String in = null; - while (!Objects.equals(in, "exit")) { - in = reader.readLine(); + + Runtime.getRuntime().addShutdownHook(new Thread(()->{ + logger.info("Shutting down"); + r.close(); + })); + + while (true) { + } } catch (Exception e) { e.printStackTrace();