Search in sources :

Example 16 with NetworkListener

use of org.glassfish.grizzly.http.server.NetworkListener in project narayana by jbosstm.

the class SpdyEnabledHttpServer method createHttpServer.

private static HttpServer createHttpServer(final URI uri, final GrizzlyHttpContainer handler, final boolean secure, final SSLEngineConfigurator sslEngineConfigurator, final int poolSize, final boolean enableSpdy) throws ProcessingException {
    final String host = (uri.getHost() == null) ? NetworkListener.DEFAULT_NETWORK_HOST : uri.getHost();
    final int port = (uri.getPort() == -1) ? 80 : uri.getPort();
    final HttpServer server = new HttpServer();
    final NetworkListener listener = new NetworkListener("grizzly", host, port);
    listener.setSecure(secure);
    if (sslEngineConfigurator != null) {
        listener.setSSLEngineConfig(sslEngineConfigurator);
    }
    if (poolSize > 0) {
        TCPNIOTransport transport = listener.getTransport();
        transport.getKernelThreadPoolConfig().setMaxPoolSize(poolSize);
    }
    if (enableSpdy) {
        SpdyAddOn spdyAddOn = new SpdyAddOn(SpdyMode.NPN);
        System.out.printf("SPDY: max conc. streams: %d%n", spdyAddOn.getMaxConcurrentStreams());
        listener.registerAddOn(spdyAddOn);
    }
    listener.setSecure(secure);
    server.addListener(listener);
    // Map the path to the processor.
    final ServerConfiguration config = server.getServerConfiguration();
    if (handler != null) {
        config.addHttpHandler(handler, uri.getPath());
    }
    config.setPassTraceRequest(true);
    try {
        // Start the server.
        server.start();
    } catch (IOException ex) {
        throw new ProcessingException("IOException thrown when trying to start grizzly server", ex);
    }
    return server;
}
Also used : TCPNIOTransport(org.glassfish.grizzly.nio.transport.TCPNIOTransport) ServerConfiguration(org.glassfish.grizzly.http.server.ServerConfiguration) HttpServer(org.glassfish.grizzly.http.server.HttpServer) IOException(java.io.IOException) SpdyAddOn(org.glassfish.grizzly.spdy.SpdyAddOn) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener) ProcessingException(javax.ws.rs.ProcessingException)

Example 17 with NetworkListener

use of org.glassfish.grizzly.http.server.NetworkListener in project jaeger-client-java by jaegertracing.

the class JerseyServer method main.

public static void main(String[] args) throws Exception {
    BasicConfigurator.configure();
    String serviceName = serviceNameFromEnv();
    JerseyServer server = new JerseyServer("0.0.0.0:8081", serviceName, Arrays.asList(new TraceBehaviorResource(), new EndToEndBehaviorResource(new EndToEndBehavior(getEvn(SAMPLING_HOST_PORT, "jaeger-agent:5778"), "crossdock-" + serviceName, senderFromEnv(getEvn(COLLECTOR_HOST_PORT, "jaeger-collector:14268"), getEvn(AGENT_HOST, "jaeger-agent")))), new HealthResource()));
    server.addNetworkListener(new NetworkListener("health", "0.0.0.0", 8080));
    Builder tchannelBuilder = new Builder(serviceName);
    tchannelBuilder.setServerPort(8082);
    new TChannelServer(tchannelBuilder, new TraceBehavior(), server.getTracer()).start();
}
Also used : EndToEndBehavior(com.uber.jaeger.crossdock.resources.behavior.EndToEndBehavior) TraceBehavior(com.uber.jaeger.crossdock.resources.behavior.TraceBehavior) TraceBehaviorResource(com.uber.jaeger.crossdock.resources.behavior.http.TraceBehaviorResource) Builder(com.uber.tchannel.api.TChannel.Builder) ClientBuilder(javax.ws.rs.client.ClientBuilder) EndToEndBehaviorResource(com.uber.jaeger.crossdock.resources.behavior.http.EndToEndBehaviorResource) TChannelServer(com.uber.jaeger.crossdock.resources.behavior.tchannel.TChannelServer) HealthResource(com.uber.jaeger.crossdock.resources.health.HealthResource) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener)

Example 18 with NetworkListener

use of org.glassfish.grizzly.http.server.NetworkListener in project dukescript-presenters by dukescript.

