Java 类io.netty.channel.socket.SocketChannelConfig 实例源码

项目:grpc-java    文件:NettyClientTransportTest.java   
@Test
public void setSoLingerChannelOption() throws IOException {
  startServer();
  Map<ChannelOption<?>, Object> channelOptions = new HashMap<ChannelOption<?>, Object>();
  // set SO_LINGER option
  int soLinger = 123;
  channelOptions.put(ChannelOption.SO_LINGER, soLinger);
  NettyClientTransport transport = new NettyClientTransport(
      address, NioSocketChannel.class, channelOptions, group, newNegotiator(),
      DEFAULT_WINDOW_SIZE, DEFAULT_MAX_MESSAGE_SIZE, GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE,
      KEEPALIVE_TIME_NANOS_DISABLED, 1L, false, authority, null /* user agent */,
      tooManyPingsRunnable, new TransportTracer());
  transports.add(transport);
  callMeMaybe(transport.start(clientTransportListener));

  // verify SO_LINGER has been set
  ChannelConfig config = transport.channel().config();
  assertTrue(config instanceof SocketChannelConfig);
  assertEquals(soLinger, ((SocketChannelConfig) config).getSoLinger());
}
项目:ServiceCOLDCache    文件:NettyRequestProxyFilter.java   
private void setBufferSizeIfConfigIsSocketChannelConfig(
        ChannelConfig config, long contentLength) {
    if (config instanceof SocketChannelConfig) {
        int sendBufferSize = contentLength < m_maxSendBufferSize ? (int) contentLength
                : m_maxSendBufferSize;
        ((SocketChannelConfig) config).setSendBufferSize(sendBufferSize);
    }
}
项目:folsom    文件:TcpTuningHandler.java   
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
  final SocketChannelConfig config = (SocketChannelConfig) ctx.channel().config();

  // Disable Nagle's algorithm
  config.setTcpNoDelay(true);

  // Setup TCP keepalive
  config.setKeepAlive(true);

  super.channelActive(ctx);

  // Our work is done
  ctx.channel().pipeline().remove(this);
}
项目:ServiceCOLDCache    文件:NettyRequestProxyFilterTest.java   
@Test
public void testFilterRequest() throws IOException {
    AppConfiguration appConfig = new AppConfiguration(new ConfigLoader(),
            null);
    appConfig.init();

    PolicyManager policyManager = mock(PolicyManager.class);
    NettyRequestProxyFilter filter = new NettyRequestProxyFilter(
            policyManager, appConfig);

    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    when(ctx.attr(any(AttributeKey.class))).thenReturn(
            mock(Attribute.class));
    assertNull(filter.filterRequest(mock(HttpRequest.class), ctx));

    DefaultFullHttpRequest req = new DefaultFullHttpRequest(
            HttpVersion.HTTP_1_1, HttpMethod.GET, "http://test.ebay.com/s/");
    when(policyManager.cacheIsNeededFor(any(CacheDecisionObject.class)))
            .thenReturn(false);
    assertNull(filter.filterRequest(req, ctx));

    when(policyManager.cacheIsNeededFor(any(CacheDecisionObject.class)))
            .thenReturn(true);
    CacheManager cm = mock(CacheManager.class);
    when(policyManager.getCacheManager()).thenReturn(cm);
    assertNull(filter.filterRequest(req, ctx));

    FullHttpResponse resp = mock(FullHttpResponse.class);
    HttpHeaders respHeaders = mock(HttpHeaders.class);
    when(resp.headers()).thenReturn(respHeaders);
    when(respHeaders.get(any(CharSequence.class))).thenReturn("100");
    when(cm.get(anyString())).thenReturn(resp);
    Channel channel = mock(Channel.class);
    SocketChannelConfig config = mock(SocketChannelConfig.class);
    when(channel.config()).thenReturn(config);
    when(ctx.channel()).thenReturn(channel);
    req.headers().add("h1", "v1");

    when(resp.content()).thenReturn(
            new EmptyByteBuf(new PooledByteBufAllocator())).thenReturn(
            Unpooled.copiedBuffer("Hello".getBytes()));
    assertEquals(resp, filter.filterRequest(req, ctx));
    assertEquals(resp, filter.filterRequest(req, ctx));
}
项目:spring4-understanding    文件:Netty4ClientHttpRequestFactory.java   
/**
 * Template method for changing properties on the given {@link SocketChannelConfig}.
 * <p>The default implementation sets the connect timeout based on the set property.
 * @param config the channel configuration
 */
protected void configureChannel(SocketChannelConfig config) {
    if (this.connectTimeout >= 0) {
        config.setConnectTimeoutMillis(this.connectTimeout);
    }
}
项目:java-restify    文件:NettyBootstrapFactory.java   
private void configure(SocketChannelConfig channelConfiguration) {
    channelConfiguration.setConnectTimeoutMillis(nettyHttpClientRequestConfiguration.connectionTimeout());
}
项目:haven-platform    文件:NettyRequestFactory.java   
/**
 * Template method for changing properties on the given {@link SocketChannelConfig}.
 * <p>The default implementation sets the connect timeout based on the set property.
 * @param config the channel configuration
 */
protected void configureChannel(SocketChannelConfig config) {
    if (this.connectTimeout >= 0) {
        config.setConnectTimeoutMillis(this.connectTimeout);
    }
}
项目:netty4.0.27Learn    文件:NioSocketChannel.java   
@Override
public SocketChannelConfig config() {
    return config;
}
项目:netty4study    文件:NioSocketChannel.java   
@Override
public SocketChannelConfig config() {
    return config;
}
项目:netty-netty-5.0.0.Alpha1    文件:NioSocketChannel.java   
@Override
public SocketChannelConfig config() {
    return config;
}
项目:netty-xnio-transport    文件:AbstractXnioSocketChannel.java   
@Override
public SocketChannelConfig config() {
    return config;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setTcpNoDelay(boolean tcpNoDelay) {
    channel.setOption(Options.TCP_NODELAY, tcpNoDelay);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setSoLinger(int soLinger) {
    throw new UnsupportedOperationException();
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setSendBufferSize(int sendBufferSize) {
    channel.setOption(Options.SEND_BUFFER, sendBufferSize);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
    channel.setOption(Options.RECEIVE_BUFFER, receiveBufferSize);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setKeepAlive(boolean keepAlive) {
    channel.setOption(Options.KEEP_ALIVE, keepAlive);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setTrafficClass(int trafficClass) {
    channel.setOption(Options.IP_TRAFFIC_CLASS, trafficClass);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setReuseAddress(boolean reuseAddress) {
    channel.setOption(Options.REUSE_ADDRESSES, reuseAddress);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
    throw new UnsupportedOperationException();
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setAllowHalfClosure(boolean allowHalfClosure) {
    throw new UnsupportedOperationException();
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
    super.setConnectTimeoutMillis(connectTimeoutMillis);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
    super.setMaxMessagesPerRead(maxMessagesPerRead);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setWriteSpinCount(int writeSpinCount) {
    super.setWriteSpinCount(writeSpinCount);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setAllocator(ByteBufAllocator allocator) {
    super.setAllocator(allocator);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
    super.setRecvByteBufAllocator(allocator);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setAutoRead(boolean autoRead) {
    super.setAutoRead(autoRead);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
    super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
    super.setMessageSizeEstimator(estimator);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
    super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
    return this;
}
项目:netty-xnio-transport    文件:XnioSocketChannelConfig.java   
@Override
public SocketChannelConfig setAutoClose(boolean autoClose) {
    super.setAutoClose(autoClose);
    return this;
}