@Override public Mono<CloseableChannel> start(ConnectionAcceptor acceptor) { Objects.requireNonNull(acceptor, "acceptor must not be null"); return server .doOnConnection( c -> { c.addHandlerLast(new RSocketLengthCodec()); TcpDuplexConnection connection = new TcpDuplexConnection(c); acceptor.apply(connection).then(Mono.<Void>never()).subscribe(c.disposeSubscriber()); }) .bind() .map(CloseableChannel::new); } }
/** * Attach an IO handler to react on connected client * * @param handler an IO handler that can dispose underlying connection when {@link * Publisher} terminates. * * @return a new {@link TcpClient} */ public final TcpClient handle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler) { Objects.requireNonNull(handler, "handler"); return doOnConnected(c -> { if (log.isDebugEnabled()) { log.debug(format(c.channel(), "Handler is being applied: {}"), handler); } Mono.fromDirect(handler.apply((NettyInbound) c, (NettyOutbound) c)) .subscribe(c.disposeSubscriber()); }); }
/** * Attach an IO handler to react on connected client * * @param handler an IO handler that can dispose underlying connection when {@link * Publisher} terminates. * * @return a new {@link UdpClient} */ public final UdpClient handle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) { Objects.requireNonNull(handler, "handler"); return doOnConnected(c -> { if (log.isDebugEnabled()) { log.debug(format(c.channel(), "Handler is being applied: {}"), handler); } Mono.fromDirect(handler.apply((UdpInbound) c, (UdpOutbound) c)) .subscribe(c.disposeSubscriber()); }); }
/** * Attach an IO handler to react on connected client * * @param handler an IO handler that can dispose underlying connection when {@link * Publisher} terminates. * * @return a new {@link UdpClient} */ public final UdpClient handle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) { Objects.requireNonNull(handler, "handler"); return doOnConnected(c -> { if (log.isDebugEnabled()) { log.debug(format(c.channel(), "Handler is being applied: {}"), handler); } Mono.fromDirect(handler.apply((UdpInbound) c, (UdpOutbound) c)) .subscribe(c.disposeSubscriber()); }); }
/** * Attach an IO handler to react on connected client * * @param handler an IO handler that can dispose underlying connection when {@link * Publisher} terminates. * * @return a new {@link UdpServer} */ public final UdpServer handle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) { Objects.requireNonNull(handler, "handler"); return doOnBound(c -> { if (log.isDebugEnabled()) { log.debug(format(c.channel(), "Handler is being applied: {}"), handler); } Mono.fromDirect(handler.apply((UdpInbound) c, (UdpOutbound) c)) .subscribe(c.disposeSubscriber()); }); }
/** * Attach an IO handler to react on connected client * * @param handler an IO handler that can dispose underlying connection when {@link * Publisher} terminates. * * @return a new {@link TcpClient} */ public final TcpClient handle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler) { Objects.requireNonNull(handler, "handler"); return doOnConnected(c -> { if (log.isDebugEnabled()) { log.debug(format(c.channel(), "Handler is being applied: {}"), handler); } Mono.fromDirect(handler.apply((NettyInbound) c, (NettyOutbound) c)) .subscribe(c.disposeSubscriber()); }); }
/** * Attach an IO handler to react on connected client * * @param handler an IO handler that can dispose underlying connection when {@link * Publisher} terminates. * * @return a new {@link UdpServer} */ public final UdpServer handle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) { Objects.requireNonNull(handler, "handler"); return doOnBound(c -> { if (log.isDebugEnabled()) { log.debug(format(c.channel(), "Handler is being applied: {}"), handler); } Mono.fromDirect(handler.apply((UdpInbound) c, (UdpOutbound) c)) .subscribe(c.disposeSubscriber()); }); }
@Override public Mono<CloseableChannel> start(ConnectionAcceptor acceptor) { Objects.requireNonNull(acceptor, "acceptor must not be null"); return server .doOnConnection( c -> { c.addHandlerLast(new RSocketLengthCodec()); TcpDuplexConnection connection = new TcpDuplexConnection(c); acceptor.apply(connection).then(Mono.<Void>never()).subscribe(c.disposeSubscriber()); }) .bind() .map(CloseableChannel::new); } }
@Override @SuppressWarnings("unchecked") public void onStateChange(Connection connection, State newState) { if (newState == State.CONFIGURED) { try { if (log.isDebugEnabled()) { log.debug(format(connection.channel(), "Handler is being applied: {}"), handler); } Mono.fromDirect(handler.apply(connection.inbound(), connection.outbound())) .subscribe(connection.disposeSubscriber()); } catch (Throwable t) { log.error(format(connection.channel(), ""), t); connection.channel() .close(); } } } }
@Override @SuppressWarnings("unchecked") public void onStateChange(Connection connection, State newState) { if (newState == State.CONFIGURED) { try { if (log.isDebugEnabled()) { log.debug(format(connection.channel(), "Handler is being applied: {}"), handler); } Mono.fromDirect(handler.apply(connection.inbound(), connection.outbound())) .subscribe(connection.disposeSubscriber()); } catch (Throwable t) { log.error(format(connection.channel(), ""), t); connection.channel() .close(); } } } }
@Override @SuppressWarnings("unchecked") public void onStateChange(Connection connection, State newState) { if (newState == HttpClientState.RESPONSE_RECEIVED) { sink.success(connection); return; } if (newState == State.CONFIGURED && HttpClientOperations.class == connection.getClass()) { if (log.isDebugEnabled()) { log.debug(format(connection.channel(), "Handler is being applied: {}"), handler); } handler.channel(connection.channel()); // Mono.fromDirect(initializer.upgraded) // .then(Mono.defer(() -> Mono.fromDirect(handler.requestWithBody((HttpClientOperations)connection)))) // .subscribe(connection.disposeSubscriber()); Mono.defer(() -> Mono.fromDirect(handler.requestWithBody((HttpClientOperations)connection))) .subscribe(connection.disposeSubscriber()); } } }
@Override @SuppressWarnings("unchecked") public void onStateChange(Connection connection, State newState) { if (newState == HttpClientState.RESPONSE_RECEIVED) { sink.success(connection); return; } if (newState == State.CONFIGURED && HttpClientOperations.class == connection.getClass()) { if (log.isDebugEnabled()) { log.debug(format(connection.channel(), "Handler is being applied: {}"), handler); } handler.channel(connection.channel()); // Mono.fromDirect(initializer.upgraded) // .then(Mono.defer(() -> Mono.fromDirect(handler.requestWithBody((HttpClientOperations)connection)))) // .subscribe(connection.disposeSubscriber()); Mono.defer(() -> Mono.fromDirect(handler.requestWithBody((HttpClientOperations)connection))) .subscribe(connection.disposeSubscriber()); } } }