Code cleanups.

This commit is contained in:
Simone Bordet 2016-03-08 12:46:10 +01:00
parent 18b689b820
commit 6ac2c4a701
1 changed files with 38 additions and 49 deletions

View File

@ -28,7 +28,6 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
@ -39,19 +38,20 @@ import org.eclipse.jetty.util.thread.ShutdownThread;
/**
* Shutdown/Stop Monitor thread.
* <p>
* This thread listens on the host/port specified by the STOP.HOST/STOP.PORT system parameter (defaults to 127.0.0.1/-1 for not listening) for
* request authenticated with the key given by the STOP.KEY system parameter (defaults to "eclipse") for admin requests.
* This thread listens on the host/port specified by the STOP.HOST/STOP.PORT
* system parameter (defaults to 127.0.0.1/-1 for not listening) for request
* authenticated with the key given by the STOP.KEY system parameter
* (defaults to "eclipse") for admin requests.
* <p>
* If the stop port is set to zero, then a random port is assigned and the port number is printed to stdout.
* If the stop port is set to zero, then a random port is assigned and the
* port number is printed to stdout.
* <p>
* Commands "stop" and "status" are currently supported.
*/
public class ShutdownMonitor
{
private final Set<LifeCycle> _lifeCycles = new CopyOnWriteArraySet<LifeCycle>();
// Implementation of safe lazy init, using Initialization on Demand Holder technique.
static class Holder
private static class Holder
{
static ShutdownMonitor instance = new ShutdownMonitor();
}
@ -61,33 +61,25 @@ public class ShutdownMonitor
return Holder.instance;
}
/* ------------------------------------------------------------ */
public static synchronized void register(LifeCycle... lifeCycles)
{
getInstance()._lifeCycles.addAll(Arrays.asList(lifeCycles));
}
/* ------------------------------------------------------------ */
public static synchronized void deregister(LifeCycle lifeCycle)
{
getInstance()._lifeCycles.remove(lifeCycle);
}
/* ------------------------------------------------------------ */
public static synchronized boolean isRegistered(LifeCycle lifeCycle)
{
return getInstance()._lifeCycles.contains(lifeCycle);
}
/* ------------------------------------------------------------ */
/**
* ShutdownMonitorRunnable
*
* Thread for listening to STOP.PORT for command to stop Jetty.
* If ShowndownMonitor.exitVm is true, then Sytem.exit will also be
* called after the stop.
*
*/
private class ShutdownMonitorRunnable implements Runnable
{
@ -327,6 +319,7 @@ public class ShutdownMonitor
}
private final Set<LifeCycle> _lifeCycles = new CopyOnWriteArraySet<LifeCycle>();
private boolean DEBUG;
private String host;
private int port;
@ -404,7 +397,6 @@ public class ShutdownMonitor
}
}
private void debug(String format, Object... args)
{
if (DEBUG)
@ -441,7 +433,6 @@ public class ShutdownMonitor
return exitVm;
}
public void setDebug(boolean flag)
{
this.DEBUG = flag;
@ -509,7 +500,6 @@ public class ShutdownMonitor
t.start();
}
protected boolean isAlive ()
{
boolean result = false;
@ -520,7 +510,6 @@ public class ShutdownMonitor
return result;
}
@Override
public String toString()
{