Example usage for io.netty.channel EventLoopGroup scheduleAtFixedRate

List of usage examples for io.netty.channel EventLoopGroup scheduleAtFixedRate

Introduction

In this page you can find the example usage for io.netty.channel EventLoopGroup scheduleAtFixedRate.

Prototype

@Override
    ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit);

Source Link

Usage

From source file:com.linecorp.armeria.server.Server.java

License:Apache License

private void stop0(CompletableFuture<Void> future) {
    assert future != null;

    final EventLoopGroup bossGroup = this.bossGroup;
    final GracefulShutdownHandler gracefulShutdownHandler = this.gracefulShutdownHandler;

    if (gracefulShutdownHandler == null) {
        stop1(future, bossGroup);//from w  w w  . j  a  v  a 2  s. c  o m
        return;
    }

    // Check every 100 ms for the server to have completed processing
    // requests.
    bossGroup.scheduleAtFixedRate(() -> {
        if (gracefulShutdownHandler.completedQuietPeriod()) {
            stop1(future, bossGroup);
        }
    }, 0, 100, TimeUnit.MILLISECONDS);

    // Make sure the event loop stops after the timeout, regardless of what
    // the GracefulShutdownHandler says.
    bossGroup.schedule(() -> stop1(future, bossGroup), config.gracefulShutdownTimeout().toMillis(),
            TimeUnit.MILLISECONDS);
}

From source file:com.siondream.superjumper.net.SecureChatServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup(1);
    try {//from  w w  w  . j a v  a 2  s  . c  om
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new SecureChatServerInitializer());
        workerGroup.scheduleAtFixedRate(new ServerNetOptLoop(), 100000000, 100000000, TimeUnit.NANOSECONDS);
        b.bind(PORT).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:eu.matejkormuth.pexel.network.NettyClientComunicator.java

License:Open Source License

private void init(final int port, final String host, final String thisSlaveName, final String authKey)
        throws InterruptedException, SSLException {
    this.log.info("Setting up SSL...");
    // Configure SSL.
    final SslContext sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);

    EventLoopGroup group = new NioEventLoopGroup();
    try {/*w w  w  . j a  v a 2 s.co m*/
        this.b = new Bootstrap();
        this.b.group(group).channel(NioSocketChannel.class)
                .handler(new NettyClientComunicatorInitializer(sslCtx, port, host));

        group.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                NettyClientComunicator.this.sendQueue();
            }
        }, 0L, 10L, TimeUnit.MILLISECONDS);

        this.log.info("Connecting to master...");
        // Start the connection attempt.
        this.channelToMaster = this.b.connect(host, port).sync().channel();

        // Log in.
        this.channelToMaster
                .writeAndFlush(new NettyMessage(NettyRegisterMesssage.create(authKey, thisSlaveName)));

    } finally {
        // The connection is closed automatically on shutdown.
        this.log.info("Shutting down..");
        group.shutdownGracefully();
    }
}

From source file:eu.matejkormuth.pexel.network.NettyServerComunicator.java

License:Open Source License

public void init(final int port) throws SSLException, CertificateException, InterruptedException {
    this.log.info("Initializing SSL...");
    SelfSignedCertificate ssc = new SelfSignedCertificate("pexel.eu");
    SslContext sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/*from   w ww.  j a v  a2  s .  c  om*/
        this.log.info("Starting up server...");
        this.b = new ServerBootstrap();
        this.b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new NettyServerComunicatorInitializer(sslCtx));

        workerGroup.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                NettyServerComunicator.this.sendQueues();
            }
        }, 0L, 10L, TimeUnit.MILLISECONDS);

        this.b.bind(port).sync().channel().closeFuture().sync();
    } finally {
        this.log.info("Stopping server...");
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:org.anhonesteffort.chnlbrkr.BrkrList.java

License:Open Source License

public BrkrList(ChnlBrkrConfig config, HostId.Reader hostId, EventLoopGroup workerGroup,
        Optional<RedisClient> redisClient) {
    this.hostId = hostId;

    if (redisClient.isPresent()) {
        expiringSet = Optional.of(new ExpiringRedisSet(config, redisClient.get().connect().async()));

        workerGroup.scheduleAtFixedRate(() -> expiringSet.get().removeExpiredMembers(), 0l,
                config.brokerCacheExpireIntervalMs(), TimeUnit.MILLISECONDS);

        workerGroup.scheduleAtFixedRate(() -> expiringSet.get().addBrkr(hostId), 0l,
                config.brokerCacheUpdateIntervalMs(), TimeUnit.MILLISECONDS);
    } else {/*w  w w.j a  v a  2  s .  com*/
        expiringSet = Optional.empty();
    }
}