io.netty.channel.socket.SocketChannel.closeFuture()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(220)

本文整理了Java中io.netty.channel.socket.SocketChannel.closeFuture()方法的一些代码示例,展示了SocketChannel.closeFuture()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SocketChannel.closeFuture()方法的具体详情如下:
包路径:io.netty.channel.socket.SocketChannel
类名称:SocketChannel
方法名:closeFuture

SocketChannel.closeFuture介绍

暂无

代码示例

代码示例来源:origin: apache/drill

@Override
 protected void initChannel(SocketChannel ch) throws Exception {
  // logger.debug("initializing client connection.");
  connection = initRemoteConnection(ch);
  ch.closeFuture().addListener(getCloseHandler(ch, connection));
  final ChannelPipeline pipe = ch.pipeline();
  // Make sure that the SSL handler is the first handler in the pipeline so everything is encrypted
  if (isSslEnabled()) {
   setupSSL(pipe, sslHandshakeListener);
  }
  pipe.addLast(RpcConstants.PROTOCOL_DECODER, getDecoder(connection.getAllocator()));
  pipe.addLast(RpcConstants.MESSAGE_DECODER, new RpcDecoder("c-" + rpcConfig.getName()));
  pipe.addLast(RpcConstants.PROTOCOL_ENCODER, new RpcEncoder("c-" + rpcConfig.getName()));
  pipe.addLast(RpcConstants.HANDSHAKE_HANDLER, new ClientHandshakeHandler(connection));
  if(pingHandler != null){
   pipe.addLast(RpcConstants.IDLE_STATE_HANDLER, pingHandler);
  }
  pipe.addLast(RpcConstants.MESSAGE_HANDLER, new InboundHandler(connection));
  pipe.addLast(RpcConstants.EXCEPTION_HANDLER, new RpcExceptionHandler<>(connection));
 }
}); //

代码示例来源:origin: apache/drill

@Override
     protected void initChannel(SocketChannel ch) throws Exception {
//            logger.debug("Starting initialization of server connection.");
      SC connection = initRemoteConnection(ch);
      ch.closeFuture().addListener(getCloseHandler(ch, connection));

      final ChannelPipeline pipe = ch.pipeline();
      // Make sure that the SSL handler is the first handler in the pipeline so everything is encrypted
      if (isSslEnabled()) {
       setupSSL(pipe);
      }

      pipe.addLast(RpcConstants.PROTOCOL_DECODER, getDecoder(connection.getAllocator(), getOutOfMemoryHandler()));
      pipe.addLast(RpcConstants.MESSAGE_DECODER, new RpcDecoder("s-" + rpcConfig.getName()));
      pipe.addLast(RpcConstants.PROTOCOL_ENCODER, new RpcEncoder("s-" + rpcConfig.getName()));
      pipe.addLast(RpcConstants.HANDSHAKE_HANDLER, getHandshakeHandler(connection));

      if (rpcMapping.hasTimeout()) {
       pipe.addLast(RpcConstants.TIMEOUT_HANDLER,
         new LoggingReadTimeoutHandler(connection, rpcMapping.getTimeout()));
      }

      pipe.addLast(RpcConstants.MESSAGE_HANDLER, new InboundHandler(connection));
      pipe.addLast(RpcConstants.EXCEPTION_HANDLER, new RpcExceptionHandler<>(connection));

      connect = true;
//            logger.debug("Server connection initialization completed.");
     }
    });

代码示例来源:origin: dremio/dremio-oss

public void setChannelCloseHandler(ChannelFutureListener closeHandler) {
 channel.closeFuture().addListener(closeHandler);
}

代码示例来源:origin: org.projectreactor/reactor-tcp

@Override
public ConsumerSpec close(final Runnable onClose) {
  channel.closeFuture().addListener(new ChannelCloseListener(onClose));
  return this;
}

代码示例来源:origin: dremio/dremio-oss

