private Integer getTimeout() { Integer timeout = 0; try { timeout = connection.getSourceChannel().getOption(Options.READ_TIMEOUT); } catch (IOException ignore) { // should never happen } Integer idleTimeout = openListener.getUndertowOptions().get(UndertowOptions.IDLE_TIMEOUT); if ((timeout == null || timeout <= 0) && idleTimeout != null) { timeout = idleTimeout; } else if (timeout != null && idleTimeout != null && idleTimeout > 0) { timeout = Math.min(timeout, idleTimeout); } return timeout; }
@Override public void start(StartContext context) throws StartException { preStart(context); serverService.getValue().registerListener(this); try { final InetSocketAddress socketAddress = binding.getValue().getSocketAddress(); openListener = createOpenListener(); final ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(openListener); HttpHandler handler = serverService.getValue().getRoot(); for (HandlerWrapper wrapper : listenerHandlerWrappers) { handler = wrapper.wrap(handler); } openListener.setRootHandler(handler); startListening(worker.getValue(), socketAddress, acceptListener); registerBinding(); } catch (IOException e) { throw new StartException("Could not start http listener", e); } }
public synchronized void start() { xnio = Xnio.getInstance(Undertow.class.getClassLoader()); channels = new ArrayList<AcceptingChannel<? extends StreamConnection>>(); try { worker = xnio.createWorker( OptionMap.builder() .set(Options.WORKER_IO_THREADS, ioThreads) .set(Options.CONNECTION_HIGH_WATER, 1000000) .set(Options.CONNECTION_LOW_WATER, 1000000) .set(Options.WORKER_TASK_CORE_THREADS, workerThreads) .set(Options.WORKER_TASK_MAX_THREADS, workerThreads) .set(Options.TCP_NODELAY, true) .set(Options.CORK, true) .addAll(workerOptions) .getMap()); OptionMap socketOptions = OptionMap.builder() .set(Options.WORKER_IO_THREADS, ioThreads) .set(Options.TCP_NODELAY, true) .set(Options.REUSE_ADDRESSES, true) .set(Options.BALANCING_TOKENS, 1) .set(Options.BALANCING_CONNECTIONS, 2) .addAll(this.socketOptions) .getMap(); Pool<ByteBuffer> buffers = new ByteBufferSlicePool( directBuffers ? BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR : BufferAllocator.BYTE_BUFFER_ALLOCATOR, bufferSize, bufferSize * buffersPerRegion); for (ListenerConfig listener : listeners) { if (listener.type == ListenerType.AJP) { AjpOpenListener openListener = new AjpOpenListener(buffers, serverOptions, bufferSize); openListener.setRootHandler(rootHandler); ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(openListener); AcceptingChannel<? extends StreamConnection> server = worker.createStreamConnectionServer( new InetSocketAddress(Inet4Address.getByName(listener.host), listener.port), acceptListener, socketOptions); server.resumeAccepts(); channels.add(server); } else { OptionMap undertowOptions = OptionMap.builder() .set(UndertowOptions.BUFFER_PIPELINED_DATA, true) .addAll(serverOptions) .getMap(); if (listener.type == ListenerType.HTTP) { HttpOpenListener openListener = new HttpOpenListener(buffers, undertowOptions, bufferSize); openListener.setRootHandler(rootHandler); ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(openListener); AcceptingChannel<? extends StreamConnection> server = worker.createStreamConnectionServer( new InetSocketAddress(Inet4Address.getByName(listener.host), listener.port), acceptListener, socketOptions); server.resumeAccepts(); channels.add(server); } else if (listener.type == ListenerType.HTTPS) { OpenListener openListener = new HttpOpenListener(buffers, undertowOptions, bufferSize); if (serverOptions.get(UndertowOptions.ENABLE_SPDY, false)) { openListener = new SpdyOpenListener( buffers, new ByteBufferSlicePool(BufferAllocator.BYTE_BUFFER_ALLOCATOR, 1024, 1024), undertowOptions, bufferSize, (HttpOpenListener) openListener); } openListener.setRootHandler(rootHandler); ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(openListener); XnioSsl xnioSsl; if (listener.sslContext != null) { xnioSsl = new JsseXnioSsl( xnio, OptionMap.create(Options.USE_DIRECT_BUFFERS, true), listener.sslContext); } else { xnioSsl = xnio.getSslProvider( listener.keyManagers, listener.trustManagers, OptionMap.create(Options.USE_DIRECT_BUFFERS, true)); } AcceptingChannel<SslConnection> sslServer = xnioSsl.createSslConnectionServer( worker, new InetSocketAddress(Inet4Address.getByName(listener.host), listener.port), (ChannelListener) acceptListener, socketOptions); sslServer.resumeAccepts(); channels.add(sslServer); } } } } catch (Exception e) { throw new RuntimeException(e); } }