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.yahoo.ads.pb.network.netty.NettyPistachioServerInitializer.java
License:Open Source License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline();/*from www.ja v a2 s . c o m*/ if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new ProtobufVarint32FrameDecoder()); p.addLast(new ProtobufDecoder(NettyPistachioProtocol.Request.getDefaultInstance())); p.addLast(new ProtobufVarint32LengthFieldPrepender()); p.addLast(new ProtobufEncoder()); p.addLast(new NettyPistachioServerHandler()); }
From source file:com.yao.netty.objectecho.ObjectEchoServer.java
License:Apache License
public static void main(String[] args) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from www. jav a 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(); p.addLast(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(null)), new ObjectEchoServerHandler()); } }); // Bind and start to accept incoming connections. b.bind(PORT).sync().channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.yeahmobi.pangolin.proxy.SocksServer.java
License:Apache License
public void start() { try {/*from w w w.ja 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(serverConfig.getPort()).sync().channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.zhang.pool.NettyChannelPool.java
License:Apache License
/** * Create a new instance of ChannelPool/* w w w. j a v a 2 s. c om*/ * * @param maxPerRoute * max number of channels per route allowed in pool * @param connectTimeOutInMilliSecondes * max time wait for a channel return from pool * @param maxIdleTimeInMilliSecondes * max idle time for a channel before close * @param forbidForceConnect * value is false indicates that when there is not any channel in pool and no new * channel allowed to be create based on maxPerRoute, a new channel will be forced * to create.Otherwise, a <code>TimeoutException</code> will be thrown. The default * value is false. * @param additionalChannelInitializer * user-defined initializer * @param options * user-defined options * @param customGroup user defined {@link EventLoopGroup} */ @SuppressWarnings("unchecked") public NettyChannelPool(Map<String, Integer> maxPerRoute, int connectTimeOutInMilliSecondes, int maxIdleTimeInMilliSecondes, boolean forbidForceConnect, AdditionalChannelInitializer additionalChannelInitializer, Map<ChannelOption, Object> options, EventLoopGroup customGroup) { this.additionalChannelInitializer = additionalChannelInitializer; this.maxIdleTimeInMilliSecondes = maxIdleTimeInMilliSecondes; this.connectTimeOutInMilliSecondes = connectTimeOutInMilliSecondes; this.maxPerRoute = new ConcurrentHashMap<String, Semaphore>(); this.routeToPoolChannels = new ConcurrentHashMap<String, LinkedBlockingQueue<Channel>>(); this.group = null == customGroup ? new NioEventLoopGroup() : customGroup; this.forbidForceConnect = forbidForceConnect; this.clientBootstrap = new Bootstrap(); clientBootstrap.group(group).channel(NioSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true) .handler(new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception { ch.pipeline().addLast("log", new LoggingHandler(LogLevel.INFO)); ch.pipeline().addLast(HttpClientCodec.class.getSimpleName(), new HttpClientCodec()); if (null != NettyChannelPool.this.additionalChannelInitializer) { NettyChannelPool.this.additionalChannelInitializer.initChannel(ch); } ch.pipeline().addLast(HttpObjectAggregator.class.getSimpleName(), new HttpObjectAggregator(1048576)); ch.pipeline().addLast(IdleStateHandler.class.getSimpleName(), new IdleStateHandler(0, 0, NettyChannelPool.this.maxIdleTimeInMilliSecondes, TimeUnit.MILLISECONDS)); ch.pipeline().addLast(NettyChannelPoolHandler.class.getSimpleName(), new NettyChannelPoolHandler(NettyChannelPool.this)); } }); if (null != options) { for (Entry<ChannelOption, Object> entry : options.entrySet()) { clientBootstrap.option(entry.getKey(), entry.getValue()); } } if (null != maxPerRoute) { for (Entry<String, Integer> entry : maxPerRoute.entrySet()) { this.maxPerRoute.put(entry.getKey(), new Semaphore(entry.getValue())); } } }
From source file:com.zy.learning.netty.websocket.WebSocketServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {//from www . j a v a2 s .c o 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 ProtocolDetectorInitializer()); //.childHandler(new WebSocketServerInitializer(sslCtx)); Channel ch = b.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(); } }
From source file:com.zz.learning.netty5.chap12.server.NettyServer.java
License:Apache License
private void bind() throws Exception { // ??NIO/*from w ww . jav a 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)); // 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()); ch.pipeline().addLast("BusinessMessageRespHandler", new BusinessMessageRespHandler()); } }); // ??? ChannelFuture cf = b.bind(NettyConstant.REMOTEIP, NettyConstant.PORT).sync(); // serverChannel = cf.channel(); System.out.println("Netty server start ok : " + (NettyConstant.REMOTEIP + " : " + NettyConstant.PORT)); }
From source file:connexion.ServerSocket.java
public static void bind(int port) throws InterruptedException, SSLException, CertificateException { // Configure SSL. SelfSignedCertificate ssc = new SelfSignedCertificate(); SslContext sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey()); // Configure Group bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ServerInitializer(sslCtx)); b.bind(port).sync().channel().closeFuture().sync(); }
From source file:core.communication.threadpool.io.CallServer.java
License:Apache License
public static void connectServer() throws Exception { // Configure the bootstrap.server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); final CallServerHandler serverHandler = new CallServerHandler(); try {/*from w w w .jav 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 { ChannelPipeline p = ch.pipeline(); p.addLast(serverHandler); } }); // Start the bootstrap.server. ChannelFuture f = b.bind(PORT).sync(); // Wait until the bootstrap.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:core.HttpServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("log", new JbdcLoggingHandler(LogLevel.INFO)); pipeline.addLast("codec", new HttpServerCodec()); pipeline.addLast("handler", new HttpServerHandler()); }
From source file:de.dfki.kiara.impl.TransportServerImpl.java
License:Open Source License
@Override public void run() throws IOException { int numServers = 0; try {//from ww w . j a v a2 s . c o m synchronized (serverEntries) { for (ServerEntry serverEntry : serverEntries) { int port = Integer.parseInt(serverEntry.port); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(serverEntry.transport.createServerChildHandler(serverEntry.listener)); serverEntry.channel = b.bind(serverEntry.address, port).sync().channel(); ++numServers; } } } catch (InterruptedException ex) { throw new IOException(ex); } }