Class FaunaStream<E>

  • Type Parameters:
    E - The type of document data contained in the Fauna events.
    All Implemented Interfaces:
    java.lang.AutoCloseable, java.util.concurrent.Flow.Processor<java.util.List<java.nio.ByteBuffer>,​FaunaEvent<E>>, java.util.concurrent.Flow.Publisher<FaunaEvent<E>>, java.util.concurrent.Flow.Subscriber<java.util.List<java.nio.ByteBuffer>>

    public class FaunaStream<E>
    extends java.util.concurrent.SubmissionPublisher<FaunaEvent<E>>
    implements java.util.concurrent.Flow.Processor<java.util.List<java.nio.ByteBuffer>,​FaunaEvent<E>>
    A processor for handling and decoding Fauna Event Streams.

    The FaunaStream class extends SubmissionPublisher to process incoming ByteBuffers, decode them into FaunaEvent objects, and forward them to subscribers.

    • Constructor Summary

      Constructors 
      Constructor Description
      FaunaStream​(java.lang.Class<E> elementClass, StatsCollector statsCollector)
      Constructs a FaunaStream instance with the specified event data type and stats collector.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void onComplete()
      Completes the stream by canceling the subscription.
      void onError​(java.lang.Throwable throwable)
      Handles errors by canceling the subscription and closing the stream.
      void onNext​(java.util.List<java.nio.ByteBuffer> buffers)
      Processes incoming ByteBuffers, decodes them into Fauna events, and submits the events to subscribers.
      void onSubscribe​(java.util.concurrent.Flow.Subscription subscription)
      Handles subscription by setting the subscription and requesting data.
      void subscribe​(java.util.concurrent.Flow.Subscriber<? super FaunaEvent<E>> subscriber)
      Subscribes a single subscriber to this stream.
      • Methods inherited from class java.util.concurrent.SubmissionPublisher

        close, closeExceptionally, consume, estimateMaximumLag, estimateMinimumDemand, getClosedException, getExecutor, getMaxBufferCapacity, getNumberOfSubscribers, getSubscribers, hasSubscribers, isClosed, isSubscribed, offer, offer, submit
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FaunaStream

        public FaunaStream​(java.lang.Class<E> elementClass,
                           StatsCollector statsCollector)
        Constructs a FaunaStream instance with the specified event data type and stats collector.
        Parameters:
        elementClass - The class of the event data type.
        statsCollector - The StatsCollector to track statistics for events.
    • Method Detail

      • subscribe

        public void subscribe​(java.util.concurrent.Flow.Subscriber<? super FaunaEvent<E>> subscriber)
        Subscribes a single subscriber to this stream.
        Specified by:
        subscribe in interface java.util.concurrent.Flow.Publisher<E>
        Overrides:
        subscribe in class java.util.concurrent.SubmissionPublisher<FaunaEvent<E>>
        Parameters:
        subscriber - The Flow.Subscriber to subscribe to this stream.
        Throws:
        ClientException - if more than one subscriber attempts to subscribe.
      • onSubscribe

        public void onSubscribe​(java.util.concurrent.Flow.Subscription subscription)
        Handles subscription by setting the subscription and requesting data.
        Specified by:
        onSubscribe in interface java.util.concurrent.Flow.Subscriber<E>
        Parameters:
        subscription - The subscription to this stream.
      • onNext

        public void onNext​(java.util.List<java.nio.ByteBuffer> buffers)
        Processes incoming ByteBuffers, decodes them into Fauna events, and submits the events to subscribers.
        Specified by:
        onNext in interface java.util.concurrent.Flow.Subscriber<E>
        Parameters:
        buffers - The list of ByteBuffers containing encoded event data.
        Throws:
        ClientException - if there is an error decoding the stream or processing events.
      • onError

        public void onError​(java.lang.Throwable throwable)
        Handles errors by canceling the subscription and closing the stream.
        Specified by:
        onError in interface java.util.concurrent.Flow.Subscriber<E>
        Parameters:
        throwable - The Throwable encountered during stream processing.
      • onComplete

        public void onComplete()
        Completes the stream by canceling the subscription.
        Specified by:
        onComplete in interface java.util.concurrent.Flow.Subscriber<E>