@Override public Future<?> shutdownGracefully() { return group.shutdownGracefully(); }
@Override public EventExecutor next() { return newExecutor(group.next()); }
@Override public <T> Future<T> submit(Runnable task, T result) { return group.submit(task, result); }
/** * Check if the {@link EventExecutorGroup} is active * * @return false if the worker pool is terminating, shutdown or terminated */ private boolean isEventLoopActive() { EventExecutorGroup eventExecutors = clientResources.eventExecutorGroup(); if (eventExecutors.isShuttingDown() || eventExecutors.isShutdown() || eventExecutors.isTerminated()) { return false; } return true; }
/** * Shutdown executor in order. * * @param iterator Executors to shutdown. */ private void shutdownGracefully(final Iterator<EventExecutorGroup> iterator) { if (iterator.hasNext()) { EventExecutorGroup group = iterator.next(); if (!group.isShuttingDown()) { group.shutdownGracefully().addListener(future -> { if (!future.isSuccess()) { log.debug("shutdown of {} resulted in exception", group, future.cause()); } shutdownGracefully(iterator); }); } } }
@Override public boolean isShuttingDown() { return group.isShuttingDown(); }
void processMessage(String channel, String message, Supplier<Runnable> runnableSupplier) { if (!processingAllowed(channel, message)) { return; } timedSemaphore.onEvent(timeout -> { Runnable runnable = runnableSupplier.get(); if (timeout == null) { eventExecutors.submit(runnable); } else { eventExecutors.schedule(runnable, timeout.remaining(), TimeUnit.MILLISECONDS); } }); }
@Override public Future<?> terminationFuture() { return group.terminationFuture(); }
@Override public Iterator<EventExecutor> iterator() { final Iterator<EventExecutor> itr = group.iterator(); return new Iterator<EventExecutor>() { @Override public boolean hasNext() { return itr.hasNext(); } @Override public EventExecutor next() { return newExecutor(itr.next()); } @Override public void remove() { itr.remove(); } }; }
static void pingBeforeActivate(AsyncCommand<?, ?, ?> cmd, CompletableFuture<Boolean> initializedFuture, ChannelHandlerContext ctx, ClientResources clientResources, Duration timeout) throws Exception { ctx.fireUserEventTriggered(new PingBeforeActivate(cmd)); Runnable timeoutGuard = () -> { if (cmd.isDone() || initializedFuture.isDone()) { return; } initializedFuture.completeExceptionally(ExceptionFactory.createTimeoutException( "Cannot initialize channel (PING before activate)", timeout)); }; Timeout timeoutHandle = clientResources.timer().newTimeout(t -> { if (clientResources.eventExecutorGroup().isShuttingDown()) { timeoutGuard.run(); return; } clientResources.eventExecutorGroup().submit(timeoutGuard); }, timeout.toNanos(), TimeUnit.NANOSECONDS); cmd.whenComplete((o, throwable) -> { timeoutHandle.cancel(); if (throwable == null) { ctx.fireChannelActive(); initializedFuture.complete(true); } else { initializedFuture.completeExceptionally(throwable); } }); }
@Override public void execute(Runnable command) { group.execute(command); }
@Override public boolean isShutdown() { return group.isShutdown(); }
@Override public boolean isTerminated() { return group.isTerminated(); }
@Override public Promise<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit) { logger.debug("Release executor {}", eventLoopGroup); Class<?> key = getKey(release(eventLoopGroup)); if ((key == null && eventLoopGroup.isShuttingDown()) || refCounter.containsKey(eventLoopGroup)) { DefaultPromise<Boolean> promise = new DefaultPromise<Boolean>(GlobalEventExecutor.INSTANCE); promise.setSuccess(true); return promise; } if (key != null) { eventLoopGroups.remove(key); } Future<?> shutdownFuture = eventLoopGroup.shutdownGracefully(quietPeriod, timeout, unit); return toBooleanPromise(shutdownFuture); }
/** * Check if the {@link EventExecutorGroup} is active * * @return false if the worker pool is terminating, shutdown or terminated */ protected boolean isEventLoopActive() { EventExecutorGroup eventExecutors = clientResources.eventExecutorGroup(); if (eventExecutors.isShuttingDown() || eventExecutors.isShutdown() || eventExecutors.isTerminated()) { return false; } return true; }
@Override public boolean isShuttingDown() { return group.isShuttingDown(); }
@Override public Future<?> terminationFuture() { return group.terminationFuture(); }
@Override public Iterator<EventExecutor> iterator() { final Iterator<EventExecutor> itr = group.iterator(); return new Iterator<EventExecutor>() { @Override public boolean hasNext() { return itr.hasNext(); } @Override public EventExecutor next() { return newExecutor(itr.next()); } @Override public void remove() { itr.remove(); } }; }
@Override public void execute(Runnable command) { group.execute(command); }
@Override public boolean isShutdown() { return group.isShutdown(); }