Servlet terminate handler

This commit is contained in:
Alexander Nozik 2017-04-12 10:24:23 +03:00
parent 804898ca93
commit 170b537a57

View File

@ -7,12 +7,9 @@ import hep.dataforge.storage.filestorage.FileStorage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException; import java.text.ParseException;
import java.util.Objects;
/** /**
* Created by darksnake on 11-Apr-17. * 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 NUMASS_REPO_ELEMENT = "numass.repository";
private static final String LISTENER_ELEMENT = "listener"; private static final String LISTENER_ELEMENT = "listener";
private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path"; 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; FileStorage root;
NumassServer listener; NumassServer listener;
@ -39,10 +36,14 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
public static void main(String[] args) { public static void main(String[] args) {
try (ServerRunner r = new ServerRunner()) { try (ServerRunner r = new ServerRunner()) {
r.start(); r.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String in = null; Runtime.getRuntime().addShutdownHook(new Thread(()->{
while (!Objects.equals(in, "exit")) { logger.info("Shutting down");
in = reader.readLine(); r.close();
}));
while (true) {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();