当前位置: 首页>>代码示例>>Java>>正文


Java ChannelConfig类代码示例

本文整理汇总了Java中io.netty.channel.ChannelConfig的典型用法代码示例。如果您正苦于以下问题:Java ChannelConfig类的具体用法?Java ChannelConfig怎么用?Java ChannelConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ChannelConfig类属于io.netty.channel包,在下文中一共展示了ChannelConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exceptionCaught

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    final ChannelConfig config = ctx.channel().config();
    if (config.isAutoRead()) {
        // stop accept new connections for 1 second to allow the channel to recover
        // See https://github.com/netty/netty/issues/1328
        config.setAutoRead(false);
        ctx.channel().eventLoop().schedule(new Runnable() {
            @Override
            public void run() {
               config.setAutoRead(true);
            }
        }, 1, TimeUnit.SECONDS);
    }
    // still let the exceptionCaught event flow through the pipeline to give the user
    // a chance to do something with it
    ctx.fireExceptionCaught(cause);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:19,代码来源:ServerBootstrap.java

示例2: exceptionCaught

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    final ChannelConfig config = ctx.channel().config();
    if (config.isAutoRead()) {
        // stop accept new connections for 1 second to allow the channel to recover
        // See https://github.com/netty/netty/issues/1328
        config.setAutoRead(false);
        ctx.channel().eventLoop().schedule(new Runnable() {
            @Override
            public void run() {
                config.setAutoRead(true);
            }
        }, 1, TimeUnit.SECONDS);
    }
    // still let the exceptionCaught event flow through the pipeline to give the user
    // a chance to do something with it
    ctx.fireExceptionCaught(cause);
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:19,代码来源:ServerBootstrap.java

示例3: resume

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void resume() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        ChannelConfig chconf = unit.mock(ChannelConfig.class);
        expect(chconf.isAutoRead()).andReturn(false);
        expect(chconf.setAutoRead(true)).andReturn(chconf);

        Channel ch = unit.mock(Channel.class);
        expect(ch.config()).andReturn(chconf);

        ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
        expect(ctx.channel()).andReturn(ch);
      })
      .run(unit -> {
        new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).resume();
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:23,代码来源:NettyWebSocketTest.java

示例4: resumeIgnored

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void resumeIgnored() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        ChannelConfig chconf = unit.mock(ChannelConfig.class);
        expect(chconf.isAutoRead()).andReturn(true);

        Channel ch = unit.mock(Channel.class);
        expect(ch.config()).andReturn(chconf);

        ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
        expect(ctx.channel()).andReturn(ch);
      })
      .run(unit -> {
        new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).resume();
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:NettyWebSocketTest.java

示例5: pause

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void pause() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        ChannelConfig chconf = unit.mock(ChannelConfig.class);
        expect(chconf.isAutoRead()).andReturn(true);
        expect(chconf.setAutoRead(false)).andReturn(chconf);

        Channel ch = unit.mock(Channel.class);
        expect(ch.config()).andReturn(chconf);

        ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
        expect(ctx.channel()).andReturn(ch);
      })
      .run(unit -> {
        new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).pause();
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:23,代码来源:NettyWebSocketTest.java

示例6: pauseIgnored

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void pauseIgnored() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        ChannelConfig chconf = unit.mock(ChannelConfig.class);
        expect(chconf.isAutoRead()).andReturn(false);

        Channel ch = unit.mock(Channel.class);
        expect(ch.config()).andReturn(chconf);

        ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
        expect(ctx.channel()).andReturn(ch);
      })
      .run(unit -> {
        new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).pause();
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:NettyWebSocketTest.java

示例7: setSoLingerChannelOption

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@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());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:NettyClientTransportTest.java

示例8: setBufferSizeIfConfigIsSocketChannelConfig

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
private void setBufferSizeIfConfigIsSocketChannelConfig(
		ChannelConfig config, long contentLength) {
	if (config instanceof SocketChannelConfig) {
		int sendBufferSize = contentLength < m_maxSendBufferSize ? (int) contentLength
				: m_maxSendBufferSize;
		((SocketChannelConfig) config).setSendBufferSize(sendBufferSize);
	}
}
 
