ch.eventLoop().execute(this::clearQueues);
@Override public void initChannel(SocketChannel ch) throws Exception { final ChannelPipeline p = ch.pipeline(); final Http2Connection conn = new DefaultHttp2Connection(false); final HttpToHttp2ConnectionHandler connHandler = new HttpToHttp2ConnectionHandlerBuilder() .connection(conn) .frameListener(new DelegatingDecompressorFrameListener( conn, new InboundHttp2ToHttpAdapterBuilder(conn) .maxContentLength(Integer.MAX_VALUE) .propagateSettings(true).build())) .build(); clientHandler = new THttp2ClientHandler(ch.eventLoop()); if (sslCtx != null) { p.addLast(sslCtx.newHandler(p.channel().alloc())); p.addLast(connHandler); configureEndOfPipeline(p); } else { final Http1ClientCodec sourceCodec = new Http1ClientCodec(); final HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler( sourceCodec, new Http2ClientUpgradeCodec(connHandler), 65536); p.addLast(sourceCodec, upgradeHandler, new UpgradeRequestHandler()); } }
boolean inEventLoop() { return channel.eventLoop().inEventLoop(); }
private void scheduleTimeout( SocketChannel ch, HandshakeClient handshakeClient ) { ch.eventLoop().schedule( () -> { if ( handshakeClient.failIfNotDone( "Timed out after " + timeout ) ) { log.warn( "Failed handshake after timeout" ); } }, timeout.toMillis(), TimeUnit.MILLISECONDS ); }
@Override protected <C> TcpConnection<IN, OUT> createConnection(C channel) { SocketChannel ch = (SocketChannel)channel; return new NettyTcpConnection<IN, OUT>( env, getCodec(), new NettyEventLoopDispatcher(ch.eventLoop()), eventsDispatcher, ch, connectAddress ); }
@Override protected <C> NettyTcpConnection<IN, OUT> createConnection(C channel) { SocketChannel ch = (SocketChannel)channel; return new NettyTcpConnection<IN, OUT>( env, getCodec(), new NettyEventLoopDispatcher(ch.eventLoop()), eventsDispatcher, ch ); }
@Override protected <C> NetChannel<IN, OUT> createChannel(C ioChannel) { SocketChannel ch = (SocketChannel) ioChannel; int backlog = getEnvironment().getProperty("reactor.tcp.connectionReactorBacklog", Integer.class, 128); return new NettyNetChannel<IN, OUT>( getEnvironment(), getCodec(), new NettyEventLoopDispatcher(ch.eventLoop(), backlog), getReactor(), ch ); }
ch.eventLoop().execute(this::clearQueues);
/** * schedules the handshake initiation after the connection attempt */ private void scheduleHandshake( SocketChannel ch, HandshakeClient handshakeClient, TimeoutStrategy.Timeout handshakeDelay ) { ch.eventLoop().schedule( () -> { if ( ch.isActive() ) { initiateHandshake( ch, handshakeClient ); } else if ( ch.isOpen() ) { handshakeDelay.increment(); scheduleHandshake( ch, handshakeClient, handshakeDelay ); } else { handshakeClient.failIfNotDone( "Channel closed" ); } }, handshakeDelay.getMillis(), MILLISECONDS ); }