Class StreamingChannel<T>

java.lang.Object
com.tnsai.coordination.streaming.StreamingChannel<T>
All Implemented Interfaces:
Closeable, AutoCloseable

public final class StreamingChannel<T> extends Object implements Closeable
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
 
  • Method Details

    • emit

      public boolean emit(T value)
      Emits a value to the channel. Subject to backpressure strategy.
    • emitAll

      public int emitAll(Collection<T> values)
      Emits multiple values to the channel.
    • subscribe

      public StreamingChannel<T> subscribe(Consumer<T> consumer)
      Subscribes a consumer to receive values from this channel.
    • onError

      public StreamingChannel<T> onError(Consumer<Throwable> handler)
      Registers an error handler.
    • onComplete

      public StreamingChannel<T> onComplete(Runnable handler)
      Registers a completion handler.
    • complete

      public void complete()
      Signals that no more data will be emitted. Remaining items are still delivered.
    • map

      public <R> StreamingChannel<R> map(Function<T,R> mapper)
      Creates a new channel that applies a transformation to each item.
    • filter

      public StreamingChannel<T> filter(Predicate<T> predicate)
      Creates a new channel that only passes items matching the predicate.
    • id

      public String 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:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • builder

      public static <T> StreamingChannel.Builder<T> builder()