List of usage examples for io.netty.handler.codec.compression SnappyFramedEncoder SnappyFramedEncoder
SnappyFramedEncoder
From source file:org.apache.giraph.conf.ImmutableClassesGiraphConfiguration.java
License:Apache License
/** * Get encoder for message compression in netty * * @return message to byte encoder// w ww.j ava 2s . c om */ public MessageToByteEncoder getNettyCompressionEncoder() { switch (GiraphConstants.NETTY_COMPRESSION_ALGORITHM.get(this)) { case "SNAPPY": return new SnappyFramedEncoder(); case "INFLATE": return new JdkZlibEncoder(); default: return null; } }
From source file:org.apache.jackrabbit.oak.plugins.segment.standby.server.StandbyServer.java
License:Apache License
public StandbyServer(int port, final SegmentStore store, String[] allowedClientIPRanges, boolean secure) throws CertificateException, SSLException { this.port = port; if (secure) { SelfSignedCertificate ssc = new SelfSignedCertificate(); sslContext = SslContext.newServerContext(ssc.certificate(), ssc.privateKey()); }/* ww w.jav a2 s. c o m*/ observer = new CommunicationObserver("primary"); handler = new StandbyServerHandler(store, observer, allowedClientIPRanges); bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer(); try { jmxServer.registerMBean(new StandardMBean(this, StandbyStatusMBean.class), new ObjectName(this.getMBeanName())); } catch (Exception e) { log.error("can't register standby status mbean", e); } b = new ServerBootstrap(); b.group(bossGroup, workerGroup); b.channel(NioServerSocketChannel.class); b.option(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.SO_REUSEADDR, true); b.childOption(ChannelOption.TCP_NODELAY, true); b.childOption(ChannelOption.SO_REUSEADDR, true); b.childOption(ChannelOption.SO_KEEPALIVE, true); b.childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); if (sslContext != null) { p.addLast(sslContext.newHandler(ch.alloc())); } p.addLast(new LineBasedFrameDecoder(8192)); p.addLast(new StringDecoder(CharsetUtil.UTF_8)); p.addLast(new SnappyFramedEncoder()); p.addLast(new RecordIdEncoder()); p.addLast(new SegmentEncoder()); p.addLast(new BlobEncoder()); p.addLast(handler); } }); }
From source file:org.kobeyoung81.dummyhttpproxy.HexDumpProxyFrontendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { final Channel inboundChannel = ctx.channel(); // Start the connection attempt. Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()) .handler(new HexDumpProxyBackendHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false); ChannelFuture f = b.connect(remoteHost, remotePort); outboundChannel = f.channel();/*w w w . j av a2s. c om*/ if ("local".equals(role)) { outboundChannel.pipeline().addLast(new SnappyFramedEncoder()); outboundChannel.pipeline().addLast(new DummyHttpRequestEncoder()); outboundChannel.pipeline().addFirst(new SnappyFramedDecoder()); outboundChannel.pipeline().addFirst(new DummyHttpResponseDecoder()); } f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has // failed. inboundChannel.close(); } } }); }
From source file:org.kobeyoung81.dummyhttpproxy.HexDumpProxyInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) { if ("local".equals(role)) { ch.pipeline().addLast(new LoggingHandler(LogLevel.ERROR), new HexDumpProxyFrontendHandler(role, remoteHost, remotePort)); } else {//ww w .j a v a2s . com ch.pipeline().addLast(new LoggingHandler(LogLevel.ERROR), new DummyHttpRequestDecoder(), new SnappyFramedDecoder(), new HexDumpProxyFrontendHandler(role, remoteHost, remotePort), new SnappyFramedEncoder(), new DummyHttpResponseEncoder()); } }
From source file:org.kobeyoung81.hexdumpproxy.HexDumpProxyFrontendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { final Channel inboundChannel = ctx.channel(); // Start the connection attempt. Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()) .handler(new HexDumpProxyBackendHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false); ChannelFuture f = b.connect(remoteHost, remotePort); outboundChannel = f.channel();/* w w w.j a v a 2 s .c o m*/ if ("local".equals(role)) { outboundChannel.pipeline().addLast(new SnappyFramedEncoder()); outboundChannel.pipeline().addFirst(new SnappyFramedDecoder()); } f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has // failed. inboundChannel.close(); } } }); }
From source file:org.kobeyoung81.hexdumpproxy.HexDumpProxyInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) { if ("local".equals(role)) { ch.pipeline().addLast(//from w w w.j a v a 2s. com //new LoggingHandler(LogLevel.ERROR), new HexDumpProxyFrontendHandler(role, remoteHost, remotePort)); } else { ch.pipeline().addLast( //new LoggingHandler(LogLevel.ERROR), new SnappyFramedDecoder(), new HexDumpProxyFrontendHandler(role, remoteHost, remotePort), new SnappyFramedEncoder()); } }
From source file:se.sics.kompics.network.netty.NettyInitializer.java
License:Open Source License
/** * Initiate the Pipeline for the newly active connection. *//* ww w.ja v a 2 s . c om*/ @Override protected void initChannel(C ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // IN pipeline.addLast("decompressor", new SnappyFramedDecoder()); pipeline.addLast("decoder", new MessageDecoder()); pipeline.addLast("handler", handler); //pipeline.addBefore("handler", "handlerLogger", new LoggingHandler("handlerLogger")); //pipeline.addBefore("handler", "decoder", new MessageDecoder()); //pipeline.addBefore("decoder", "decoderLogger", new LoggingHandler("decoderLogger")); //pipeline.addBefore("decoderLogger", "deframer", new LengthFieldBasedFrameDecoder(65532, 0, 2)); //2^16 - 2bytes for the length header (snappy wants to more than 65536 bytes uncompressed) //pipeline.addBefore("deframer", "deframerLogger", new LoggingHandler("deframerLogger")); //pipeline.addBefore("decoder", "decompressor", new SnappyFramedDecoder()); // OUT pipeline.addLast("compressor", new SnappyFramedEncoder()); pipeline.addLast("encoder", new MessageEncoder()); //pipeline.addAfter("encoder", "encoderLogger", new LoggingHandler("encoderLogger")); //pipeline.addAfter("encoderLogger", "framer", new LengthFieldPrepender(2)); //pipeline.addAfter("framer", "framerLogger", new LoggingHandler("framerLogger")); //pipeline.addAfter("encoder", "compressor", new SnappyFramedEncoder()); }