@Override
public void addTerminationListener(GenericFutureListener<? extends Future<? super Void>> listener) {
 getChannel().closeFuture().addListener(listener);
}

代码示例来源:origin: org.projectreactor/reactor-tcp

@Override
  public ConsumerSpec writeIdle(long idleTimeout, final Runnable onWriteIdle) {
    final IdleWriteListener iwl = new IdleWriteListener(idleTimeout, onWriteIdle);
    channel.closeFuture().addListener(new ChannelFutureListener() {
      @Override
      public void operationComplete(ChannelFuture future) throws Exception {
        try {
          iwl.channelInactive(null);
        } catch(NullPointerException ignored) {}
      }
    });
    channel.pipeline().addLast(iwl);
    return this;
  }
}

代码示例来源:origin: addthis/hydra

@Override
  protected void initChannel(final SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (log.isTraceEnabled()) {
      log.trace("New socket connection {}", ch);
      ch.closeFuture().addListener(future -> log.trace("channel closed {}", ch));
    }
    pipeline.addLast("decoder", new HttpRequestDecoder(maxInitialLineLength,maxHeaderSize,maxChunkSize));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(maxContentLength));
    // compression is neat, but a little buggy
//        pipeline.addLast(ImmediateEventExecutor.INSTANCE, "compressor", new HttpContentCompressor());
    pipeline.addLast("query", httpQueryHandler);

  }
}

代码示例来源:origin: cdapio/cdap

@Override
 protected void initChannel(SocketChannel ch) throws Exception {
  ch.closeFuture().addListener(onCloseResetListener);
  ChannelPipeline pipeline = ch.pipeline();
  SslHandler sslHandler = getSslHandler(discoverable, ch.alloc());
  if (sslHandler != null) {
   pipeline.addLast("ssl", sslHandler);
  }
  pipeline.addLast("idle-state-handler",
           new IdleStateHandler(0, 0, cConf.getInt(Constants.Router.CONNECTION_TIMEOUT_SECS)));
  pipeline.addLast("codec", new HttpClientCodec());
  pipeline.addLast("forwarder", new OutboundHandler(inboundChannel));
 }
});

代码示例来源:origin: org.projectreactor/reactor-tcp

@Override
public ConsumerSpec readIdle(long idleTimeout, final Runnable onReadIdle) {
  final IdleReadListener irl = new IdleReadListener(idleTimeout, onReadIdle);
  channel.closeFuture().addListener(new ChannelFutureListener() {
    @Override
    public void operationComplete(ChannelFuture future) throws Exception {
      try {
        irl.channelInactive(null);
      } catch(NullPointerException ignored) {}
    }
  });
  channel.pipeline().addFirst(irl);
  return this;
}

代码示例来源:origin: dremio/dremio-oss

@Override
public void removeTerminationListener(GenericFutureListener<? extends Future<? super Void>> listener) {
 getChannel().closeFuture().removeListener(listener);
}

代码示例来源:origin: digitalpetri/modbus

@Override
  protected void initChannel(SocketChannel channel) throws Exception {
    channelCounter.inc();
    logger.info("channel initialized: {}", channel);
    channel.pipeline().addLast(new LoggingHandler(LogLevel.TRACE));
    channel.pipeline().addLast(new ModbusTcpCodec(new ModbusResponseEncoder(), new ModbusRequestDecoder()));
    channel.pipeline().addLast(new ModbusTcpSlaveHandler(ModbusTcpSlave.this));
    channel.closeFuture().addListener(future -> channelCounter.dec());
  }
};

代码示例来源:origin: dremio/dremio-oss

@Override
public void connectionSucceeded(final ServerConnection connection) {
 connection.getChannel().closeFuture().addListener(
   new GenericFutureListener<Future<? super Void>>() {
    @Override
    public void operationComplete(Future<? super Void> future)
      throws Exception {
     for (final UserResultsListener listener : queryIdToResultsListenersMap.values()) {
      listener.submissionFailed(UserException.connectionError()
        .message("Connection %s closed unexpectedly. SabotNode down?",
          connection.getName())
        .build(logger));
      if (listener instanceof BufferingResultsListener) {
       // the appropriate listener will be failed by SubmissionListener#failed
       logger.warn("Buffering listener failed before results were transferred to the actual listener.");
      }
     }
    }
   });
 parentHandler.connectionSucceeded(connection);
}