the class DynamicHTTP method initServer.

static URI initServer() throws Exception {
    server = HttpServer.createSimpleServer(null, new PortRange(8080, 65535));
    final WebSocketAddOn addon = new WebSocketAddOn();
    for (NetworkListener listener : server.getListeners()) {
        listener.registerAddOn(addon);
    }
    resources = new ArrayList<Resource>();
    conf = server.getServerConfiguration();
    final DynamicHTTP dh = new DynamicHTTP();
    conf.addHttpHandler(dh, "/");
    server.start();
    return pageURL("http", server, "/test.html");
}
Also used : PortRange(org.glassfish.grizzly.PortRange) WebSocketAddOn(org.glassfish.grizzly.websockets.WebSocketAddOn) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener)

Example 19 with NetworkListener

use of org.glassfish.grizzly.http.server.NetworkListener in project dukescript-presenters by dukescript.

the class DynamicHTTP method pageURL.

private static URI pageURL(String proto, HttpServer server, final String page) {
    NetworkListener listener = server.getListeners().iterator().next();
    int port = listener.getPort();
    try {
        return new URI(proto + "://localhost:" + port + page);
    } catch (URISyntaxException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener)

Example 20 with NetworkListener

use of org.glassfish.grizzly.http.server.NetworkListener in project graylog2-server by Graylog2.

the class JerseyService method setUp.

private HttpServer setUp(URI listenUri, SSLEngineConfigurator sslEngineConfigurator, int threadPoolSize, int selectorRunnersCount, int maxHeaderSize, boolean enableGzip, boolean enableCors, Set<Resource> additionalResources) {
    final ResourceConfig resourceConfig = buildResourceConfig(enableCors, additionalResources);
    final HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(listenUri, resourceConfig, sslEngineConfigurator != null, sslEngineConfigurator, false);
    final NetworkListener listener = httpServer.getListener("grizzly");
    listener.setMaxHttpHeaderSize(maxHeaderSize);
    final ExecutorService workerThreadPoolExecutor = instrumentedExecutor("http-worker-executor", "http-worker-%d", threadPoolSize);
    listener.getTransport().setWorkerThreadPool(workerThreadPoolExecutor);
    // The Grizzly default value is equal to `Runtime.getRuntime().availableProcessors()` which doesn't make
    // sense for Graylog because we are not mainly a web server.
    // See "Selector runners count" at https://grizzly.java.net/bestpractices.html for details.
    listener.getTransport().setSelectorRunnersCount(selectorRunnersCount);
    listener.setDefaultErrorPageGenerator(errorPageGenerator);
    if (enableGzip) {
        final CompressionConfig compressionConfig = listener.getCompressionConfig();
        compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON);
        compressionConfig.setCompressionMinSize(512);
    }
    return httpServer;
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) InstrumentedExecutorService(com.codahale.metrics.InstrumentedExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener) CompressionConfig(org.glassfish.grizzly.http.CompressionConfig)

Aggregations

NetworkListener (org.glassfish.grizzly.http.server.NetworkListener)20 HttpServer (org.glassfish.grizzly.http.server.HttpServer)11 IOException (java.io.IOException)7 ProcessingException (javax.ws.rs.ProcessingException)5 ServerConfiguration (org.glassfish.grizzly.http.server.ServerConfiguration)5 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 CompressionConfig (org.glassfish.grizzly.http.CompressionConfig)3 CLStaticHttpHandler (org.glassfish.grizzly.http.server.CLStaticHttpHandler)3 SSLEngineConfigurator (org.glassfish.grizzly.ssl.SSLEngineConfigurator)3 GrizzlyHttpContainer (org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer)3 InstrumentedExecutorService (com.codahale.metrics.InstrumentedExecutorService)2 BindException (java.net.BindException)2 ExecutorService (java.util.concurrent.ExecutorService)2 PortRange (org.glassfish.grizzly.PortRange)2 TCPNIOTransport (org.glassfish.grizzly.nio.transport.TCPNIOTransport)2 SpdyAddOn (org.glassfish.grizzly.spdy.SpdyAddOn)2 ThreadPoolConfig (org.glassfish.grizzly.threadpool.ThreadPoolConfig)2 WebSocketAddOn (org.glassfish.grizzly.websockets.WebSocketAddOn)2 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)2