protected Builder(String serviceName) { this.serviceName = serviceName; bossThreadPoolSize = DEFAULT_BOSS_THREAD_POOL_SIZE; workerThreadPoolSize = DEFAULT_WORKER_THREAD_POOL_SIZE; execThreadPoolSize = DEFAULT_EXEC_HANDLER_THREAD_POOL_SIZE; execThreadKeepAliveSecs = DEFAULT_EXEC_HANDLER_THREAD_KEEP_ALIVE_TIME_SECS; rejectedExecutionHandler = DEFAULT_REJECTED_EXECUTION_HANDLER; httpChunkLimit = DEFAULT_HTTP_CHUNK_LIMIT; port = 0; channelConfigs = new HashMap<>(); childChannelConfigs = new HashMap<>(); channelConfigs.put(ChannelOption.SO_BACKLOG, DEFAULT_CONNECTION_BACKLOG); sslHandlerFactory = null; exceptionHandler = new ExceptionHandler(); }
/** * Calls the httpHandler method. */ void invoke(HttpRequest request) throws Exception { bodyConsumer = null; Object invokeResult; try { args[0] = this.request = request; invokeResult = method.invoke(handler, args); } catch (InvocationTargetException e) { exceptionHandler.handle(e.getTargetException(), request, responder); return; } catch (Throwable t) { exceptionHandler.handle(t, request, responder); return; } if (isStreaming) { // Casting guarantee to be succeeded. bodyConsumer = (BodyConsumer) invokeResult; } }
/** * Calls {@link BodyConsumer#finished(HttpResponder)} method. The current bodyConsumer will be set to {@code null} * after the call. */ private void bodyConsumerFinish() { BodyConsumer consumer = bodyConsumer; bodyConsumer = null; try { consumer.finished(responder); } catch (Throwable t) { exceptionHandler.handle(t, request, responder); } }
/** * Calls the {@link BodyConsumer#chunk(ByteBuf, HttpResponder)} method. If the chunk method call * throws exception, the {@link BodyConsumer#handleError(Throwable)} will be called and this method will * throw {@link HandlerException}. */ private void bodyConsumerChunk(ByteBuf buffer) throws HandlerException { try { bodyConsumer.chunk(buffer, responder); } catch (Throwable t) { try { bodyConsumerError(t); } catch (Throwable t2) { exceptionHandler.handle(t2, request, responder); // log original throwable since we'll lose it otherwise LOG.debug("Handled exception thrown from handleError. original exception from chunk call was:", t); return; } exceptionHandler.handle(t, request, responder); } }