Example usage for io.netty.util.concurrent EventExecutorGroup shutdownGracefully

List of usage examples for io.netty.util.concurrent EventExecutorGroup shutdownGracefully

Introduction

In this page you can find the example usage for io.netty.util.concurrent EventExecutorGroup shutdownGracefully.

Prototype

Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit);

Source Link

Document

Signals this executor that the caller wants the executor to be shut down.

Usage

From source file:com.lambdaworks.redis.resource.DefaultEventLoopGroupProvider.java

License:Apache License

@Override
public Promise<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout,
        TimeUnit unit) {//from   ww  w. j  av  a 2 s.c  o m

    Class<?> key = getKey(release(eventLoopGroup));

    if ((key == null && eventLoopGroup.isShuttingDown()) || refCounter.containsKey(eventLoopGroup)) {
        DefaultPromise<Boolean> promise = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);
        promise.setSuccess(true);
        return promise;
    }

    if (key != null) {
        eventLoopGroups.remove(key);
    }

    Future<?> shutdownFuture = eventLoopGroup.shutdownGracefully(quietPeriod, timeout, unit);
    return toBooleanPromise(shutdownFuture);
}

From source file:io.hekate.network.netty.NettyUtils.java

License:Apache License

/**
 * {@link EventExecutorGroup#shutdownGracefully(long, long, TimeUnit) Shuts down} the specified executor with {@code 0} graceful
 * shutdown period./*from  ww w . ja  va  2 s.  c  o m*/
 *
 * @param executor Executor to shutdown (can be {@code null}).
 *
 * @return Waiting.
 */
public static Waiting shutdown(EventExecutorGroup executor) {
    if (executor == null) {
        return Waiting.NO_WAIT;
    } else {
        return executor.shutdownGracefully(0, Long.MAX_VALUE, TimeUnit.MILLISECONDS)::await;
    }
}

From source file:io.hekate.network.netty.NettyUtilsTest.java

License:Apache License

@Test
public void testShutdown() throws Exception {
    assertSame(Waiting.NO_WAIT, NettyUtils.shutdown(null));

    EventExecutorGroup mock = mock(EventExecutorGroup.class);

    when(mock.shutdownGracefully(anyLong(), anyLong(), any())).thenReturn(genericMock(Future.class));

    NettyUtils.shutdown(mock);/*  w  ww. j a v a2 s  .  c  o m*/

    verify(mock).shutdownGracefully(eq(0L), eq(Long.MAX_VALUE), same(TimeUnit.MILLISECONDS));
}

From source file:io.lettuce.core.resource.DefaultEventLoopGroupProvider.java

License:Apache License

@Override
public Promise<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout,
        TimeUnit unit) {// ww w .j  av a 2 s .  c  om

    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);
}

From source file:org.robotninjas.barge.rpc.netty.NettyRaftService.java

License:Apache License

public static Closeable makeCloseable(EventExecutorGroup eventLoopGroup) {
    return new Closeable() {
        @Override/*from www  . j a va  2s.c  o  m*/
        public void close() throws IOException {
            try {
                Future<?> future = eventLoopGroup.shutdownGracefully(1, 1, TimeUnit.SECONDS);
                future.await();
            } catch (Exception e) {
                throw new IOException("Error shutting down netty event loop", e);
            }
        }
    };
}