@Override
 public ChannelPipeline getPipeline() throws Exception {
   ChannelPipeline pipeline = Channels.pipeline();
   if (sslFactory != null) {
     pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
   }
   pipeline.addLast("decoder", new HttpRequestDecoder());
   pipeline.addLast("aggregator", new HttpChunkAggregator(1 << 16));
   pipeline.addLast("encoder", new HttpResponseEncoder());
   pipeline.addLast("chunking", new ChunkedWriteHandler());
   pipeline.addLast("shuffle", PullServer);
   return pipeline;
   // TODO factor security manager into pipeline
   // TODO factor out encode/decode to permit binary shuffle
   // TODO factor out decode of index to permit alt. models
 }
Esempio n. 2
0
  private <In, Out> Channel listen(int port, NetworkEndpointFactory<In, Out> endpointFactory) {
    ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);

    bootstrap.setPipelineFactory(
        () ->
            Channels.pipeline(
                new ObjectEncoder(),
                new ObjectDecoder(ClassResolvers.softCachingResolver(getClass().getClassLoader())),
                new LoggingHandler(NettyNetworkServer.class, logLevel),
                new NettyNetworkEndpointAdapter<>(endpointFactory.createEndpoint()),
                new AddToChannelGroupHandler(allChannels)));

    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", true);

    Channel channel = bootstrap.bind(new InetSocketAddress(port));
    allChannels.add(channel);
    return channel;
  }
Esempio n. 3
0
  private <K, V, T extends RedisAsyncConnection<K, V>> T connect(
      CommandHandler<K, V> handler, T connection) {
    try {
      ConnectionWatchdog watchdog = new ConnectionWatchdog(bootstrap, channels, timer);
      ChannelPipeline pipeline = Channels.pipeline(watchdog, handler, connection);
      Channel channel = bootstrap.getFactory().newChannel(pipeline);

      ChannelFuture future = channel.connect((SocketAddress) bootstrap.getOption("remoteAddress"));
      future.await();

      if (!future.isSuccess()) {
        throw future.getCause();
      }

      watchdog.setReconnect(true);

      return connection;
    } catch (Throwable e) {
      throw new RedisException("Unable to connect", e);
    }
  }
 @Override
 public ChannelPipeline getPipeline() throws Exception {
   ChannelPipeline pipeline = Channels.pipeline();
   pipeline.addLast("openChannels", transport.serverOpenChannels);
   HttpRequestDecoder requestDecoder =
       new HttpRequestDecoder(
           (int) transport.maxInitialLineLength.bytes(),
           (int) transport.maxHeaderSize.bytes(),
           (int) transport.maxChunkSize.bytes());
   if (transport.maxCumulationBufferCapacity != null) {
     if (transport.maxCumulationBufferCapacity.bytes() > Integer.MAX_VALUE) {
       requestDecoder.setMaxCumulationBufferCapacity(Integer.MAX_VALUE);
     } else {
       requestDecoder.setMaxCumulationBufferCapacity(
           (int) transport.maxCumulationBufferCapacity.bytes());
     }
   }
   if (transport.maxCompositeBufferComponents != -1) {
     requestDecoder.setMaxCumulationBufferComponents(transport.maxCompositeBufferComponents);
   }
   pipeline.addLast("decoder", requestDecoder);
   pipeline.addLast("decoder_compress", new ESHttpContentDecompressor(transport.compression));
   HttpChunkAggregator httpChunkAggregator =
       new HttpChunkAggregator((int) transport.maxContentLength.bytes());
   if (transport.maxCompositeBufferComponents != -1) {
     httpChunkAggregator.setMaxCumulationBufferComponents(
         transport.maxCompositeBufferComponents);
   }
   pipeline.addLast("aggregator", httpChunkAggregator);
   pipeline.addLast("encoder", new ESHttpResponseEncoder());
   if (transport.compression) {
     pipeline.addLast("encoder_compress", new HttpContentCompressor(transport.compressionLevel));
   }
   if (transport.pipelining) {
     pipeline.addLast("pipelining", new HttpPipeliningHandler(transport.pipeliningMaxEvents));
   }
   pipeline.addLast("handler", requestHandler);
   return pipeline;
 }