Package com.tnsai.coordination.streaming
Class StreamingChannel<T>
java.lang.Object
com.tnsai.coordination.streaming.StreamingChannel<T>
- All Implemented Interfaces:
Closeable,AutoCloseable
A typed streaming channel for inter-agent communication with configurable backpressure.
Supports push-based producer/consumer patterns with flow control.
Example usage:
StreamingChannel<String> channel = StreamingChannel.<String>builder()
.bufferSize(100)
.backpressure(BackpressureStrategy.DROP_OLDEST)
.build();
// Consumer side
channel.subscribe(chunk -> processChunk(chunk));
// Producer side
channel.emit("data chunk 1");
channel.emit("data chunk 2");
channel.complete(); // signal end of stream
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when backpressure strategy is ERROR and buffer is full.static classstatic final recordChannel metrics snapshot. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the total buffer capacity.intReturns the number of items currently in the buffer.static <T> StreamingChannel.Builder<T> builder()voidclose()voidcomplete()Signals that no more data will be emitted.longReturns the total number of items dropped due to backpressure.booleanEmits a value to the channel.intemitAll(Collection<T> values) Emits multiple values to the channel.longReturns the total number of items emitted.Creates a new channel that only passes items matching the predicate.id()Returns the channel identifier.booleanisClosed()Returns whether the channel is closed.booleanReturns whether the channel has been completed (no more emits).<R> StreamingChannel<R> Creates a new channel that applies a transformation to each item.metrics()Returns a snapshot of channel metrics.onComplete(Runnable handler) Registers a completion handler.Registers an error handler.Subscribes a consumer to receive values from this channel.
-
Method Details
-
emit
Emits a value to the channel. Subject to backpressure strategy. -
emitAll
Emits multiple values to the channel. -
subscribe
Subscribes a consumer to receive values from this channel. -
onError
Registers an error handler. -
onComplete
Registers a completion handler. -
complete
public void complete()Signals that no more data will be emitted. Remaining items are still delivered. -
map
Creates a new channel that applies a transformation to each item. -
filter
Creates a new channel that only passes items matching the predicate. -
id
Returns the channel identifier. -
bufferUsed
public int bufferUsed()Returns the number of items currently in the buffer. -
bufferCapacity
public int bufferCapacity()Returns the total buffer capacity. -
isCompleted
public boolean isCompleted()Returns whether the channel has been completed (no more emits). -
isClosed
public boolean isClosed()Returns whether the channel is closed. -
emittedCount
public long emittedCount()Returns the total number of items emitted. -
droppedCount
public long droppedCount()Returns the total number of items dropped due to backpressure. -
metrics
Returns a snapshot of channel metrics. -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
builder
-