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:cn.david.main.PersonServer.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 {// ww w . jav a 2 s.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 ServerInitializer()); // 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:cn.david.socks.SocksServer.java
License:Apache License
public static void main(String[] args) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/* w ww . j a v a 2s. co m*/ 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(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:cn.npt.net.websocket.WebSocketServer.java
License:Apache License
private void init(int port, boolean ssl, String webSocketPath) throws Exception { final SslContext sslCtx; if (this.ssl) { SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else {// w w w .ja v a2 s.co m sslCtx = null; } bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new WebSocketServerInitializer(sslCtx, webSocketPath, ssl)); Channel ch = b.bind(this.port).sync().channel(); ch.closeFuture().sync();// } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } System.out.println("start websocket..."); }
From source file:co.paralleluniverse.comsat.webactors.netty.WebActorTest.java
License:Open Source License
@Before public void setUp() throws InterruptedException, IOException { System.out.println("Clearing sessions"); WebActorHandler.sessions.clear();/*from ww w. j av a 2s . c o m*/ group = new NioEventLoopGroup(); final ServerBootstrap b = new ServerBootstrap(); b.group(group).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new LoggingHandler(LogLevel.INFO)); pipeline.addLast(new HttpRequestDecoder()); pipeline.addLast(new LoggingHandler(LogLevel.INFO)); pipeline.addLast(HTTP_RESPONSE_ENCODER_KEY, new HttpResponseEncoder()); pipeline.addLast(new LoggingHandler(LogLevel.INFO)); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new LoggingHandler(LogLevel.INFO)); pipeline.addLast(webActorHandlerCreatorInEffect.call()); } }); ch = b.bind(INET_PORT).sync(); AbstractEmbeddedServer.waitUrlAvailable("http://localhost:" + INET_PORT); System.err.println("Server is up"); }
From source file:com.andrewkroh.cisco.xmlservices.HttpClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. ChannelPipeline p = ch.pipeline();//from w w w .j a va 2s . com // Create a logger for debugging purposes: p.addLast("log", new LoggingHandler(LogLevel.INFO)); // Adds codec for handling HTTP messages: p.addLast("codec", new HttpClientCodec()); // Add decompresser for GZIP'ed messages: p.addLast("inflater", new HttpContentDecompressor()); // Add automatic handling of "chunked" HTTP messages: p.addLast("aggregator", new HttpObjectAggregator(1048576)); // Finally add our handler: p.addLast("handler", handler); }
From source file:com.avanza.astrix.netty.server.NettyRemotingServer.java
License:Apache License
public void start() { bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_REUSEADDR, false).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override//from w w w. ja v a 2 s. co m public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(null)), new NettyRemotingServerHandler(serviceActivator)); } }); // Bind and start to accept incoming connections. Binds to all interfaces // TODO: Allow specifying a bind port range. Attempt to bind to each port in range and use first successfully bound port ChannelFuture channel = b.bind(port); try { if (channel.await(2, TimeUnit.SECONDS)) { if (channel.isSuccess()) { port = InetSocketAddress.class.cast(channel.channel().localAddress()).getPort(); log.info("NettyRemotingServer started listening on port={}", port); return; } } } catch (InterruptedException e) { } throw new IllegalStateException("Failed to start netty remoting server. Can't bind to port: " + port); }
From source file:com.baidu.rigel.biplatform.ma.file.serv.FileServer.java
License:Open Source License
private static void startServer(String location, int port) { fileLocation = new FileLocation(location); service = new LocalFileOperationServiceImpl(fileLocation); EventLoopGroup bossGroup = new NioEventLoopGroup(10); EventLoopGroup workGroup = new NioEventLoopGroup(50); try {//w w w. j a v a2 s . com ServerBootstrap strap = new ServerBootstrap(); strap.group(bossGroup, workGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel channel) throws Exception { // ?? channel.pipeline().addLast(new ObjectDecoder(ClassResolvers .weakCachingConcurrentResolver(FileServer.class.getClassLoader()))); channel.pipeline().addLast(new ObjectEncoder()); // channel.pipeline().addLast("HeartBeatHandler", new HeartBeatRespHandler()); channel.pipeline().addLast(new FileServer()); } }); ChannelFuture future = strap.bind(port).sync(); LOGGER.info("start file server successfully"); LOGGER.info("port : " + port); LOGGER.info("location : " + location); future.channel().closeFuture().sync(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); LOGGER.error("can not start file server with [port : {}] and fileLocation {{}}", port, location); printUsage(); System.exit(-1); } finally { bossGroup.shutdownGracefully(); workGroup.shutdownGracefully(); } }
From source file:com.bala.learning.learning.netty.HttpServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {//from w ww . j a v a 2 s .c o m SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else { sslCtx = null; } // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new HttpServerInitializer(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:com.beeswax.http.server.HttpServer.java
License:Apache License
public void run() throws InterruptedException { // Create event loop groups. One for incoming connections handling and // second for handling actual event by workers final NioEventLoopGroup bossGroup = new NioEventLoopGroup(serverConfig.bossGroupSize); final NioEventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from ww w. j av a 2 s. c o m*/ ServerBootstrap bootStrap = new ServerBootstrap(); bootStrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) // SO_BACKLOG : The maximum queue length for incoming connections. .option(ChannelOption.SO_BACKLOG, serverConfig.backlogSize) // TCP_NODELAY: option to disable Nagle's algorithm to achieve lower latency on every packet sent .option(ChannelOption.TCP_NODELAY, serverConfig.tcpNodelay) // SO_KEEPALIVE: option to enable keep-alive packets for a socket connection .childOption(ChannelOption.SO_KEEPALIVE, serverConfig.keepAlive) .childHandler(new HttpServerChannelInitializer(serverConfig, handlerFactory)); // bind to port final ChannelFuture channelFuture = bootStrap.bind(serverConfig.port).sync(); // Wait until the server socket is closed. channelFuture.channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.bianlz.ndg.p14.server.NettyServer.java
License:Apache License
public void bind() throws Exception { // ??NIO/*from w ww. java 2 s . 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(5000)); ch.pipeline().addLast(new LoginAuthRespHandler()); ch.pipeline().addLast("HeartBeatHandler", new HeartBeatRespHandler()); } }); // ??? b.bind(Constant.REMOTEIP, Constant.PORT).sync(); System.out.println("Netty server start ok : " + (Constant.REMOTEIP + " : " + Constant.PORT)); }