PacketConsumerUtil


@ExperimentalApi
object PacketConsumerUtil


Summary

Nested types

fun interface PacketConsumerUtil.ThrowingFunction<I : Any?, O : Any?>

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

Public functions

PacketProcessor<I, O>
<I : Any?, O : Any?> createPacketProcessor(
    onPayload: PacketConsumerUtil.ThrowingFunction<I, O>,
    onEndOfStream: Runnable
)

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

ListenableFuture<Void?>
<T : Any?> release(consumer: PacketConsumer<T>, executor: ExecutorService)

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

Public functions

createPacketProcessor

fun <I : Any?, O : Any?> createPacketProcessor(
    onPayload: PacketConsumerUtil.ThrowingFunction<I, O>,
    onEndOfStream: Runnable
): PacketProcessor<I, O>

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

fun <T : Any?> release(consumer: PacketConsumer<T>, executor: ExecutorService): ListenableFuture<Void?>

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

Parameters
consumer: PacketConsumer<T>

The PacketConsumer to release.

executor: ExecutorService

The ExecutorService to launch the coroutine on.

Returns
ListenableFuture<Void?>

A ListenableFuture that completes when the consumer has been released.