开发者ID:eBay,项目名称:ServiceCOLDCache,代码行数:9,代码来源:NettyRequestProxyFilter.java

示例9: run

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
public void run() {
    ChannelConfig config = ctx.channel().config();
    if (!config.isAutoRead() && isHandlerActive(ctx)) {
        // If AutoRead is False and Active is True, user make a direct setAutoRead(false)
        // Then Just reset the status
        if (logger.isDebugEnabled()) {
            logger.debug("Not unsuspend: " + config.isAutoRead() + ':' +
                    isHandlerActive(ctx));
        }
        ctx.attr(READ_SUSPENDED).set(false);
    } else {
        // Anything else allows the handler to reset the AutoRead
        if (logger.isDebugEnabled()) {
            if (config.isAutoRead() && !isHandlerActive(ctx)) {
                logger.debug("Unsuspend: " + config.isAutoRead() + ':' +
                        isHandlerActive(ctx));
            } else {
                logger.debug("Normal unsuspend: " + config.isAutoRead() + ':'
                        + isHandlerActive(ctx));
            }
        }
        ctx.attr(READ_SUSPENDED).set(false);
        config.setAutoRead(true);
        ctx.channel().read();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Unsupsend final status => " + config.isAutoRead() + ':'
                + isHandlerActive(ctx));
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:32,代码来源:AbstractTrafficShapingHandler.java

示例10: runLineBasedFrameDecoder

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
private static void runLineBasedFrameDecoder() {

        TcpServer<String, String> transport = Netty4TcpServer.<String, String>create(
                0,
                new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel channel) throws Exception {
                        int bufferSize = 1;
                        ChannelConfig config = channel.config();
                        config.setOption(ChannelOption.SO_RCVBUF, bufferSize);
                        config.setOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(bufferSize));
                        channel.pipeline().addFirst(
                                new LineBasedFrameDecoder(256),
                                new StringDecoder(CharsetUtil.UTF_8),
                                new StringEncoder(CharsetUtil.UTF_8));
                    }
                });

        ReactorTcpServer.create(transport).start(connection -> {
            connection.log("input")
                    .observeComplete(v -> LOG.info("Connection input complete"))
                    .capacity(1)
                    .consume(line -> {
                        String response = "Hello " + line + "\n";
                        Streams.wrap(connection.writeWith(Streams.just(response))).consume();
                    });
            return Streams.never();
        });
    }
 
开发者ID:reactive-ipc,项目名称:reactive-ipc-jvm,代码行数:30,代码来源:CodecSample.java

示例11: configure

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
private <T extends Channel> T configure(T channel) {
    ChannelConfig channelConfig = channel.config();

    if (connectTimeout != null) {
        channelConfig.setConnectTimeoutMillis(connectTimeout);
    }

    return channel;
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:10,代码来源:NettyDockerCmdExecFactory.java

示例12: configure

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
private <T extends Channel> T configure(T channel) {
    ChannelConfig channelConfig = channel.config();

    if (connectTimeout != null) {
        channelConfig.setConnectTimeoutMillis(connectTimeout);
    }
    // START of new readTimeout code
    if (readTimeout != null) {
        channel.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler());
    }
    // END of new readTimeout code

    return channel;
}
 
开发者ID:jenkinsci,项目名称:docker-plugin,代码行数:15,代码来源:NettyDockerCmdExecFactory.java

示例13: resume

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
public void resume() {
  ChannelConfig config = ctx.channel().config();
  if (!config.isAutoRead()) {
    config.setAutoRead(true);
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:8,代码来源:NettyWebSocket.java

示例14: pause

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
public void pause() {
  ChannelConfig config = ctx.channel().config();
  if (config.isAutoRead()) {
    config.setAutoRead(false);
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:8,代码来源:NettyWebSocket.java

示例15: config

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
public ChannelConfig config() {
    return null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:Netty4HttpChannelTests.java


注:本文中的io.netty.channel.ChannelConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。