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.irh.material.basics.netty.chapter14_1.server.NettyServer.java
License:Apache License
public void bind() throws Exception { // ??NIO//w ww . j av a 2 s . com EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.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 IOException { ch.pipeline().addLast("decoder", new NettyMessageDecoder(1024 * 1024, 4, 4)); ch.pipeline().addLast("encoder", new NettyMessageEncoder()); ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(50)); ch.pipeline().addLast("LoginAuthHandler", new LoginAuthRespHandler()); ch.pipeline().addLast("HeartBeatHandler", new HeartBeatRespHandler()); } }); // ??? bootstrap.bind(NettyConstant.REMOTEIP, NettyConstant.PORT).sync(); System.out.println("Netty server start ok : " + (NettyConstant.REMOTEIP + " : " + NettyConstant.PORT)); }
From source file:com.jjzhk.Chapter14.netty.NettyServer.java
License:Apache License
public void bind() throws Exception { // ?NIO?//from www . ja va 2s .c o m EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); 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 IOException { ch.pipeline().addLast(new NettyMessageDecoder(1024 * 1024, 4, 4)); ch.pipeline().addLast(new NettyMessageEncoder()); ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(50)); ch.pipeline().addLast(new LoginAuthRespHandler()); ch.pipeline().addLast("HeartBeatHandler", new HeartBeatRespHandler()); } }); // ???? b.bind(NettyConstant.REMOTEIP, NettyConstant.PORT).sync(); System.out.println("Netty server start ok : " + (NettyConstant.REMOTEIP + " : " + NettyConstant.PORT)); }
From source file:com.juaby.labs.rpc.server.Rpc2Server.java
License:Apache License
public void start() { RpcThreadFactory threadName = new RpcThreadFactory("RPC-SVR-WORKER", false); int threads = Runtime.getRuntime().availableProcessors() * 2 + 1; bossGroup = new NioEventLoopGroup(threads, threadName); workerGroup = new NioEventLoopGroup(); try {/* ww w.j a va 2s .c o m*/ 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) throws Exception { ChannelPipeline p = ch.pipeline(); // Configure SSL. final SslContext sslCtx; if (SSL) { SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else { sslCtx = null; } if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast( //output new Rpc2ServerEncoder(), //input new Rpc2ServerDecoder(ServiceConfig.MAX_OBJECT_SIZE), new Rpc2ServerHandler()); } }); // Bind and start to accept incoming connections. //b.bind(HOST, PORT).sync().channel().closeFuture().sync(); b.bind(host, port); } finally { } }
From source file:com.just.server.http.https.HttpsStaticFileServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream("D:\\catest.key"), "catest".toCharArray()); kmf.init(ks, "catest".toCharArray()); sslCtx = SslContextBuilder.forServer(kmf).sslProvider(SslProvider.JDK).build(); EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/* ww w . j av a 2 s. co m*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new HttpStaticFileServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); System.err.println("Open your web browser and navigate to " + "https" + "://127.0.0.1:" + PORT + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.khs.microservice.whirlpool.whirlpoolserver.WhirlpoolServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from w ww . j av a 2 s .com*/ 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) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("encoder", new HttpResponseEncoder()); p.addLast("decoder", new HttpRequestDecoder()); p.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8)); p.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8)); p.addLast("aggregator", new HttpObjectAggregator(65536)); p.addLast("handler", new WhirlpoolServerHandler()); } }); // Start the server. ChannelFuture f = b.bind(PORT).sync(); logger.info("Whirlpool Server started"); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } finally { logger.info("Whirlpool Server shutdown started"); // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); logger.info("Whirlpool Server shutdown completed"); } }
From source file:com.khs.stockticker.StockTickerServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//www . java 2 s . c o m 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) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("encoder", new HttpResponseEncoder()); p.addLast("decoder", new HttpRequestDecoder()); p.addLast("aggregator", new HttpObjectAggregator(65536)); p.addLast("handler", new StockTickerServerHandler()); } }); // Start the server. ChannelFuture f = b.bind(PORT).sync(); logger.info("Ticket Symbol Server started"); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } finally { logger.info("Ticket Symbol Server shutdown started"); // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); logger.info("Ticket Symbol Server shutdown completed"); } }
From source file:com.kradac.karview.netty.EchoServer.java
public void run() throws Exception { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from w w w . j a v a2 s. com 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(new ReadTimeoutHandler(timeout * 60)); ch.pipeline().addLast(new MyDecoder()); ch.pipeline().addLast(new MyEncoder()); ch.pipeline().addLast( // new LoggingHandler(LogLevel.INFO), new EchoServerHandler(t)); } }); // Start the server. 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.lampard.netty4.protocol.netty.server.NettyServer.java
License:Apache License
public void bind() throws Exception { // ??NIO/* ww w . ja v a 2s .co m*/ EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); 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 IOException { ch.pipeline().addLast(new NettyMessageDecoder(1024 * 1024, 4, 4)); ch.pipeline().addLast(new NettyMessageEncoder()); ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(50)); ch.pipeline().addLast(new LoginAuthRespHandler()); ch.pipeline().addLast("HeartBeatHandler", new HeartBeatRespHandler()); } }); // ??? b.bind(NettyConstant.REMOTEIP, NettyConstant.PORT).sync(); LOG.info("Netty server start ok : " + (NettyConstant.REMOTEIP + " : " + NettyConstant.PORT)); }
From source file:com.lb.netty.protoc.SubReqServer.java
License:Apache License
public void bind(int port) throws Exception { // ??NIO//from ww w . j a v a 2 s. co m EventLoopGroup bossGroup = new NioEventLoopGroup(); 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) { ch.pipeline().addLast(new ProtobufVarint32FrameDecoder()); // protobuffer ch.pipeline().addLast( new ProtobufDecoder(SubscribeReqProto.SubscribeReq.getDefaultInstance())); ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender()); ch.pipeline().addLast(new ProtobufEncoder()); ch.pipeline().addLast(new SubReqServerHandler()); } }); // ??? ChannelFuture f = b.bind(port).sync(); // ??? f.channel().closeFuture().sync(); } finally { // ? bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.linkedin.proxy.main.ProxyServer.java
License:Apache License
public static void main(String[] args) throws Exception { //process command line if (processCommandLine(args) == false) { m_log.fatal("Command line processing error. Closing..."); return;/*from ww w . j a v a 2s .co m*/ } //process properties file Properties prop = getProperties(PROP_FILE); if (prop == null) { m_log.fatal("Error in processing properties file. Closing..."); return; } //set mode ProxyMode runMode; String temp = prop.getProperty(FLAG_PROXY_MODE); if (temp == null) { m_log.fatal("Mode is missing. Closing..."); return; } else if (temp.equals("mysql")) { runMode = ProxyMode.MYSQL; } else if (temp.equals("rocksdb")) { runMode = ProxyMode.ROCKSDB; } else { m_log.fatal("Unknown mode " + temp + ". Closing..."); return; } //Process mode specific files Set<String> dbSet = new HashSet<String>(); if (runMode == ProxyMode.ROCKSDB) { //for rocksdb, I need db names if (DB_SET_FILE.equals("")) { m_log.fatal("DB set file is missing. Closing..."); return; } else if (processDbSet(dbSet, DB_SET_FILE) == false) { m_log.fatal("Error in processing Dbset file. Closing..."); return; } else { m_log.info("DB set file is processed"); } } else { m_log.fatal("Unknown mode " + runMode + ". Closing..."); return; } //perform mode based initializations if any if (runMode == ProxyMode.ROCKSDB) { RocksDB.loadLibrary(); } //get run time int runTime; temp = prop.getProperty(FLAG_PROXY_RUNTIME); if (temp == null) { runTime = 0; } else { runTime = Integer.parseInt(temp); } m_log.info("Runtime is " + runTime); //get thread pool size int thrSize; temp = prop.getProperty(FLAG_PROXY_THR); if (temp == null) { m_log.warn("Thread pool size parameter is missing. It is set to 10 by default"); thrSize = 10; } else { thrSize = Integer.parseInt(temp); } //get listening port int port; temp = prop.getProperty(FLAG_PROXY_PORT); if (temp == null) { m_log.fatal("Listening port is not specified. Closing..."); return; } else { port = Integer.parseInt(temp); } //init thread pools bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(thrSize); //create connection pools if (runMode == ProxyMode.ROCKSDB) { connPool = new BlockingRocksdbConnectionPool(dbSet); } else if (runMode == ProxyMode.MYSQL) { connPool = new BlockingMysqlConnectionPool(); } else { m_log.fatal("Unkown setup. Closing..."); return; } //init connection pool if (connPool.init(prop) == false) { m_log.fatal("Cannot init conn pool. Closing..."); return; } //if run time is specified, then start closing thread Thread closingThread = null; if (runTime > 0) { closingThread = new ClosingThread(runTime); closingThread.start(); System.out.println("Closing in " + runTime + " seconds."); } else { System.out.println("Type \"close\" to close proxy."); } try { ServerBootstrap b = new ServerBootstrap(); if (runMode == ProxyMode.MYSQL) { b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new MysqlInitializer(prop, connPool)); } else if (runMode == ProxyMode.ROCKSDB) { b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new RocksdbInitializer(prop, connPool)); } ch = b.bind(port).sync().channel(); if (runTime > 0) { ch.closeFuture().sync(); } else { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while (true) { String line = in.readLine(); m_log.debug("Got line: " + line); if (line == null || "close".equals(line.toLowerCase())) { break; } } } } catch (Exception e) { m_log.error("Error..", e); } finally { close(); } }