Search in sources :

Example 1 with WriteTimeoutHandler

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();
    }
}
Also used : NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) WriteTimeoutHandler(io.netty.handler.timeout.WriteTimeoutHandler) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) HttpProxyServerHandle(com.wing.apirecord.core.handler.HttpProxyServerHandle) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 2 with WriteTimeoutHandler

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();
    }
}
Also used : WebSocketFrameAggregator(io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) WriteTimeoutHandler(io.netty.handler.timeout.WriteTimeoutHandler) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec)

Example 3 with WriteTimeoutHandler

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);
}
Also used : ReactorClientHttpConnector(org.springframework.http.client.reactive.ReactorClientHttpConnector) ClientHttpConnector(org.springframework.http.client.reactive.ClientHttpConnector) WriteTimeoutHandler(io.netty.handler.timeout.WriteTimeoutHandler) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) WebClient(org.springframework.web.reactive.function.client.WebClient) ReactorClientHttpConnector(org.springframework.http.client.reactive.ReactorClientHttpConnector) Bean(org.springframework.context.annotation.Bean)

Aggregations

WriteTimeoutHandler (io.netty.handler.timeout.WriteTimeoutHandler)3 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)2 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)2 ReadTimeoutHandler (io.netty.handler.timeout.ReadTimeoutHandler)2 HttpProxyServerHandle (com.wing.apirecord.core.handler.HttpProxyServerHandle)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)1 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)1 WebSocketFrameAggregator (io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator)1 Bean (org.springframework.context.annotation.Bean)1 ClientHttpConnector (org.springframework.http.client.reactive.ClientHttpConnector)1 ReactorClientHttpConnector (org.springframework.http.client.reactive.ReactorClientHttpConnector)1 WebClient (org.springframework.web.reactive.function.client.WebClient)1