本文整理汇总了Java中io.netty.handler.timeout.ReadTimeoutHandler类的典型用法代码示例。如果您正苦于以下问题:Java ReadTimeoutHandler类的具体用法?Java ReadTimeoutHandler怎么用?Java ReadTimeoutHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReadTimeoutHandler类属于io.netty.handler.timeout包,在下文中一共展示了ReadTimeoutHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Client
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
/**
* 本地爬虫服务,长连接
*
* @param action
*/
public Client(@Nonnull final Action action){
isLongConnection = true;
final Client self = this;
this.action = action;
channelInitializer = new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ProtobufVarint32FrameDecoder());
ch.pipeline().addLast(new ProtobufDecoder(ProcessData.getDefaultInstance()));
ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender());
ch.pipeline().addLast(new ProtobufEncoder());
ch.pipeline().addLast(new ReadTimeoutHandler(60));
ch.pipeline().addLast(new LoginAuthReqHandler(channel));
ch.pipeline().addLast(new LocalCrawlerHandler(action));
ch.pipeline().addLast(new HeartBeatReqHandler(self, closeLongConnection));
}
};
}
示例2: NettyServer
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
private NettyServer(){
pGroup = new NioEventLoopGroup();
cGroup = new NioEventLoopGroup();
serverBootstrap = new ServerBootstrap();
serverBootstrap.group(pGroup, cGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
//设置日志
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(SocketChannel sc) throws Exception {
sc.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder());
sc.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingEncoder());
sc.pipeline().addLast(new ReadTimeoutHandler(60));
sc.pipeline().addLast(new NettyServerHandler());
}
});
}
示例3: initChannel
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
RPCChannelHandler channelHandler =
new RPCChannelHandler(syncManager, rpcService);
IdleStateHandler idleHandler =
new IdleStateHandler(5, 10, 0);
ReadTimeoutHandler readTimeoutHandler =
new ReadTimeoutHandler(30);
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("idle", idleHandler);
pipeline.addLast("timeout", readTimeoutHandler);
pipeline.addLast("handshaketimeout",
new HandshakeTimeoutHandler(channelHandler, timer, 10));
pipeline.addLast("syncMessageDecoder",
new SyncMessageDecoder(maxFrameSize));
pipeline.addLast("syncMessageEncoder",
new SyncMessageEncoder());
pipeline.addLast("handler", channelHandler);
}
示例4: initChannel
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
/**
* Adds pipelines to channel.
*
* @param ch channel to be operated on
*/
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipe = ch.pipeline();
if (ssl) {
// HTTPs connection
SSLEngine sslEng = getSsl(null);
sslEng.setUseClientMode(true);
pipe.addLast("SSL", new SslHandler(sslEng, false));
}
pipe.addFirst("Timer", new ReadTimeoutHandler(30));
pipe.addLast("Codec", new HttpClientCodec());
pipe.addLast("Inflater", new HttpContentDecompressor());
pipe.addLast("Handler", new HTTPMessageHandler(builder));
}
示例5: initChannel
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
@Override
public void initChannel(Channel ch) throws Exception
{
try
{
ch.config().setOption( ChannelOption.IP_TOS, 0x18 );
} catch ( ChannelException ex )
{
// IP_TOS is not supported (Windows XP / Windows Server 2003)
}
ch.config().setOption( ChannelOption.TCP_NODELAY, true );
ch.config().setAllocator( PooledByteBufAllocator.DEFAULT );
ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );
ch.pipeline().addLast( FRAME_PREPENDER, framePrepender );
ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
}
示例6: initChannel
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
RPCChannelHandler channelHandler =
new RPCChannelHandler(syncManager, rpcService);
IdleStateHandler idleHandler =
new IdleStateHandler(5, 10, 0);
ReadTimeoutHandler readTimeoutHandler =
new ReadTimeoutHandler(30);
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("idle", idleHandler);
pipeline.addLast("timeout", readTimeoutHandler);
pipeline.addLast("handshaketimeout",
new HandshakeTimeoutHandler(channelHandler, timer, 10));
pipeline.addLast("syncMessageDecoder",
new SyncMessageDecoder(maxFrameSize));
pipeline.addLast("syncMessageEncoder",
new SyncMessageEncoder());
pipeline.addLast("handler", channelHandler);
}
示例7: initChannel
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
}
pipeline.addLast(new HttpResponseEncoder());
pipeline.addLast(new HttpRequestDecoder());
// Uncomment the following line if you don't want to handle HttpChunks.
//pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
//p.addLast(new HttpObjectAggregator(1048576));
// Remove the following line if you don't want automatic content compression.
//pipeline.addLast(new HttpContentCompressor());
// Uncomment the following line if you don't want to handle HttpContents.
pipeline.addLast(new HttpObjectAggregator(65536));
pipeline.addLast("readTimeoutHandler", new ReadTimeoutHandler(READ_TIMEOUT));
pipeline.addLast("myHandler", new MyHandler());
pipeline.addLast("handler", new HttpServerHandler(listener));
}
示例8: provideHandlerProviders
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
@Provides
@EppProtocol
static ImmutableList<Provider<? extends ChannelHandler>> provideHandlerProviders(
Provider<SslServerInitializer<NioSocketChannel>> sslServerInitializerProvider,
Provider<ProxyProtocolHandler> proxyProtocolHandlerProvider,
@EppProtocol Provider<ReadTimeoutHandler> readTimeoutHandlerProvider,
Provider<LengthFieldBasedFrameDecoder> lengthFieldBasedFrameDecoderProvider,
Provider<LengthFieldPrepender> lengthFieldPrependerProvider,
Provider<EppServiceHandler> eppServiceHandlerProvider,
Provider<LoggingHandler> loggingHandlerProvider,
Provider<FullHttpRequestRelayHandler> relayHandlerProvider) {
return ImmutableList.of(
proxyProtocolHandlerProvider,
sslServerInitializerProvider,
readTimeoutHandlerProvider,
lengthFieldBasedFrameDecoderProvider,
lengthFieldPrependerProvider,
eppServiceHandlerProvider,
loggingHandlerProvider,
relayHandlerProvider);
}
示例9: modifyPipeLine
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
/**
* Modify the pipeline for the request
*
* @param req to process
* @param pipeline to modify
* @param <R> Type of Response
*/
private <R> void modifyPipeLine(final EtcdRequest<R> req, final ChannelPipeline pipeline) {
final EtcdResponseHandler<R> handler = new EtcdResponseHandler<>(this, req);
if (req.hasTimeout()) {
pipeline.addFirst(new ReadTimeoutHandler(req.getTimeout(), req.getTimeoutUnit()));
}
pipeline.addLast(handler);
pipeline.addLast(new ChannelHandlerAdapter() {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
handler.retried(true);
req.getPromise().handleRetry(cause);
}
});
}
示例10: initChannel
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc(), NettyPistachioClient.HOST, NettyPistachioClient.PORT));
}
LogLevel level = LogLevel.DEBUG;
p.addLast(new LoggingHandler(level));
p.addLast(new ReadTimeoutHandler(ConfigurationManager.getConfiguration().getInt("Network.Netty.ClientReadTimeoutMillis",10000), TimeUnit.MILLISECONDS));
p.addLast(new ProtobufVarint32FrameDecoder());
p.addLast(new ProtobufDecoder(NettyPistachioProtocol.Response.getDefaultInstance()));
p.addLast(new ProtobufVarint32LengthFieldPrepender());
p.addLast(new ProtobufEncoder());
p.addLast(new NettyPistachioClientHandler());
}
示例11: initChannel
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast("timeout", new ReadTimeoutHandler(15));
pipeline.addLast("codec-http", new HttpServerCodec());
pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
pipeline.addLast("handler", new HTTPHandler(plugin));
pipeline.addLast("websocket", new WebSocketServerProtocolHandler("/server"));
pipeline.addLast("packet-decoder", new PacketDecoder());
pipeline.addLast("packet-encoder", new PacketEncoder());
pipeline.addLast("packet-handler", new ClientHandler(socketChannel, plugin));
socketChannel.config().setAllocator(PooledByteBufAllocator.DEFAULT);
plugin.getWebHandler().getChannelGroup().add(socketChannel);
}
示例12: start
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
public void start() {
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup);
b.channel(NioServerSocketChannel.class);
b.childHandler(new ChannelInitializer<SocketChannel>() {
public void initChannel(SocketChannel ch) throws Exception {
IngotPlayer ingotPlayer = new IngotPlayer(ch);
ch.pipeline().addLast(new ReadTimeoutHandler(15));
ch.pipeline().addLast(new VarIntCodec());
ch.pipeline().addLast(ingotPlayer.packetCodec);
}
});
b.option(ChannelOption.SO_BACKLOG, 16);
b.childOption(ChannelOption.SO_KEEPALIVE, true);
future = b.bind(25565);
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例13: initChannel
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
p.addLast(new ReadTimeoutHandler(60, TimeUnit.SECONDS));
if (sslContext != null) {
p.addLast(sslContext.newHandler(ch.alloc()));
}
p.addLast(new HttpContentCompressor(5));
p.addLast(new HttpServerCodec());
p.addLast(new HttpObjectAggregator(1048576));
p.addLast(new ChunkedWriteHandler());
if (null != corsConfig) {
p.addLast(new CorsHandler(corsConfig));
}
p.addLast(new WebSocketServerCompressionHandler());
p.addLast(new WebSocketServerProtocolHandler(webSocketPath, null, true));
p.addLast(new LaputaServerHandler(null != sslContext, requestProcessor));
}
示例14: initChannel
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel channel) throws Exception {
channel.pipeline()
.addLast(new ReadTimeoutHandler(30))
.addLast("splitter", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4))
.addLast(new PacketDecoder())
.addLast("prepender", new LengthFieldPrepender(4))
.addLast(new PacketEncoder())
.addLast(client.getHandler());
this.client.setChannel(channel);
System.out.println("Netty client started");
}
示例15: init
import io.netty.handler.timeout.ReadTimeoutHandler; //导入依赖的package包/类
public void init(ChannelPipeline pipeline, String remoteId, boolean discoveryMode, ChannelManager channelManager) {
this.channelManager = channelManager;
this.remoteId = remoteId;
isActive = remoteId != null && !remoteId.isEmpty();
pipeline.addLast("readTimeoutHandler",
new ReadTimeoutHandler(config.peerChannelReadTimeout(), TimeUnit.SECONDS));
pipeline.addLast(stats.tcp);
pipeline.addLast("handshakeHandler", handshakeHandler);
this.discoveryMode = discoveryMode;
if (discoveryMode) {
// temporary key/nodeId to not accidentally smear our reputation with
// unexpected disconnect
// handshakeHandler.generateTempKey();
}
handshakeHandler.setRemoteId(remoteId, this);
messageCodec.setChannel(this);
msgQueue.setChannel(this);
p2pHandler.setMsgQueue(msgQueue);
messageCodec.setP2pMessageFactory(new P2pMessageFactory());
shhHandler.setMsgQueue(msgQueue);
messageCodec.setShhMessageFactory(new ShhMessageFactory());
bzzHandler.setMsgQueue(msgQueue);
messageCodec.setBzzMessageFactory(new BzzMessageFactory());
}