List of usage examples for io.netty.handler.logging LogLevel INFO
LogLevel INFO
To view the source code for io.netty.handler.logging LogLevel INFO.
Click Source Link
From source file:com.fsocks.SocksServer.java
License:Apache License
public static void main(String[] args) throws Exception { Properties properties = new Properties(); try {//from w w w . ja v a2s. c o m properties.load(SocksServer.class.getResourceAsStream("/config.properties")); PORT = Integer.parseInt(properties.getProperty("port")); } catch (Exception e) { logger.warn("load config.properties error, default port 11080, auth false!"); } EventLoopGroup bossGroup = new NioEventLoopGroup(16); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new SocksServerInitializer()); b.bind(PORT).sync().channel().closeFuture().sync(); } catch (Exception e) { logger.error("SocksServer server error,", e); } finally { logger.error("SocksServer is shutdown"); bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.galaxy.netty.http.HttpStaticFileServer.java
License:Apache License
public static void main(String[] args) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from ww w. ja va2 s . co m ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new HttpStaticFileServerInitializer()); 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:com.gdut.Netty_testing.dongjun.server.ElectricControlServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {// w w w . j a va2s . c om 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 ElectricControlServerInitializer(sslCtx)); b.bind(PORT).sync().channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.gdut.Netty_testing.time_server.client.TimeClient.java
License:Apache License
/** * /* w w w . j a v a 2 s .c o m*/ * @Title: main * @Description: TODO * @param @param args * @param @throws Exception * @return void * @throws */ public static void main(String[] args) throws Exception { // Configure SSL.git final SslContext sslCtx; if (SSL) { sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); } else { sslCtx = null; } // Configure the client. EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new TimeDecoder(), new TimeClientHandler(), new TimeOutBoundHandler(), new LoggingHandler(LogLevel.INFO)); } }); // Start the client. ChannelFuture f = b.connect(HOST, PORT).sync(); // channel.connect(remoteAddress, promise); // ?connect()??OutboundHandler // ?InboundHandlerlogic??? // ?? // InboundHandler?writeAndFlush(Object // msg)??OutBoundHandler // ?? ctx.write(encoded, promise); // writeAndFlush(Object msg) // ?InboundHandler decoder? // ?TimeClientHandler()Handler, // ctx.close();?OutBoundHandler ? Thread.sleep(9000); // Wait until the connection is closed. f.channel().closeFuture().sync(); } finally { // Shut down the event loop to terminate all threads. group.shutdownGracefully(); } }
From source file:com.gdut.Netty_testing.time_server.server.TimeServer.java
License:Apache License
/** * /*from ww w.ja v a 2 s . c om*/ * @Title: main * @Description: TODO * @param @param args * @param @throws Exception * @return void * @throws */ public static void main(String[] args) throws Exception { // Configure SSL. 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) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new LoggingHandler(LogLevel.INFO), new TimeEncoder(), new TimeServerHandler()); // new TimeEncoder(), } }); // Start the server. ChannelFuture f = b.bind(PORT).sync(); f.addListener(new GenericFutureListener<Future<? super Void>>() { public void operationComplete(Future<? super Void> future) throws Exception { // TODO Auto-generated method stub System.out.println("success " + future.isSuccess()); } }); // 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:com.github.gregwhitaker.requestreply.Server.java
License:Apache License
/** * Starts the server.//from w ww . j ava 2 s. c o m * * @throws Exception */ private void start() throws Exception { ServerBootstrap server = new ServerBootstrap(); server.group(new NioEventLoopGroup(1), new NioEventLoopGroup(4)).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ReactiveSocketChannelInitializer()); server.bind(bindAddress).sync(); }
From source file:com.github.herong.rpc.netty.protobuf.demo1.ProtobufServer.java
License:Apache License
public void run() throws Exception { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*w w w . j a va2s . c o m*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline() // .addLast("frameDecoder", new ProtobufVarint32FrameDecoder()) // .addLast("protobufDecoder", new ProtobufDecoder(AddressBookProtos.AddressBook.getDefaultInstance())) // .addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender()) .addLast("protobufEncoder", new ProtobufEncoder()) // .addLast("handler", new ProtobufServerHandler()); } }); // Start the server. ChannelFuture f = b.bind(port).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:com.github.herong.rpc.netty.protobuf.demo2.Demo2ProtobufServer.java
License:Apache License
public void run() throws Exception { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/* w ww .j av a 2 s . co m*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline() // .addLast("frameDecoder", new ProtobufVarint32FrameDecoder()) // .addLast("protobufDecoder", new ProtobufDecoder(Message.DTO.getDefaultInstance())) // .addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender()) .addLast("protobufEncoder", new ProtobufEncoder()) // .addLast("handler", new Demo2ProtobufServerHandler()); } }); // Start the server. ChannelFuture f = b.bind(port).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:com.github.jonbonazza.puni.core.Application.java
License:Apache License
private void bootstrap() throws Exception { SslContext sslContext = null;//from w ww . jav a2 s. co m SSLConfiguration sslConfig = config.getSsl(); if (config.getSsl().isEnabled()) { sslContext = SslContext.newServerContext(new File(sslConfig.getCert()), new File(sslConfig.getPrivateKey())); } EventLoopGroup eventGroup = new NioEventLoopGroup(config.getEventLoopThreadCount()); try { ServerBootstrap b = new ServerBootstrap(); b.group(eventGroup).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new HttpInitializer(sslContext, muxer)); Channel ch = b.bind(config.getPort()).sync().channel(); ch.closeFuture().sync(); bootstrapped = true; } finally { eventGroup.shutdownGracefully(); } }
From source file:com.github.nettybook.ch7.junit.TelnetServerV3.java
License:Apache License
public void start() { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from w ww . 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 TelnetServerInitializerV3()); ChannelFuture future = b.bind(address).sync(); future.channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }