use of io.netty.handler.timeout.WriteTimeoutHandler in project apiRecord by tobecoder2015.
the class NettyHttpProxyServer method start.
public void start(int port) {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
// ChannelInboundHandlerAdapter
try {
init();
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast("httpCodec", new HttpServerCodec());
ch.pipeline().addLast(new ReadTimeoutHandler(10));
ch.pipeline().addLast(new WriteTimeoutHandler(10));
ch.pipeline().addLast("serverHandle", new HttpProxyServerHandle(proxyInterceptFactory.build()));
}
});
ChannelFuture f = b.bind(port).sync();
f.channel().closeFuture().sync();
} catch (Exception e) {
e.printStackTrace();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
use of io.netty.handler.timeout.WriteTimeoutHandler in project rskj by rsksmart.
the class Web3WebSocketServer method start.
@Override
public void start() {
logger.info("RPC WebSocket enabled");
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpServerCodec());
p.addLast(new HttpObjectAggregator(maxAggregatedFrameSize));
p.addLast(new WriteTimeoutHandler(serverWriteTimeoutSeconds, TimeUnit.SECONDS));
p.addLast(new RskWebSocketServerProtocolHandler("/websocket", maxFrameSize));
p.addLast(new WebSocketFrameAggregator(maxAggregatedFrameSize));
p.addLast(webSocketJsonRpcHandler);
p.addLast(web3ServerHandler);
p.addLast(new Web3ResultWebSocketResponseHandler());
}
});
webSocketChannel = b.bind(host, port);
try {
webSocketChannel.sync();
} catch (InterruptedException e) {
logger.error("The RPC WebSocket server couldn't be started", e);
Thread.currentThread().interrupt();
}
}
use of io.netty.handler.timeout.WriteTimeoutHandler in project JavaForFun by gumartinm.
the class ServicesConfig method webClientBuilder.
@Bean
public WebClient.Builder webClientBuilder() {
ClientHttpConnector connector = new ReactorClientHttpConnector(options -> {
options.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeOut).onChannelInit(channel -> {
channel.pipeline().addLast(new ReadTimeoutHandler(readTimeOut, TimeUnit.MILLISECONDS));
channel.pipeline().addLast(new WriteTimeoutHandler(writeTimeout, TimeUnit.MILLISECONDS));
return true;
});
});
WebClient.Builder webClientBuilder = WebClient.builder();
return webClientBuilder.clientConnector(connector);
}
Aggregations