List of usage examples for io.netty.handler.logging LoggingHandler LoggingHandler
public LoggingHandler()
From source file:MyNettyServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {// w w w. j a v a 2s. co m SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey()); } 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()) .childHandler(new ServerInitializer(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:barry.ServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("logging", new LoggingHandler()); // ???// ww w. j a v a 2s .c o m // pipelinene.addLast("decoder", new MsgDecoder()); // ????byte // pipeline.addLast("encoder", new MsgEncoder()); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // pipeline.addLast(new IdleStateHandler(0, 0, 90, TimeUnit.SECONDS)); // pipeline.addLast("handler", serverHandler); }
From source file:com.barry.netty.ServerInitializer.java
License:Apache License
@Override public void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); byte[] bytes = { Constant.TAIL_BYTE }; ByteBuf delimiter = Unpooled.wrappedBuffer(bytes); pipeline.addLast("logging", new LoggingHandler()); // ??/*from w w w . j av a2s . c o m*/ pipeline.addLast("decoderContent", new MessageBufferDecoder()); // ??? pipeline.addLast("DelimiterDecode", new DelimiterBasedFrameDecoder(Constant.MAX_LEN, false, delimiter)); // ??? pipeline.addLast("decoderObj", new MsgDecoder()); // pipeline.addLast("handler", new ServerHandler()); }
From source file:com.github.milenkovicm.kafka.connection.ControlKafkaBroker.java
License:Apache License
@Override protected ChannelInitializer<SocketChannel> pipeline() { return new ChannelInitializer<SocketChannel>() { @Override/*from ww w . ja v a 2 s. co m*/ public void initChannel(SocketChannel channel) throws Exception { final ChannelPipeline pipeline = channel.pipeline(); pipeline.addLast(new LengthFieldBasedFrameDecoder(Short.MAX_VALUE, 0, 4, 0, 4)); if (properties.get(ProducerProperties.NETTY_DEBUG_PIPELINE)) { pipeline.addLast(new LoggingHandler()); } pipeline.addLast(new MetadataHandler(properties)); pipeline.addLast(new TerminalHandler()); } }; }
From source file:com.github.milenkovicm.kafka.connection.DataKafkaBroker.java
License:Apache License
@Override protected ChannelInitializer<SocketChannel> pipeline() { return new ChannelInitializer<SocketChannel>() { @Override// w w w . j av a2 s. co m public void initChannel(SocketChannel channel) throws Exception { final ChannelPipeline pipeline = channel.pipeline(); pipeline.addLast(new LengthFieldBasedFrameDecoder(Short.MAX_VALUE, 0, 4, 0, 4)); pipeline.addLast(metricHandler); if (properties.get(ProducerProperties.NETTY_DEBUG_PIPELINE)) { pipeline.addLast(new LoggingHandler()); } if (properties.get(ProducerProperties.NETTY_HANDLER_COMPOSITE)) { pipeline.addLast(new CompositeProducerHandler(topicName, properties)); } else { pipeline.addLast(new CopyProducerHandler(topicName, properties)); } pipeline.addLast(new TerminalHandler()); } }; }
From source file:com.github.nettybook.ch4.EchoClient.java
License:Apache License
public static void main(String[] args) throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {//w ww .j av a 2s . c o m Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new EchoClientHandler1()); p.addLast(new LoggingHandler()); } }); ChannelFuture f = b.connect("localhost", 8888).sync(); f.channel().closeFuture().sync(); } finally { group.shutdownGracefully(); } }
From source file:com.qualys.jserf.SerfClientInitializer.java
License:Apache License
@Override protected void initChannel(SocketChannel socketChannel) throws Exception { ChannelPipeline pipeline = socketChannel.pipeline(); if (log.isDebugEnabled()) { pipeline.addFirst("loggingHandler", new LoggingHandler()); }//from ww w . j a va2 s . co m pipeline.addLast("reconnectHandler", new ReconnectClientHandler(channelManger)); log.debug("Adding ByteArray Encoder"); pipeline.addLast("bytesEncoder", new ByteArrayEncoder()); log.debug("Adding SerfClientHandler"); pipeline.addLast("handler", new SerfClientHandler(extractorManager, messagePack, callBacksBySequence)); }
From source file:com.slyak.services.proxy.server.NettyProxyServer.java
License:Apache License
@SneakyThrows(InterruptedException.class) public void start() { ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED); ServerBootstrap bootstrap = new ServerBootstrap(); bossGroup = new NioEventLoopGroup(proxyProperties.getBoss()); workerGroup = new NioEventLoopGroup(proxyProperties.getWorker()); clientGroup = new NioEventLoopGroup(proxyProperties.getClient()); try {/*from w w w . j ava 2s . c o m*/ bootstrap.group(bossGroup, workerGroup).channel(getChannelClass()) .option(ChannelOption.SO_BACKLOG, proxyProperties.getBackLog()) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, proxyProperties.getConnectTimeout()) .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_REUSEADDR, true) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); //channel time out handler pipeline.addLast(new IdleStateHandler(0, 0, 30)); pipeline.addLast(new IdleEventHandler()); //logging pipeline.addLast(new LoggingHandler()); if (isRouter()) { pipeline.addLast(getProxyHandler(proxyProperties)); } else { pipeline.addLast(getCustomChannelHandlers(clientGroup)); } pipeline.addLast(ExceptionHandler.INSTANCE); } }); //start server ChannelFuture future = bootstrap.bind(proxyProperties.getPort()).sync(); log.debug("Starting proxy server , port is {}", proxyProperties.getPort()); future.channel().closeFuture().sync(); } finally { stop(); } }
From source file:diskCacheV111.doors.NettyLineBasedDoor.java
License:Open Source License
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { ChannelPipeline pipeline = ctx.pipeline(); String self = ctx.name();//from w w w . jav a 2 s . c o m if (expectProxyProtocol) { pipeline.addBefore("door", "haproxy", new HAProxyMessageDecoder()); } // Decoders pipeline.addBefore(self, "frameDecoder", new LineBasedFrameDecoder(KiB.toBytes(64))); pipeline.addBefore(self, "stringDecoder", new StringDecoder(charset)); // Encoder pipeline.addBefore(self, "lineEncoder", new LineEncoder(lineSeparator, charset)); pipeline.addBefore(self, "logger", new LoggingHandler()); }
From source file:gwlpr.loginshard.LoginShardChannelInitializer.java
License:Open Source License
@Override protected void initChannel(Channel ch) { // inbound handlers ch.pipeline().addLast(//from ww w. ja v a2s. c o m //new AutoFlushHandler(), new LoggingHandler(), new ConnectionStateHandler(), HandshakeHandler.produceLoginHandshake(encrypted), new LoginServerCodec(), new MessageDemuxDecoder()); }