public HttpServerExchange dispatch(final Executor executor, final HttpHandler handler) { final Runnable runnable = new Runnable() { @Override public void run() { Connectors.executeRootHandler(handler, HttpServerExchange.this); } }; dispatch(executor, runnable); return this; }
@Override public void handleException(Channel channel, final IOException e) { exchange.dispatch(new HttpHandler() { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { callback.onException(exchange, null, e); } }); } }));
public HttpServerExchange dispatch(final HttpHandler handler) { dispatch(null, handler); return this; }
@Override public void onComplete(final HttpServerExchange exchange, final Sender sender) { exchange.dispatch(next); }
/** * Dispatches this request to the XNIO worker thread pool. Once the call stack returns * the given runnable will be submitted to the executor. * <p> * In general handlers should first check the value of {@link #isInIoThread()} before * calling this method, and only dispatch if the request is actually running in the IO * thread. * * @param runnable The task to run * @throws IllegalStateException If this exchange has already been dispatched */ public HttpServerExchange dispatch(final Runnable runnable) { dispatch(null, runnable); return this; }
@Override public void startAsync(final Executor executor, final Runnable runnable) { exchange.dispatch(executor, runnable); }
public synchronized void open() { open = true; for(Holder holder : held) { holder.exchange.dispatch(holder.next); } held.clear(); }
@Override public void run() { synchronized (GateHandlerWrapper.this) { if(open) { exchange.dispatch(next); } else { held.add(new Holder(next, exchange)); } } } });
@Override public void handleEvent(StreamSinkChannel channel) { channel.suspendWrites(); exchange.dispatch(new HttpHandler() { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { callback.onComplete(exchange, null); } }); } }, new ChannelExceptionHandler<Channel>() {
@Override public void exchangeEvent(final HttpServerExchange exchange, final NextListener nextListener) { try { synchronized (RequestLimit.this) { final SuspendedRequest task = queue.poll(); if (task != null) { task.exchange.addExchangeCompleteListener(COMPLETION_LISTENER); task.exchange.dispatch(task.next); } else { decrementRequests(); } } } finally { nextListener.proceed(); } } };
@Override public void onComplete(final HttpServerExchange exchange, final Sender sender) { if (exchange.isInIoThread()) { exchange.dispatch(this); } else { run(); } }
@Override public final void handleRequest(HttpServerExchange exchange) throws Exception { if (exchange.isInIoThread()) { if (executorService == null) { exchange.dispatch(this); } else { exchange.putAttachment(EXECUTOR, executorService); exchange.dispatch(executorService, this); } return; } else if (executorService != null && exchange.getAttachment(EXECUTOR) == null) { exchange.putAttachment(EXECUTOR, executorService); exchange.dispatch(executorService, this); return; } exchange.startBlocking(); handleInternal(exchange); }
@Override public void completed(final HttpServerExchange exchange, final ProxyConnection connection) { exchange.putAttachment(CONNECTION, connection); exchange.dispatch(SameThreadExecutor.INSTANCE, new ProxyAction(connection, exchange, requestHeaders, rewriteHostHeader, reuseXForwarded, exchange.isRequestComplete() ? this : null, idempotentPredicate)); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.startBlocking(); if (exchange.isInIoThread()) { exchange.dispatch(handler); } else { handler.handleRequest(exchange); } }
@Override public void handleEvent(StreamSinkChannel channel) { channel.suspendWrites(); channel.getWriteSetter().set(null); exchange.dispatch(this); }
@Override public void handleEvent(final StreamSourceChannel channel) { try { doParse(channel); if (state == 4) { exchange.dispatch(SameThreadExecutor.INSTANCE, handler); } } catch (IOException e) { IoUtils.safeClose(channel); UndertowLogger.REQUEST_IO_LOGGER.ioExceptionReadingFromChannel(e); exchange.endExchange(); } }
@Override protected void handshake(final Runnable handler) throws Exception { exchange.getResponseHeaders() .put(Headers.CONNECTION, "Close") .put(Headers.CONTENT_TYPE, "text/event-stream; charset=utf-8"); exchange.setStatusCode(200) .setPersistent(false); exchange.dispatch(handler); }
/** * Try to open a socket connection to given address. * * @param address the socket address * @param exchange the http servers exchange * @param callback the ping callback * @param options the options */ static void pingHost(InetSocketAddress address, HttpServerExchange exchange, PingCallback callback, OptionMap options) { final XnioIoThread thread = exchange.getIoThread(); final XnioWorker worker = thread.getWorker(); final HostPingTask r = new HostPingTask(address, worker, callback, options); // Schedule timeout task scheduleCancelTask(exchange.getIoThread(), r, 5, TimeUnit.SECONDS); exchange.dispatch(exchange.isInIoThread() ? SameThreadExecutor.INSTANCE : thread, r); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (exchange.isInIoThread()) { HeaderValues upgrade = exchange.getRequestHeaders().get(Headers.UPGRADE); if (upgrade != null && upgrade.contains("h2c")) { // reset protocol exchange.setProtocol(Protocols.HTTP_1_1); } exchange.dispatch(this); return; } handler.handle(new UndertowRequest(exchange, config), new UndertowResponse(exchange)); }
/** * Try to ping a server using the undertow client. * * @param connection the connection URI * @param callback the ping callback * @param exchange the http servers exchange * @param client the undertow client * @param xnioSsl the ssl setup * @param options the options */ static void pingHttpClient(URI connection, PingCallback callback, HttpServerExchange exchange, UndertowClient client, XnioSsl xnioSsl, OptionMap options) { final XnioIoThread thread = exchange.getIoThread(); final RequestExchangeListener exchangeListener = new RequestExchangeListener(callback, NodeHealthChecker.NO_CHECK, true); final Runnable r = new HttpClientPingTask(connection, exchangeListener, thread, client, xnioSsl, exchange.getConnection().getByteBufferPool(), options); exchange.dispatch(exchange.isInIoThread() ? SameThreadExecutor.INSTANCE : thread, r); // Schedule timeout task scheduleCancelTask(exchange.getIoThread(), exchangeListener, 5, TimeUnit.SECONDS); }