本文整理汇总了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);
}
示例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);
}
示例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();
});
}
示例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();
});
}
示例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();
});
}
示例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();
});
}
示例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());
}
示例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);
}
}
示例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));
}
}
示例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();
});
}
示例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;
}
示例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;
}
示例13: resume
import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
public void resume() {
ChannelConfig config = ctx.channel().config();
if (!config.isAutoRead()) {
config.setAutoRead(true);
}
}
示例14: pause
import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
public void pause() {
ChannelConfig config = ctx.channel().config();
if (config.isAutoRead()) {
config.setAutoRead(false);
}
}
示例15: config
import io.netty.channel.ChannelConfig; //导入依赖的package包/类
@Override
public ChannelConfig config() {
return null;
}