@Override
public void start(final String rootPath, int port) throws IOException, DeploymentException {
contextPath = rootPath;
server = new HttpServer();
final ServerConfiguration config = server.getServerConfiguration();
final NetworkListener listener =
new NetworkListener("grizzly",
"0.0.0.0",
port);
server.addListener(listener);
// server = HttpServer.createSimpleServer(rootPath, port);
ThreadPoolConfig workerThreadPoolConfig = Utils.getProperty(localProperties, WORKER_THREAD_POOL_CONFIG, ThreadPoolConfig.class);
ThreadPoolConfig selectorThreadPoolConfig = Utils.getProperty(localProperties, SELECTOR_THREAD_POOL_CONFIG, ThreadPoolConfig.class);
// TYRUS-287: configurable server thread pools
if (workerThreadPoolConfig != null || selectorThreadPoolConfig != null) {
TCPNIOTransportBuilder transportBuilder = TCPNIOTransportBuilder.newInstance();
if (workerThreadPoolConfig != null) {
transportBuilder.setWorkerThreadPoolConfig(workerThreadPoolConfig);
}
if (selectorThreadPoolConfig != null) {
transportBuilder.setSelectorThreadPoolConfig(selectorThreadPoolConfig);
}
transportBuilder.setIOStrategy(WorkerThreadIOStrategy.getInstance());
server.getListener("grizzly").setTransport(transportBuilder.build());
} else {
// if no configuration is set, just update IO Strategy to worker thread strat.
server.getListener("grizzly").getTransport().setIOStrategy(WorkerThreadIOStrategy.getInstance());
}
// idle timeout set to indefinite.
server.getListener("grizzly").getKeepAlive().setIdleTimeoutInSeconds(-1);
server.getListener("grizzly").registerAddOn(new WebSocketAddOn(this));
final WebSocketEngine webSocketEngine = getWebSocketEngine();
final Object staticContentPath = localProperties.get(Server.STATIC_CONTENT_ROOT);
HttpHandler staticHandler = null;
if (staticContentPath != null && !staticContentPath.toString().isEmpty()) {
staticHandler = new StaticHttpHandler(staticContentPath.toString());
}
final Object wsadl = localProperties.get(TyrusWebSocketEngine.WSADL_SUPPORT);
if (wsadl != null && wsadl.toString().equalsIgnoreCase("true")) { // wsadl enabled
config.addHttpHandler(new WsadlHttpHandler((TyrusWebSocketEngine) webSocketEngine, staticHandler));
} else if (staticHandler != null) { // wsadl disabled
config.addHttpHandler(staticHandler);
}
if (applicationEventListener != null) {
applicationEventListener.onApplicationInitialized(rootPath);
}