use of com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool in project dropwizard by dropwizard.
the class AbstractServerFactory method createThreadPool.
protected ThreadPool createThreadPool(MetricRegistry metricRegistry) {
final BlockingQueue<Runnable> queue = new BlockingArrayQueue<>(minThreads, maxThreads, maxQueuedRequests);
final InstrumentedQueuedThreadPool threadPool = new InstrumentedQueuedThreadPool(metricRegistry, maxThreads, minThreads, (int) idleThreadTimeout.toMilliseconds(), queue);
threadPool.setName("dw");
return threadPool;
}
use of com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool in project chassis by Kixeye.
the class WebSocketTransportConfiguration method webSocketServer.
@Bean(initMethod = "start", destroyMethod = "stop")
@Order(0)
public Server webSocketServer(@Value("${websocket.enabled:false}") boolean websocketEnabled, @Value("${websocket.hostname:}") String websocketHostname, @Value("${websocket.port:-1}") int websocketPort, @Value("${secureWebsocket.enabled:false}") boolean secureWebsocketEnabled, @Value("${secureWebsocket.hostname:}") String secureWebsocketHostname, @Value("${secureWebsocket.port:-1}") int secureWebsocketPort, @Value("${secureWebsocket.selfSigned:false}") boolean selfSigned, @Value("${secureWebsocket.mutualSsl:false}") boolean mutualSsl, @Value("${secureWebsocket.keyStorePath:}") String keyStorePath, @Value("${secureWebsocket.keyStoreData:}") String keyStoreData, @Value("${secureWebsocket.keyStorePassword:}") String keyStorePassword, @Value("${secureWebsocket.keyManagerPassword:}") String keyManagerPassword, @Value("${secureWebsocket.trustStorePath:}") String trustStorePath, @Value("${secureWebsocket.trustStoreData:}") String trustStoreData, @Value("${secureWebsocket.trustStorePassword:}") String trustStorePassword, @Value("${securewebsocket.excludedCipherSuites:}") String[] excludedCipherSuites) throws Exception {
// set up servlets
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
context.setErrorHandler(null);
context.setWelcomeFiles(new String[] { "/" });
for (final MessageSerDe serDe : serDes) {
// create the websocket creator
final WebSocketCreator webSocketCreator = new WebSocketCreator() {
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) {
// this will have spring construct a new one for every session
ActionInvokingWebSocket webSocket = forwardingWebSocket();
webSocket.setSerDe(serDe);
webSocket.setUpgradeRequest(req);
webSocket.setUpgradeResponse(resp);
return webSocket;
}
};
// configure the websocket servlet
ServletHolder webSocketServlet = new ServletHolder(new WebSocketServlet() {
private static final long serialVersionUID = -3022799271546369505L;
@Override
public void configure(WebSocketServletFactory factory) {
factory.setCreator(webSocketCreator);
}
});
Map<String, String> webSocketProperties = new HashMap<>();
AbstractConfiguration config = ConfigurationManager.getConfigInstance();
Iterator<String> webSocketPropertyKeys = config.getKeys("websocket");
while (webSocketPropertyKeys.hasNext()) {
String key = webSocketPropertyKeys.next();
webSocketProperties.put(key.replaceFirst(Pattern.quote("websocket."), ""), config.getString(key));
}
webSocketServlet.setInitParameters(webSocketProperties);
context.addServlet(webSocketServlet, "/" + serDe.getMessageFormatName() + "/*");
}
// create the server
Server server;
if (metricRegistry == null || !monitorThreadpool) {
server = new Server();
server.setHandler(context);
} else {
server = new Server(new InstrumentedQueuedThreadPool(metricRegistry));
InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry);
instrumented.setHandler(context);
server.setHandler(instrumented);
}
// set up connectors
if (websocketEnabled) {
InetSocketAddress address = StringUtils.isBlank(websocketHostname) ? new InetSocketAddress(websocketPort) : new InetSocketAddress(websocketHostname, websocketPort);
JettyConnectorRegistry.registerHttpConnector(server, address);
}
if (secureWebsocketEnabled) {
InetSocketAddress address = StringUtils.isBlank(secureWebsocketHostname) ? new InetSocketAddress(secureWebsocketPort) : new InetSocketAddress(secureWebsocketHostname, secureWebsocketPort);
JettyConnectorRegistry.registerHttpsConnector(server, address, selfSigned, mutualSsl, keyStorePath, keyStoreData, keyStorePassword, keyManagerPassword, trustStorePath, trustStoreData, trustStorePassword, excludedCipherSuites);
}
return server;
}
use of com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool in project metrics by dropwizard.
the class ExampleServer method main.
public static void main(String[] args) throws Exception {
COUNTER_1.inc();
COUNTER_2.inc();
final ThreadPool threadPool = new InstrumentedQueuedThreadPool(REGISTRY);
final Server server = new Server(threadPool);
final Connector connector = new ServerConnector(server, new InstrumentedConnectionFactory(new HttpConnectionFactory(), REGISTRY.timer("http.connection")));
server.addConnector(connector);
final ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/initial");
context.setAttribute(MetricsServlet.METRICS_REGISTRY, REGISTRY);
context.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, new HealthCheckRegistry());
final ServletHolder holder = new ServletHolder(new AdminServlet());
context.addServlet(holder, "/dingo/*");
final InstrumentedHandler handler = new InstrumentedHandler(REGISTRY);
handler.setHandler(context);
server.setHandler(handler);
server.start();
server.join();
}
use of com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool in project metrics by dropwizard.
the class ExampleServer method main.
public static void main(String[] args) throws Exception {
COUNTER_1.inc();
COUNTER_2.inc();
final ThreadPool threadPool = new InstrumentedQueuedThreadPool(REGISTRY);
final Server server = new Server(threadPool);
final Connector connector = new ServerConnector(server, new InstrumentedConnectionFactory(new HttpConnectionFactory(), REGISTRY.timer("http.connection")));
server.addConnector(connector);
final ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/initial");
context.setAttribute(MetricsServlet.METRICS_REGISTRY, REGISTRY);
context.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, new HealthCheckRegistry());
final ServletHolder holder = new ServletHolder(new AdminServlet());
context.addServlet(holder, "/dingo/*");
final InstrumentedHandler handler = new InstrumentedHandler(REGISTRY);
handler.setHandler(context);
server.setHandler(handler);
server.start();
server.join();
}
use of com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool in project dropwizard by dropwizard.
the class DefaultServerFactory method buildAdminConnectors.
private List<Connector> buildAdminConnectors(MetricRegistry metricRegistry, Server server) {
// threadpool is shared between all the connectors, so it should be managed by the server instead of the
// individual connectors
final QueuedThreadPool threadPool = new InstrumentedQueuedThreadPool(metricRegistry, adminMaxThreads, adminMinThreads);
threadPool.setName("dw-admin");
server.addBean(threadPool);
final List<Connector> connectors = new ArrayList<>();
for (ConnectorFactory factory : adminConnectors) {
final Connector connector = factory.build(server, metricRegistry, "admin", threadPool);
if (connector instanceof ContainerLifeCycle) {
connector.unmanage(threadPool);
}
connectors.add(connector);
}
return connectors;
}
Aggregations