/** * Remove a named handler if present and return this context * * @param name handler name * * @return this NettyContext */ default NettyContext removeHandler(String name) { ReactorNetty.removeHandler(channel(), name); 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)); }
/** * 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; }
/** * Assign a {@link Runnable} to be invoked when reads have become idle for the given * timeout. This replaces any previously set idle callback. * * @param idleTimeout the idle timeout * @param onReadIdle the idle timeout handler * * @return {@literal this} */ default NettyInbound onReadIdle(long idleTimeout, Runnable onReadIdle) { context().removeHandler(NettyPipeline.OnChannelReadIdle); context().addHandlerFirst(NettyPipeline.OnChannelReadIdle, new ReactorNetty.InboundIdleStateHandler(idleTimeout, onReadIdle)); return this; }
/** * A {@link Flux} extension that allows for extra decoding operators * @return a new {@link ByteBufFlux} */ default ByteBufFlux receive() { return ByteBufFlux.fromInbound(receiveObject(), context().channel() .alloc()); }
/** * Disable auto memory release on each buffer published, retaining in order to prevent * premature recycling when buffers are accumulated downstream (async). * * @return {@link ByteBufFlux} of retained {@link ByteBuf} */ public ByteBufFlux retain() { return new ByteBufFlux(doOnNext(ByteBuf::retain), alloc); }
/** * Send bytes 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 sendByteArray(Publisher<? extends byte[]> dataStream) { return send(ReactorNetty.publisherOrScalarMap(dataStream, Unpooled::wrappedBuffer)); }
/** * Return a pre-configured attribute stored in every inbound channel * @param key attribute key * @param <T> a channel attribute type * @return a {@link Channel} attribute * @see Channel#attr(AttributeKey) */ default <T> Attribute<T> attr(AttributeKey<T> key) { return context().channel() .attr(key); }
/** * Open a {@link java.nio.channels.FileChannel} from a path and stream * {@link ByteBuf} chunks with a default maximum size of 500K into * the returned {@link ByteBufFlux} * * @param path the path to the resource to stream * * @return a {@link ByteBufFlux} */ public static ByteBufFlux fromPath(Path path) { return fromPath(path, MAX_CHUNK_SIZE); }
@Override default HttpClientRequest onWriteIdle(long idleTimeout, Runnable onWriteIdle){ NettyOutbound.super.onWriteIdle(idleTimeout, onWriteIdle); return this; }
@Override default HttpServerResponse options(Consumer<? super NettyPipeline.SendOptions> configurator){ NettyOutbound.super.options(configurator); return this; }
@Override default HttpClientResponse onReadIdle(long idleTimeout, Runnable onReadIdle) { NettyInbound.super.onReadIdle(idleTimeout, onReadIdle); return this; }
/** * Decorate as {@link ByteBufFlux} * * @param source publisher to decorate * * @return a {@link ByteBufFlux} */ public static ByteBufFlux fromInbound(Publisher<?> source) { return fromInbound(source, ByteBufAllocator.DEFAULT); }
@Override default HttpServerRequest context(Consumer<NettyContext> contextCallback) { NettyInbound.super.context(contextCallback); return this; }
/** * Append a {@link Publisher} task such as a Mono and return a new * {@link NettyOutbound} to sequence further send. * * @param other the {@link Publisher} to subscribe to when this pending outbound * {@link #then()} is complete; * * @return a new {@link NettyOutbound} that */ default NettyOutbound then(Publisher<Void> other) { return new ReactorNetty.OutboundThen(this, other); }
/** * Open a {@link java.nio.channels.FileChannel} from a path and stream * {@link ByteBuf} chunks with a default maximum size of 500K into the returned * {@link ByteBufFlux}, using the provided {@link ByteBufAllocator}. * * @param path the path to the resource to stream * @param allocator the channel {@link ByteBufAllocator} * * @return a {@link ByteBufFlux} */ public static ByteBufFlux fromPath(Path path, ByteBufAllocator allocator) { return fromPath(path, MAX_CHUNK_SIZE, allocator); }
@Override default HttpServerResponse onWriteIdle(long idleTimeout, Runnable onWriteIdle){ NettyOutbound.super.onWriteIdle(idleTimeout, onWriteIdle); return this; }
@Override default HttpClientRequest options(Consumer<? super NettyPipeline.SendOptions> configurator){ NettyOutbound.super.options(configurator); return this; }
@Override default HttpServerRequest onReadIdle(long idleTimeout, Runnable onReadIdle) { NettyInbound.super.onReadIdle(idleTimeout, onReadIdle); return this; }