Search in sources :

Example 1 with LogExceptionRunnable

use of io.grpc.internal.LogExceptionRunnable in project grpc-java by grpc.

the class MaxConnectionIdleManager method start.

@VisibleForTesting
void start(final ChannelHandlerContext ctx, final ScheduledExecutorService scheduler) {
    this.scheduler = scheduler;
    nextIdleMonitorTime = ticker.nanoTime() + maxConnectionIdleInNanos;
    shutdownTask = new LogExceptionRunnable(new Runnable() {

        @Override
        public void run() {
            if (shutdownDelayed) {
                if (!isActive) {
                    // delay shutdown
                    shutdownFuture = scheduler.schedule(shutdownTask, nextIdleMonitorTime - ticker.nanoTime(), TimeUnit.NANOSECONDS);
                    shutdownDelayed = false;
                }
            // if isActive, exit. Will schedule a new shutdownFuture once onTransportIdle
            } else {
                close(ctx);
                shutdownFuture = null;
            }
        }
    });
    shutdownFuture = scheduler.schedule(shutdownTask, maxConnectionIdleInNanos, TimeUnit.NANOSECONDS);
}
Also used : LogExceptionRunnable(io.grpc.internal.LogExceptionRunnable) LogExceptionRunnable(io.grpc.internal.LogExceptionRunnable) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with LogExceptionRunnable

use of io.grpc.internal.LogExceptionRunnable in project grpc-java by grpc.

the class NettyServerHandler method handlerAdded.

@Override
public void handlerAdded(final ChannelHandlerContext ctx) throws Exception {
    serverWriteQueue = new WriteQueue(ctx.channel());
    // init max connection age monitor
    if (maxConnectionAgeInNanos != MAX_CONNECTION_AGE_NANOS_DISABLED) {
        maxConnectionAgeMonitor = ctx.executor().schedule(new LogExceptionRunnable(new Runnable() {

            @Override
            public void run() {
                if (gracefulShutdown == null) {
                    gracefulShutdown = new GracefulShutdown("max_age", maxConnectionAgeGraceInNanos);
                    gracefulShutdown.start(ctx);
                    ctx.flush();
                }
            }
        }), maxConnectionAgeInNanos, TimeUnit.NANOSECONDS);
    }
    if (maxConnectionIdleManager != null) {
        maxConnectionIdleManager.start(ctx);
    }
    if (keepAliveTimeInNanos != SERVER_KEEPALIVE_TIME_NANOS_DISABLED) {
        keepAliveManager = new KeepAliveManager(new KeepAlivePinger(ctx), ctx.executor(), keepAliveTimeInNanos, keepAliveTimeoutInNanos, true);
        keepAliveManager.onTransportStarted();
    }
    assert encoder().connection().equals(decoder().connection());
    transportTracer.setFlowControlWindowReader(new Utils.FlowControlReader(encoder().connection()));
    super.handlerAdded(ctx);
}
Also used : LogExceptionRunnable(io.grpc.internal.LogExceptionRunnable) LogExceptionRunnable(io.grpc.internal.LogExceptionRunnable) KeepAliveManager(io.grpc.internal.KeepAliveManager)

Aggregations

LogExceptionRunnable (io.grpc.internal.LogExceptionRunnable)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 KeepAliveManager (io.grpc.internal.KeepAliveManager)1