|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
@ -42,7 +42,7 @@ public abstract class AbstractHttpServer implements HttpServer { |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, HttpHandler> handlerMap; |
|
|
|
private Map<String, HttpHandler> handlerMap; |
|
|
|
|
|
|
|
|
|
|
|
private boolean running; |
|
|
|
private volatile boolean running; |
|
|
|
|
|
|
|
|
|
|
|
private final Object lifecycleMonitor = new Object(); |
|
|
|
private final Object lifecycleMonitor = new Object(); |
|
|
|
|
|
|
|
|
|
|
@ -87,8 +87,8 @@ public abstract class AbstractHttpServer implements HttpServer { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected HttpHandler resolveHttpHandler() { |
|
|
|
protected HttpHandler resolveHttpHandler() { |
|
|
|
return getHttpHandlerMap() != null ? |
|
|
|
return (getHttpHandlerMap() != null ? |
|
|
|
new ContextPathCompositeHandler(getHttpHandlerMap()) : getHttpHandler(); |
|
|
|
new ContextPathCompositeHandler(getHttpHandlerMap()) : getHttpHandler()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -111,26 +111,23 @@ public abstract class AbstractHttpServer implements HttpServer { |
|
|
|
|
|
|
|
|
|
|
|
// Lifecycle
|
|
|
|
// Lifecycle
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean isRunning() { |
|
|
|
|
|
|
|
synchronized (this.lifecycleMonitor) { |
|
|
|
|
|
|
|
return this.running; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public final void start() { |
|
|
|
public final void start() { |
|
|
|
synchronized (this.lifecycleMonitor) { |
|
|
|
synchronized (this.lifecycleMonitor) { |
|
|
|
if (!isRunning()) { |
|
|
|
if (!isRunning()) { |
|
|
|
String serverName = getClass().getSimpleName(); |
|
|
|
String serverName = getClass().getSimpleName(); |
|
|
|
logger.debug("Starting " + serverName + "..."); |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
|
|
|
logger.debug("Starting " + serverName + "..."); |
|
|
|
|
|
|
|
} |
|
|
|
this.running = true; |
|
|
|
this.running = true; |
|
|
|
try { |
|
|
|
try { |
|
|
|
StopWatch stopWatch = new StopWatch(); |
|
|
|
StopWatch stopWatch = new StopWatch(); |
|
|
|
stopWatch.start(); |
|
|
|
stopWatch.start(); |
|
|
|
startInternal(); |
|
|
|
startInternal(); |
|
|
|
long millis = stopWatch.getTotalTimeMillis(); |
|
|
|
long millis = stopWatch.getTotalTimeMillis(); |
|
|
|
logger.debug("Server started on port " + getPort() + "(" + millis + " millis)."); |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
|
|
|
logger.debug("Server started on port " + getPort() + "(" + millis + " millis)."); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Throwable ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
throw new IllegalStateException(ex); |
|
|
|
throw new IllegalStateException(ex); |
|
|
@ -167,6 +164,12 @@ public abstract class AbstractHttpServer implements HttpServer { |
|
|
|
|
|
|
|
|
|
|
|
protected abstract void stopInternal() throws Exception; |
|
|
|
protected abstract void stopInternal() throws Exception; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean isRunning() { |
|
|
|
|
|
|
|
return this.running; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void reset() { |
|
|
|
private void reset() { |
|
|
|
this.host = "0.0.0.0"; |
|
|
|
this.host = "0.0.0.0"; |
|
|
|
this.port = 0; |
|
|
|
this.port = 0; |
|
|
|