use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project autobahn-java by crossbario.
the class NettyWebSocket method connect.
@Override
public void connect(ITransportHandler transportHandler, TransportOptions options) throws Exception {
if (options == null) {
if (mOptions == null) {
options = new TransportOptions();
} else {
options = new TransportOptions();
options.setAutoPingInterval(mOptions.getAutoPingInterval());
options.setAutoPingTimeout(mOptions.getAutoPingTimeout());
options.setMaxFramePayloadSize(mOptions.getMaxFramePayloadSize());
}
}
URI uri;
uri = new URI(mUri);
int port = validateURIAndGetPort(uri);
String scheme = uri.getScheme();
String host = uri.getHost();
final SslContext sslContext = getSSLContext(scheme);
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, mSerializers, true, new DefaultHttpHeaders(), options.getMaxFramePayloadSize());
mHandler = new NettyWebSocketClientHandler(handshaker, this, transportHandler);
EventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group);
bootstrap.channel(NioSocketChannel.class);
TransportOptions opt = options;
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline channelPipeline = ch.pipeline();
if (sslContext != null) {
channelPipeline.addLast(sslContext.newHandler(ch.alloc(), host, port));
}
channelPipeline.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), WebSocketClientCompressionHandler.INSTANCE, new IdleStateHandler(opt.getAutoPingInterval() + opt.getAutoPingTimeout(), opt.getAutoPingInterval(), 0, TimeUnit.SECONDS), mHandler);
}
});
mChannel = bootstrap.connect(uri.getHost(), port).sync().channel();
mHandler.getHandshakeFuture().sync();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project jim-framework by jiangmin168168.
the class RpcServerInitializer method initChannel.
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
// logger.info("RpcServerInitializer.initChannel");
ChannelPipeline pipeline = socketChannel.pipeline();
;
Executor executor = this.rpcThreadPoolFactory.getThreadPool(ConstantConfig.DEFAULT_THREAD_POOL_NAME).getExecutor(1, 1);
pipeline.addLast(new RpcEncoder(RpcResponse.class)).addLast(new RpcDecoder(RpcRequest.class)).addLast(new IdleStateHandler(Constants.READER_TIME_SECONDS, 0, 0)).addLast(new ServerHeartbeatHandler()).addLast(new RpcServerInvoker(this.handlerMap, this.filterMap, executor));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project duangframework by tcrct.
the class RpcChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
// 将 RPC 请求进行解码(为了处理请求)
p.addLast(new NettyDecoder());
// // 将 RPC 响应进行编码(为了返回响应)
p.addLast(new NettyEncoder());
// 目的是支持异步大文件传输
p.addLast(new ChunkedWriteHandler());
p.addLast(new IdleStateHandler(60, 0, 0));
// 真正处理RPC业务逻辑的地方
p.addLast(new NettyServiceHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project duangframework by tcrct.
the class ClientChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
// 将 RPC 请求进行解码(为了处理请求)
p.addLast(new NettyDecoder());
// // 将 RPC 响应进行编码(为了返回响应)
p.addLast(new NettyEncoder());
// 目的是支持异步大文件传输
p.addLast(new ChunkedWriteHandler());
p.addLast(new IdleStateHandler(60, 0, 0));
// 真正处理RPC业务逻辑的地方
p.addLast(new NettyClientHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project iris by chicc999.
the class NettyTransport method handler.
protected ChannelHandler handler() {
return new ChannelInitializer() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(config.getFrameMaxSize(), 0, 4, 0, 4));
ch.pipeline().addLast(new CommandDecoder());
ch.pipeline().addLast(new CommandEncoder());
ch.pipeline().addLast(new IdleStateHandler(0, 0, config.getChannelMaxIdleTime(), TimeUnit.MILLISECONDS));
ch.pipeline().addLast(dispatcherHandler);
ch.pipeline().addLast(connectionHandler);
}
};
}
Aggregations