public void configureMonitor() { if(stopPort>0 && stopKey!=null) { ShutdownMonitor monitor = ShutdownMonitor.getInstance(); monitor.setPort(stopPort); monitor.setKey(stopKey); monitor.setExitVm(!nonblocking); } }
private void shutdownInput(Socket socket) { if (socket == null) return; try { socket.shutdownInput(); } catch (IOException ignore) { debug(ignore); } }
public void setKey(String key) { if (isAlive()) { throw new IllegalStateException("ShutdownMonitor already started"); } this.key = key; }
public static void deregister(LifeCycle lifeCycle) { getInstance().removeLifeCycle(lifeCycle); }
public static void register(LifeCycle... lifeCycles) { getInstance().addLifeCycles(lifeCycles); }
ShutdownMonitor.getInstance().start(); // initialize
ShutdownMonitor.register(this); ShutdownMonitor.getInstance().start(); // initialize
private ServerSocket listen() int port = getPort(); if (port < 0) debug("Not enabled (port < 0): %d", port); return null; String key = getKey(); try setPort(port); setKey(key); debug(x); System.err.println("Error binding ShutdownMonitor to port " + port + ": " + x.toString()); return null; debug("STOP.PORT=%d", port); debug("STOP.KEY=%s", key);
public static synchronized void deregister(LifeCycle lifeCycle) { getInstance()._lifeCycles.remove(lifeCycle); }
public static boolean isRegistered(LifeCycle lifeCycle) { return getInstance().containsLifeCycle(lifeCycle); }
debug("command=%s",cmd); if ("stop".equals(cmd)) debug("Issuing graceful shutdown.."); ShutdownThread.getInstance().run(); debug("Informing client that we are stopped."); out.write("Stopped\r\n".getBytes(StringUtil.__UTF8)); out.flush(); debug("Shutting down monitor"); close(socket); close(serverSocket); debug("Killing JVM"); System.exit(0); debug(e); System.err.println(e.toString()); close(socket); socket = null;
public void start() { if (isAlive()) { System.err.printf("ShutdownMonitor already started"); return; // cannot start it again } startListenSocket(); if (serverSocket == null) { return; } super.start(); }
protected void start() throws Exception { synchronized (this) { if (alive) { debug("Already started"); return; // cannot start it again } ServerSocket serverSocket = listen(); if (serverSocket != null) { alive = true; Thread thread = new Thread(new ShutdownMonitorRunnable(serverSocket)); thread.setDaemon(true); thread.setName("ShutdownMonitor"); thread.start(); } } }
ShutdownMonitor.getInstance().start(); // initialize
ShutdownMonitor.register(this); ShutdownMonitor.getInstance().start(); // initialize
private ServerSocket listen() int port = getPort(); if (port < 0) debug("Not enabled (port < 0): %d", port); return null; String key = getKey(); try setPort(port); setKey(key); debug(x); System.err.println("Error binding ShutdownMonitor to port " + port + ": " + x.toString()); return null; debug("STOP.PORT=%d", port); debug("STOP.KEY=%s", key);
public static synchronized boolean isRegistered(LifeCycle lifeCycle) { return getInstance()._lifeCycles.contains(lifeCycle); }