PacketConsumerUtil


@ExperimentalApi
public static class PacketConsumerUtil


Summary

Nested types

public fun interface PacketConsumerUtil.ThrowingFunction<I extends Object, O extends Object>

A functional interface representing a function that accepts one argument and produces a result, potentially throwing an exception during execution.

Public fields

static @NonNull PacketConsumerUtil

Public methods

static final @NonNull PacketProcessor<@NonNull I, @NonNull O>
<I extends Object, O extends Object> createPacketProcessor(
    @NonNull PacketConsumerUtil.ThrowingFunction<@NonNull I, @NonNull O> onPayload,
    @NonNull Runnable onEndOfStream
)

Creates a PacketProcessor that applies a transformation function to incoming payloads and executes a callback when the stream ends.

static final @NonNull ListenableFuture<Void>
<T extends Object> release(
    @NonNull PacketConsumer<@NonNull T> consumer,
    @NonNull ExecutorService executor
)

Releases the PacketConsumer from Java by wrapping the suspend call in a ListenableFuture.

Public fields

INSTANCE

public static @NonNull PacketConsumerUtil INSTANCE

Public methods

createPacketProcessor

public static final @NonNull PacketProcessor<@NonNull I, @NonNull O> <I extends Object, O extends Object> createPacketProcessor(
    @NonNull PacketConsumerUtil.ThrowingFunction<@NonNull I, @NonNull O> onPayload,
    @NonNull Runnable onEndOfStream
)

Creates a PacketProcessor that applies a transformation function to incoming payloads and executes a callback when the stream ends.

When a Packet.Payload is received, the onPayload function is applied to the data, and the result is wrapped in a new packet and sent to the output.

When a Packet.EndOfStream is received, the onEndOfStream runnable is executed immediately before the EOS packet is forwarded to the output.

release

public static final @NonNull ListenableFuture<Void> <T extends Object> release(
    @NonNull PacketConsumer<@NonNull T> consumer,
    @NonNull ExecutorService executor
)

Releases the PacketConsumer from Java by wrapping the suspend call in a ListenableFuture.

Parameters
@NonNull PacketConsumer<@NonNull T> consumer

The PacketConsumer to release.

@NonNull ExecutorService executor

The ExecutorService to launch the coroutine on.

Returns
@NonNull ListenableFuture<Void>

A ListenableFuture that completes when the consumer has been released.