@Override public ListenableFuture<Void> shutdown() { if (this.stopping) { SettableListenableFuture<Void> future = new SettableListenableFuture<>(); future.set(null); return future; } this.stopping = true; Mono<Void> result; if (this.channelGroup != null) { result = FutureMono.from(this.channelGroup.close()); if (this.loopResources != null) { result = result.onErrorResume(ex -> Mono.empty()).then(this.loopResources.disposeLater()); } if (this.poolResources != null) { result = result.onErrorResume(ex -> Mono.empty()).then(this.poolResources.disposeLater()); } result = result.onErrorResume(ex -> Mono.empty()).then(stopScheduler()); } else { result = stopScheduler(); } return new MonoToListenableFutureAdapter<>(result); }
@Override public NettyOutbound sendObject(Publisher<?> dataStream) { return then(FutureMono.deferFuture(() -> ch.channel() .writeAndFlush(dataStream))); }
@Override public NettyOutbound sendObject(Publisher<?> dataStream) { return then(FutureMono.disposableWriteAndFlush(connection.channel(), dataStream)); }
@Override public NettyOutbound sendObject(Publisher<?> dataStream) { return then(FutureMono.deferFuture(() -> ch.channel() .writeAndFlush(dataStream))); }
@Override public NettyOutbound sendObject(Publisher<?> dataStream) { return then(FutureMono.disposableWriteAndFlush(connection.channel(), dataStream)); }
/** * Creates a new instance * * @param connection the {@link Connection} to for managing the server */ public TcpDuplexConnection(Connection connection) { this.connection = Objects.requireNonNull(connection, "connection must not be null"); this.channelClosed = FutureMono.from(connection.channel().closeFuture()) .doFinally( s -> { if (!isDisposed()) { dispose(); } }) .subscribe(); }
@Override public Mono<Void> send() { if (markSentHeaderAndBody()) { HttpMessage response = newFullEmptyBodyMessage(); return FutureMono.deferFuture(() -> channel().writeAndFlush(response)); } else { return Mono.empty(); } }
@Override public Mono<Void> then() { ByteBufAllocator alloc = parent.channel().alloc(); return Flux.from(source) .collect(alloc::heapBuffer, ByteBuf::writeBytes) .flatMap(agg -> { if (!HttpUtil.isTransferEncodingChunked(request) && !HttpUtil.isContentLengthSet(request)) { request.headers() .setInt(HttpHeaderNames.CONTENT_LENGTH, agg.readableBytes()); } if (agg.readableBytes() > 0) { return parent.then().thenEmpty(FutureMono.disposableWriteAndFlush(parent.channel(), Mono.just(agg))); } agg.release(); return parent.then(); }); }
/** * Creates a new instance * * @param connection the {@link Connection} to for managing the server */ public WebsocketDuplexConnection(Connection connection) { this.connection = Objects.requireNonNull(connection, "connection must not be null"); this.channelClosed = FutureMono.from(connection.channel().closeFuture()) .doFinally( s -> { if (!isDisposed()) { dispose(); } }) .subscribe(); }
final Mono<Void> send() { if (markSentHeaderAndBody()) { HttpMessage request = newFullEmptyBodyMessage(); return FutureMono.deferFuture(() -> channel().writeAndFlush(request)); } else { return Mono.empty(); } }
@Override public Mono<Void> then() { ByteBufAllocator alloc = parent.channel().alloc(); return Flux.from(source) .collect(alloc::heapBuffer, ByteBuf::writeBytes) .flatMap(agg -> { if (!HttpUtil.isTransferEncodingChunked(request) && !HttpUtil.isContentLengthSet(request)) { request.headers() .setInt(HttpHeaderNames.CONTENT_LENGTH, agg.readableBytes()); } return parent.then().thenEmpty(FutureMono.disposableWriteAndFlush(parent.channel(), Mono.just(agg))); }); }
@Override public ListenableFuture<Void> shutdown() { if (this.stopping) { SettableListenableFuture<Void> future = new SettableListenableFuture<>(); future.set(null); return future; } this.stopping = true; Mono<Void> result; if (this.channelGroup != null) { result = FutureMono.from(this.channelGroup.close()); if (this.loopResources != null) { result = result.onErrorResume(ex -> Mono.empty()).then(this.loopResources.disposeLater()); } if (this.poolResources != null) { result = result.onErrorResume(ex -> Mono.empty()).then(this.poolResources.disposeLater()); } result = result.onErrorResume(ex -> Mono.empty()).then(stopScheduler()); } else { result = stopScheduler(); } return new MonoToListenableFutureAdapter<>(result); }
@Override public Mono<Void> send() { if (markSentHeaderAndBody()) { HttpMessage response = newFullEmptyBodyMessage(); return FutureMono.deferFuture(() -> channel().writeAndFlush(response)); } else { return Mono.empty(); } }
/** * Return an observing {@link Mono} terminating with success when shutdown * successfully or error. * * @return a {@link Mono} terminating with success if shutdown successfully or error */ default Mono<Void> onDispose() { return FutureMono.from(channel().closeFuture()); }
final Mono<Void> send() { if (markSentHeaderAndBody()) { HttpMessage request = newFullEmptyBodyMessage(); return FutureMono.deferFuture(() -> channel().writeAndFlush(request)); } else { return Mono.empty(); } }
@Override public Mono<Void> shutdown() { //noinspection unchecked return Mono.defer( () -> FutureMono.from((Future) ((EventLoopGroup) workerPool).shutdownGracefully())); }
@Override public NettyOutbound sendObject(Object message) { onTerminate().subscribe(null, null, () -> ReactorNetty.safeRelease(message)); return then(FutureMono.deferFuture(() -> connection.channel() .writeAndFlush(message))); }
@Override public Mono<Void> shutdown(Executor workerThreadPool) { //noinspection unchecked return Mono.defer( () -> workerThreadPool != null ? FutureMono.from((Future) ((EventLoopGroup) workerThreadPool).shutdownGracefully()) : Mono.empty()); } }
@Override public NettyOutbound sendObject(Object message) { onTerminate().subscribe(null, null, () -> ReactorNetty.safeRelease(message)); return then(FutureMono.deferFuture(() -> connection.channel() .writeAndFlush(message))); }
/** * Return an observing {@link Mono} terminating with success when shutdown * successfully or error. * * @return a {@link Mono} terminating with success if shutdown successfully or error */ default Mono<Void> onDispose() { return FutureMono.from(channel().closeFuture()); }