• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ChannelConfig类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: config

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


示例17: config

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
public ChannelConfig config() {
	// TODO Auto-generated method stub
	return null;
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:6,代码来源:InvocationChannel.java


示例18: config

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


示例19: config

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


示例20: doRead

import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
protected void doRead() {
    final ChannelConfig config = config();
    final ChannelPipeline pipeline = pipeline();
    boolean closed = false;
    final int maxMessagesPerRead = config.getMaxMessagesPerRead();

    Throwable exception = null;
    int localRead = 0;
    int totalRead = 0;
    try {
        for (;;) {
            // Perform a read.
            localRead = doReadMessages(readBuf);
            if (localRead == 0) {
                break;
            }
            if (localRead < 0) {
                closed = true;
                break;
            }

            // Notify with the received messages and clear the buffer.
            int size = readBuf.size();
            for (int i = 0; i < size; i ++) {
                pipeline.fireChannelRead(readBuf.get(i));
            }
            readBuf.clear();

            // Do not read beyond maxMessagesPerRead.
            // Do not continue reading if autoRead has been turned off.
            totalRead += localRead;
            if (totalRead >= maxMessagesPerRead || !config.isAutoRead()) {
                break;
            }
        }
    } catch (Throwable t) {
        exception = t;
    }

    pipeline.fireChannelReadComplete();

    if (exception != null) {
        if (exception instanceof IOException) {
            closed = true;
        }

        pipeline().fireExceptionCaught(exception);
    }

    if (closed) {
        if (isOpen()) {
            unsafe().close(unsafe().voidPromise());
        }
    } else if (localRead == 0 && isActive()) {
        // If the read amount was 0 and the channel is still active we need to trigger a new read()
        // as otherwise we will never try to read again and the user will never know.
        // Just call read() is ok here as it will be submitted to the EventLoop as a task and so we are
        // able to process the rest of the tasks in the queue first.
        //
        // See https://github.com/netty/netty/issues/2404
        read();
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:65,代码来源:AbstractOioMessageChannel.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NetClient类代码示例发布时间:2022-05-21
下一篇:
Java GanttRenderer类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap