Example usage for io.netty.handler.logging LogLevel INFO

List of usage examples for io.netty.handler.logging LogLevel INFO

Introduction

In this page you can find the example usage for io.netty.handler.logging LogLevel INFO.

Prototype

LogLevel INFO

To view the source code for io.netty.handler.logging LogLevel INFO.

Click Source Link

Usage

From source file:de.jpaw.bonaparte.netty.testServer.SslServer.java

License:Apache License

public void run() throws Exception {
    // Configure the server.
    ServerBootstrap b = new ServerBootstrap();
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/*from  w ww. j  a v a2s  . c  om*/
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100).localAddress(new InetSocketAddress(port))
                .childOption(ChannelOption.TCP_NODELAY, true).handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new BonaparteNettySslPipelineFactory(1000, new TestServerHandler(), useSsl, false,
                        requirePeerAuthentication, null));

        // Start the server.
        ChannelFuture f = b.bind().sync();

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:de.jpaw.bonaparte.netty.testServer.TestServer.java

License:Apache License

public void run() throws Exception {
    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(3);
    EventLoopGroup workerGroup = new NioEventLoopGroup(6);
    try {/*  w w  w  .  java  2  s  .c  o  m*/
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100).localAddress(new InetSocketAddress(port))
                .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new BonaparteNettyPipelineFactory(1000, new TestServerHandler(), null, 1));

        // Start the server.
        ChannelFuture f = b.bind().sync();

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } catch (Exception e) {
        System.out.println("Exception " + e + " occured");
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:demo.netty.discard.DiscardServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {//  w w  w .j av a  2 s  .  co  m
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;
    }

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {

                    @Override
                    public void initChannel(SocketChannel ch) {
                        ChannelPipeline p = ch.pipeline();
                        if (sslCtx != null) {
                            p.addLast(sslCtx.newHandler(ch.alloc()));
                        }
                        p.addLast(new DiscardServerHandler());
                    }
                });

        // Bind and start to accept incoming connections.
        ChannelFuture f = b.bind(PORT).sync();

        // Wait until the server socket is closed.
        // In this example, this does not happen, but you can do that to gracefully
        // shut down your server.
        f.channel().closeFuture().sync();
    } finally {
        workerGroup.shutdownGracefully();
        bossGroup.shutdownGracefully();
    }
}

From source file:dpfmanager.shell.modules.server.core.HttpServer.java

License:Open Source License

public void start() throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {/*from w  ww  .  j  av  a2 s.com*/
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;
    }

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup);
        b.channel(NioServerSocketChannel.class);
        b.handler(new LoggingHandler(LogLevel.INFO));
        b.childHandler(new HttpServerInitializer(sslCtx, context));

        Channel ch = b.bind(PORT).sync().channel();

        context.send(BasicConfig.MODULE_MESSAGE, new LogMessage(getClass(), Level.DEBUG,
                DPFManagerProperties.getBundle().getString("startedServer").replace("%1", getServerUri()),
                true));

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:edu.upennlib.redirect.Redirect.java

License:Apache License

@Override
public void run() {
    // Configure the bootstrap.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/*ww w. ja  v a  2 s  . co m*/
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new RedirectInitializer(validHosts, redirectPrefix))
                .childOption(ChannelOption.AUTO_READ, true).bind(listenInterface, listenPort).sync().channel()
                .closeFuture().sync();
    } catch (InterruptedException ex) {
        throw new RuntimeException(ex);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:edumsg.netty.EduMsgNettyServer.java

License:Open Source License

public static void main(String[] args) throws Exception {
    Logger log = Logger.getLogger(EduMsgNettyServer.class);
    // Configure SSL.
    EduMsgRedis.redisCache.flushDB();//from  w w w  .  j a va  2  s .  c  o m
    //        EduMsgRedis.bgSave();
    final SslContext sslCtx;
    if (SSL) {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;
    }

    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new EduMsgNettyServerInitializer(sslCtx));
        //            b.option(ChannelOption.SO_KEEPALIVE, true);
        Channel ch = b.bind(PORT).sync().channel();

        System.err.println("Server is listening on " + (SSL ? "https" : "http") + "://127.0.0.1:" + PORT + '/');

        ch.closeFuture().sync();
    } finally {
        //            bossGroup.shutdownGracefully();
        //            workerGroup.shutdownGracefully();
    }
}

From source file:enetty.HexDumpProxyInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new HttpServerCodec(),
            new HexDumpProxyFrontendHandler(remoteHost, remotePort));
}

From source file:errorcode.DaumStatusServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {// www  .  j  a v a2s .  c o m
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
    } else {
        sslCtx = null;
    }

    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new DaumStatusServerInitializer(sslCtx));

        Channel ch = b.bind(PORT).sync().channel();

        System.err.println("Open your web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:"
                + PORT + '/');

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:esens.wp6.ibmJmsBackend.log4http.HttpLogServer.java

License:Apache License

public static void start() throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {//from   w w w  . j a v  a  2 s.  c  o m
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
    } else {
        sslCtx = null;
    }

    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {

        LOGGER.debug("HTTP LOG PORT: " + PORT);
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new HttpLogServerInitializer(sslCtx));

        b.bind(PORT);//.sync().channel();
        //ch.closeFuture().sync();
    } catch (Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
    } finally {
        //bossGroup.shutdownGracefully();
        //workerGroup.shutdownGracefully();
    }
}

From source file:eu.jangos.realm.RealmServer.java

License:Apache License

/**
 * Main of the RealmServer program.//  www  . j  av  a  2s . c o  m
 *
 * @param args the command line arguments
 * @throws InterruptedException in case of interruption of the running
 * process.
 */
public static void main(String[] args) throws InterruptedException {

    logger.info("Starting JaNGOS realm server version " + VERSION + ".");
    logger.info("JaNGOS is an opensource project, check-out : https://github.com/Warkdev/JaNGOSRealm !");

    realm.setOffline(false);
    rs.save(realm);

    logger.info("Realm configuration: ");
    logger.info("Name: " + realm.getName());
    logger.info("Address: " + realm.getAddress() + ":" + realm.getPort());
    logger.info("Type: " + realm.getRealmtype().getType());
    logger.info("Timezone: " + realm.getRealmtimezone().getName());
    logger.info("Population: " + realm.getPopulation());
    logger.info("Players: " + realm.getCountPlayers() + "/" + realm.getMaxPlayers());

    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();

        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100).option(ChannelOption.TCP_NODELAY, true)
                .option(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.SO_REUSEADDR, true)
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 100).handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        p.addLast(new RealmPacketDecoder(), new RealmPacketEncoder(), new RealmAuthHandler(),
                                new ReadTimeoutHandler(TIMEOUT), new CharacterHandler());
                    }
                });

        ChannelFuture f;

        // Start the server.   
        try {
            HOST = InetAddress.getByAddress(realm.getAddress().getBytes());
            f = b.bind(HOST, PORT).sync();
            logger.info("JaNGOS realm server started listening on " + HOST.getHostAddress() + ":" + PORT);
        } catch (UnknownHostException ex) {
            f = b.bind(PORT);
            logger.info("JaNGOS realm server started listening on port " + PORT);
        }

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } finally {
        logger.info("JaNGOS realm server shutting down.");

        // Indicating that this realm is offline.
        realm.setOffline(true);
        rs.save(realm);

        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}