/** * Immediately call the passed callback with a {@link NettyContext} to operate on the * underlying * {@link Channel} state. This allows for chaining outbound API. * * @param contextCallback context callback * * @return the {@link NettyContext} */ default NettyOutbound context(Consumer<NettyContext> contextCallback){ contextCallback.accept(context()); return this; }
/** * Assign a {@link Runnable} to be invoked when writes have become idle for the given * timeout. This replaces any previously set idle callback. * * @param idleTimeout the idle timeout * @param onWriteIdle the idle timeout handler * * @return {@literal this} */ default NettyOutbound onWriteIdle(long idleTimeout, Runnable onWriteIdle) { context().removeHandler(NettyPipeline.OnChannelWriteIdle); context().addHandlerFirst(NettyPipeline.OnChannelWriteIdle, new ReactorNetty.OutboundIdleStateHandler(idleTimeout, onWriteIdle)); return this; }
/** * Return the assigned {@link ByteBufAllocator}. * * @return the {@link ByteBufAllocator} */ default ByteBufAllocator alloc() { return context().channel() .alloc(); }
OutboundThen(NettyOutbound source, Publisher<Void> thenPublisher) { this.sourceContext = source.context(); Mono<Void> parentMono = source.then(); if (parentMono == Mono.<Void>empty()) { this.thenMono = Mono.from(thenPublisher); } else { this.thenMono = parentMono.thenEmpty(thenPublisher); } }
/** * Send data to the peer, listen for any error on write and close on terminal signal * (complete|error). * Note: Nesting any send* method is not supported. * * @param msg the object to publish * * @return A {@link Mono} to signal successful sequence write (e.g. after "flush") or * any error during write */ default NettyOutbound sendObject(Object msg) { context().onClose(() -> ReactorNetty.safeRelease(msg)); return then(FutureMono.deferFuture(() -> context().channel() .writeAndFlush(msg))); }
/** * Provide a new {@link NettyOutbound} scoped configuration for sending. The * {@link NettyPipeline.SendOptions} changes will apply to the next written object or * {@link Publisher}. * * @param configurator the callback invoked to retrieve send configuration * * @return {@code this} instance */ default NettyOutbound options(Consumer<? super NettyPipeline.SendOptions> configurator) { context().channel() .pipeline() .fireUserEventTriggered(new NettyPipeline.SendOptionsChangeEvent(configurator, null)); return this; }
/** * Send Object to the peer, listen for any error on write and close on terminal signal * (complete|error). If more than one publisher is attached (multiple calls to send()) * completion occurs after all publishers complete. * Note: Nesting any send* method is not supported. * * @param dataStream the dataStream publishing Buffer items to write on this channel * * @return A Publisher to signal successful sequence write (e.g. after "flush") or any * error during write */ default NettyOutbound sendObject(Publisher<?> dataStream) { return then(FutureMono.disposableWriteAndFlush(context().channel(), dataStream)); }
if ((context().channel().pipeline().get(SslHandler.class) != null) || context().channel().pipeline().get(NettyPipeline.CompressionHandler) != null || (!(context().channel().eventLoop() instanceof NioEventLoop) && !"file".equals(file.toUri().getScheme()))) { final FileChunkedStrategy<?> strategy = getFileChunkedStrategy(); strategy.preparePipeline(context()); return FutureMono.from(context().channel().writeAndFlush(message)); return FutureMono.from(context().channel() .writeAndFlush(new DefaultFileRegion(fc, position, count))); if (context().channel() .pipeline() .get(NettyPipeline.ChunkedWriter) != null) { getFileChunkedStrategy().cleanupPipeline(context());