List of usage examples for io.netty.channel ChannelPipeline addLast
ChannelPipeline addLast(EventExecutorGroup group, ChannelHandler... handlers);
From source file:com.baidu.rigel.biplatform.tesseract.node.service.IndexAndSearchServer.java
License:Open Source License
/** * startServer/*from ww w.ja v a 2s . co m*/ * * @throws Exception */ protected void startServer() throws Exception { LOGGER.info("Index and Search server ready to start..."); long curr = System.currentTimeMillis(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup); b.channel(NioServerSocketChannel.class); b.option(ChannelOption.SO_BACKLOG, 1000000); b.childHandler(new ChannelInitializer<SocketChannel>() { /* * (non-Javadoc) * * @see * io.netty.channel.ChannelInitializer#initChannel(io.netty. * channel.Channel) */ @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("encode", new ObjectEncoder()); pipeline.addLast("decode", new ObjectDecoder(ClassResolvers.weakCachingConcurrentResolver(null))); pipeline.addLast(IndexServerHandler.getChannelHandler()); pipeline.addLast(SearchServerHandler.getChannelHandler()); pipeline.addLast(FileServerHandler.getChannelHandler()); } }); // ChannelFuture f = b.bind(IP, PORT).sync(); // f.channel().closeFuture().sync(); int currPort = NetworkUtils.getAvailablePort(this.node.getPort()); ChannelFuture f = b.bind(IP, currPort).sync(); if (currPort != this.node.getPort()) { this.node.setPort(currPort); } serverChannelFuture = f; LOGGER.info("Index and Search server started at Port:" + this.node.getPort()); LOGGER.info("Index and Search server started in " + (System.currentTimeMillis() - curr) + "ms"); this.isRunning = true; serverChannelFuture.channel().closeFuture().sync().channel(); } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } }
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()); // ??// w ww . java2 s .co 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.basho.riak.client.core.netty.HttpChannelInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("codec", new HttpClientCodec(4096, 8192, 8192, true)); p.addLast("riakHttpOperationEncoder", new RiakHttpOperationEncoder()); }
From source file:com.basho.riak.client.core.netty.PbChannelInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("riakPBCodec", new RiakPbMessageCodec()); p.addLast("riakPBOperationEncoder", new RiakPbOperationEncoder()); }
From source file:com.basho.riak.client.core.netty.RiakChannelInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(Constants.MESSAGE_CODEC, new RiakMessageCodec()); p.addLast(Constants.OPERATION_ENCODER, new RiakOperationEncoder()); p.addLast(Constants.RESPONSE_HANDLER, new RiakResponseHandler(listener)); }
From source file:com.bdtools.doxecute.WorldClockClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder()); p.addLast("protobufDecoder", new ProtobufDecoder(WorldClockProtocol.LocalTimes.getDefaultInstance())); p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender()); p.addLast("protobufEncoder", new ProtobufEncoder()); p.addLast("handler", new WorldClockClientHandler()); }
From source file:com.bdtools.doxecute.WorldClockServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder()); p.addLast("protobufDecoder", new ProtobufDecoder(WorldClockProtocol.Locations.getDefaultInstance())); p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender()); p.addLast("protobufEncoder", new ProtobufEncoder()); p.addLast("handler", new WorldClockServerHandler()); }
From source file:com.brainlounge.zooterrain.netty.WebSocketServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("codec-http", new HttpServerCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); pipeline.addLast("inboundhandler", new WebSocketServerInboundHandler(zkStateObserver)); }
From source file:com.caricah.iotracah.server.httpserver.netty.HttpServerInitializer.java
License:Apache License
@Override protected void customizePipeline(EventExecutorGroup eventExecutorGroup, ChannelPipeline pipeline) { pipeline.addLast("server", new HttpServerCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(1048576)); // we finally have the chance to add some business logic. pipeline.addLast(eventExecutorGroup, "iotracah-http", new HttpServerHandler((HttpServerImpl) getServerImpl())); }
From source file:com.caricah.iotracah.server.mqttserver.netty.MqttServerInitializer.java
License:Apache License
@Override protected void customizePipeline(EventExecutorGroup eventExecutorGroup, ChannelPipeline pipeline) { pipeline.addLast("decoder", new MqttDecoder()); pipeline.addLast("encoder", new MqttEncoder()); // we finally have the chance to add some business logic. pipeline.addLast(eventExecutorGroup, "iotracah-mqtt", new MqttServerHandler((MqttServerImpl) getServerImpl())); }