代码示例来源:origin: dremio/dremio-oss

@Override
 protected void initChannel(SocketChannel ch) throws Exception {
  connection = initRemoteConnection(ch);
  // each handler in the pipeline is created per connection
  ch.closeFuture().addListener(newCloseListener(ch, connection));
  final ChannelPipeline pipe = ch.pipeline();
  pipe.addLast(PROTOCOL_ENCODER, new RpcEncoder("c-" + rpcConfig.getName()));
  pipe.addLast(PROTOCOL_DECODER, newDecoder(connection.getAllocator()));
  pipe.addLast(HANDSHAKE_HANDLER, new ClientHandshakeHandler());
  if (timeoutInMillis != -1) {
   pipe.addLast(IDLE_STATE_HANDLER, new IdlePingHandler(timeoutInMillis));
  }
  pipe.addLast(MESSAGE_HANDLER, new InboundHandler(connection));
  pipe.addLast(EXCEPTION_HANDLER, new RpcExceptionHandler<>(connection));
 }
});

代码示例来源:origin: org.projectreactor/reactor-tcp

@Override
  public void initChannel(final SocketChannel ch) throws Exception {
    ch.config().setConnectTimeoutMillis(options.timeout());
    if(null != sslOpts) {
      SSLEngine ssl = new SSLEngineSupplier(sslOpts, true).get();
      log.debug("SSL enabled using keystore {}",
           (null != sslOpts.keystoreFile() ? sslOpts.keystoreFile() : "<DEFAULT>"));
      ch.pipeline().addLast(new SslHandler(ssl));
    }
    if(options instanceof NettyClientSocketOptions && null != ((NettyClientSocketOptions)options)
        .pipelineConfigurer()) {
      ((NettyClientSocketOptions)options).pipelineConfigurer().accept(ch.pipeline());
    }
    ch.pipeline().addLast(createChannelHandlers(ch));
    ch.closeFuture().addListener(new ChannelFutureListener() {
      @Override
      public void operationComplete(ChannelFuture future) throws Exception {
        connections.remove(ch);
      }
    });
  }
});

代码示例来源:origin: org.projectreactor/reactor-net

ch.closeFuture().addListener(new ChannelFutureListener() {
  @Override
  public void operationComplete(ChannelFuture future) throws Exception {

代码示例来源:origin: org.projectreactor/reactor-tcp

ch.closeFuture().addListener(new ChannelFutureListener() {
  @Override
  public void operationComplete(ChannelFuture future) throws Exception {

代码示例来源:origin: org.neo4j/neo4j-causal-clustering

private NettyHandshakeServer createHandshakeServer( SocketChannel channel )
{
  HandshakeServer handshakeServer = new HandshakeServer(
      applicationProtocolRepository,
      modifierProtocolRepository,
      new SimpleNettyChannel( channel, log )
  );
  handshakeServer.protocolStackFuture().whenComplete( ( protocolStack, failure ) -> onHandshakeComplete( protocolStack, channel, failure ) );
  channel.closeFuture().addListener( f -> {
    try
    {
      channel.parent().pipeline().fireUserEventTriggered(
          new ServerHandshakeFinishedEvent.Closed( toSocketAddress( channel ) ) );
    }
    catch ( RejectedExecutionException ignored )
    {
    }
  } );
  return new NettyHandshakeServer( handshakeServer );
}

代码示例来源:origin: wizardjedi/my-spring-learning

ch.closeFuture().addListener(new GenericFutureListener() {
  @Override
  public void operationComplete(Future future) throws Exception {

相关文章