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.hiido.eagle.hes.transfer.FileTransferServer.java
License:Apache License
public void start() throws Exception { logger.info("Start server at host:{} port:{}, the number of work:{}", host, port, workNum); EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(workNum); try {//from ww w.ja v 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 ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new FileHandler()); } }); ChannelFuture f = null; if (host == null) { f = b.bind(port).sync(); } else { f = b.bind(host, port).sync(); } logger.info("Server bound host:{} port:{} successfully", host, port); f.channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.hipishare.chat.SecureChatClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { LOG.info("channel?"); ChannelPipeline pipeline = ch.pipeline(); // Add SSL handler first to encrypt and decrypt everything. // In this example, we use a bogus certificate in the server side // and accept any invalid certificates in the client side. // You will need something more complicated to identify both // and server in the real world. pipeline.addLast(sslCtx.newHandler(ch.alloc(), SecureChatClient.HOST, SecureChatClient.PORT)); // On top of the SSL handler, add the text line codec. pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); pipeline.addLast(new LoggingHandler(LogLevel.INFO)); // and then business logic. pipeline.addLast(new SecureChatClientHandler()); }
From source file:com.hipishare.chat.test.EchoClient.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL.git final SslContext sslCtx; if (SSL) {/*from ww w . j av a 2s . c om*/ 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 { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc(), HOST, PORT)); } p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new EchoClientHandler()); } }); // Start the client. ChannelFuture f = b.connect(HOST, PORT).sync(); // 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.hipishare.chat.test.EchoServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {//from w w w . jav a2 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(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)); p.addLast(new IdleStateHandler(30, 10, 0, TimeUnit.SECONDS)); p.addLast(new HeartBeatHandler()); p.addLast(new EchoServerHandler()); } }); // 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.hop.hhxx.example.sctp.multihoming.SctpMultiHomingEchoServer.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 a v a 2s . c o m ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioSctpServerChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SctpChannel>() { @Override public void initChannel(SctpChannel ch) throws Exception { ch.pipeline().addLast( // new LoggingHandler(LogLevel.INFO), new SctpEchoServerHandler()); } }); InetSocketAddress localAddress = new InetSocketAddress(SERVER_PRIMARY_HOST, SERVER_PORT); InetAddress localSecondaryAddress = InetAddress.getByName(SERVER_SECONDARY_HOST); // Bind the server to primary address. ChannelFuture bindFuture = b.bind(localAddress).sync(); //Get the underlying sctp channel SctpServerChannel channel = (SctpServerChannel) bindFuture.channel(); //Bind the secondary address ChannelFuture connectFuture = channel.bindAddress(localSecondaryAddress).sync(); // Wait until the connection is closed. connectFuture.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.hxr.javatone.concurrency.netty.official.filetransfer.FileServer.java
License:Apache License
public void run() throws Exception { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from ww w . j a v a2s . 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(new StringEncoder(CharsetUtil.UTF_8), new LineBasedFrameDecoder(8192), new StringDecoder(CharsetUtil.UTF_8), new FileHandler()); } }); // 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.hxr.javatone.concurrency.netty.official.localecho.LocalEcho.java
License:Apache License
public void run() throws Exception { // Address to bind on / connect to. final LocalAddress addr = new LocalAddress(port); EventLoopGroup serverGroup = new DefaultEventLoopGroup(); EventLoopGroup clientGroup = new NioEventLoopGroup(); // NIO event loops are also OK try {//from w ww .ja va 2 s .c om // Note that we can use any event loop to ensure certain local channels // are handled by the same event loop thread which drives a certain socket channel // to reduce the communication latency between socket channels and local channels. ServerBootstrap sb = new ServerBootstrap(); sb.group(serverGroup).channel(LocalServerChannel.class) .handler(new ChannelInitializer<LocalServerChannel>() { @Override public void initChannel(LocalServerChannel ch) throws Exception { ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO)); } }).childHandler(new ChannelInitializer<LocalChannel>() { @Override public void initChannel(LocalChannel ch) throws Exception { ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new LocalEchoServerHandler()); } }); Bootstrap cb = new Bootstrap(); cb.group(clientGroup).channel(LocalChannel.class).handler(new ChannelInitializer<LocalChannel>() { @Override public void initChannel(LocalChannel ch) throws Exception { ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new LocalEchoClientHandler()); } }); // Start the server. sb.bind(addr).sync(); // Start the client. Channel ch = cb.connect(addr).sync().channel(); // Read commands from the stdin. System.out.println("Enter text (quit to end)"); ChannelFuture lastWriteFuture = null; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for (;;) { String line = in.readLine(); if (line == null || "quit".equalsIgnoreCase(line)) { break; } // Sends the received line to the server. lastWriteFuture = ch.writeAndFlush(line); } // Wait until all messages are flushed before closing the channel. if (lastWriteFuture != null) { lastWriteFuture.awaitUninterruptibly(); } } finally { serverGroup.shutdownGracefully(); clientGroup.shutdownGracefully(); } }
From source file:com.hzmsc.scada.Jmtis.server.PortUnificationServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL context SelfSignedCertificate ssc = new SelfSignedCertificate(); final SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*w ww . j a v a 2 s . co 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 { System.out.println("initChannel.........................."); ch.pipeline().addLast(new PortUnificationServerHandler(sslCtx)); } }); // Bind and start to accept incoming connections. b.bind(PORT).sync().channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.im.socket.netty.tcp.SocketServer.java
License:Apache License
public boolean start() { if (start) {/* ww w .ja va 2 s . co m*/ return start; } EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { start = true; server.group(bossGroup, workerGroup); server.channel(NioServerSocketChannel.class); server.handler(new LoggingHandler(LogLevel.INFO)); server.childHandler(new SocketServerInitializer()); Channel ch = server.bind(port).sync().channel(); ch.closeFuture().sync(); } catch (InterruptedException ex) { start = false; logger.error("WebSocketServer?", ex); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); System.out.println("WebSocketServer:-----shutdown---------"); } return start; }
From source file:com.im.test.WebSocketServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from ww w . j a v a 2 s . c o m ServerBootstrap server = new ServerBootstrap(); server.group(bossGroup, workerGroup); server.channel(NioServerSocketChannel.class); server.handler(new LoggingHandler(LogLevel.INFO)); server.childHandler(new WebSocketServerInitializer()); Channel ch = server.bind(PORT).sync().channel(); System.out.println("Open your web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:" + PORT + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }