use of org.apache.qpid.server.util.DaemonThreadFactory in project qpid-broker-j by apache.
the class HttpManagement method createServer.
private Server createServer(Collection<HttpPort<?>> ports) {
LOGGER.debug("Starting up web server on {}", ports);
_jettyServerExecutor = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory("Jetty-Server-Thread"));
Server server = new Server(new ExecutorThreadPool(_jettyServerExecutor));
int lastPort = -1;
for (HttpPort<?> port : ports) {
ServerConnector connector = createConnector(port, server);
connector.addBean(new ConnectionTrackingListener());
server.addConnector(connector);
_portConnectorMap.put(port, connector);
lastPort = port.getPort();
}
ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
root.setContextPath("/");
root.setCompactPath(true);
server.setHandler(root);
final ErrorHandler errorHandler = new ErrorHandler() {
@Override
protected void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException {
String uri = request.getRequestURI();
writeErrorPageMessage(request, writer, code, message, uri);
for (int i = 0; i < 20; i++) writer.write("<br/> \n");
}
};
root.setErrorHandler(errorHandler);
// set servlet context attributes for broker and configuration
root.getServletContext().setAttribute(HttpManagementUtil.ATTR_BROKER, getBroker());
root.getServletContext().setAttribute(HttpManagementUtil.ATTR_MANAGEMENT_CONFIGURATION, this);
root.addFilter(new FilterHolder(new ExceptionHandlingFilter()), "/*", EnumSet.allOf(DispatcherType.class));
FilterHolder corsFilter = new FilterHolder(new CrossOriginFilter());
corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, getCorsAllowOrigins());
corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, Joiner.on(",").join(getCorsAllowMethods()));
corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, getCorsAllowHeaders());
corsFilter.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, String.valueOf(getCorsAllowCredentials()));
root.addFilter(corsFilter, "/*", EnumSet.of(DispatcherType.REQUEST));
root.addFilter(new FilterHolder(new MethodFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
addFiltersAndServletsForRest(root);
if (!Boolean.TRUE.equals(getContextValue(Boolean.class, DISABLE_UI_CONTEXT_NAME))) {
addFiltersAndServletsForUserInterfaces(root);
}
root.getSessionHandler().getSessionCookieConfig().setName(JSESSIONID_COOKIE_PREFIX + lastPort);
root.getSessionHandler().getSessionCookieConfig().setHttpOnly(true);
root.getSessionHandler().setMaxInactiveInterval(getSessionTimeout());
return server;
}
use of org.apache.qpid.server.util.DaemonThreadFactory in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacade method connectToHelperNodeAndCheckPermittedHosts.
public static Collection<String> connectToHelperNodeAndCheckPermittedHosts(final String nodeName, final String hostPort, final String groupName, final String helperNodeName, final String helperHostPort, final int dbPingSocketTimeout) {
ExecutorService executor = null;
Future<Collection<String>> future = null;
try {
executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory(String.format("PermittedHostsCheck-%s-%s", groupName, nodeName)));
future = executor.submit(new Callable<Collection<String>>() {
@Override
public Collection<String> call() throws Exception {
return getPermittedHostsFromHelper(nodeName, groupName, helperNodeName, helperHostPort, dbPingSocketTimeout);
}
});
try {
final long timeout = (long) (dbPingSocketTimeout * 1.25);
final Collection<String> permittedNodes = dbPingSocketTimeout <= 0 ? future.get() : future.get(timeout, TimeUnit.MILLISECONDS);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Node '%s' permits nodes: '%s'", helperNodeName, String.valueOf(permittedNodes)));
}
if (permittedNodes == null || !permittedNodes.contains(hostPort)) {
throw new IllegalConfigurationException(String.format("Node using address '%s' is not permitted to join the group '%s'", hostPort, groupName));
}
return permittedNodes;
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else {
throw new RuntimeException(cause);
}
} catch (TimeoutException e) {
future.cancel(true);
throw new ExternalServiceTimeoutException(String.format("Task timed out trying to connect to existing node '%s' at '%s'", nodeName, hostPort));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ExternalServiceException(String.format("Task failed to connect to existing node '%s' at '%s'", nodeName, hostPort));
}
} finally {
executor.shutdown();
}
}
Aggregations