Package com.fauna.event
Class FaunaStream<E>
- java.lang.Object
-
- java.util.concurrent.SubmissionPublisher<FaunaEvent<E>>
-
- com.fauna.event.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
FaunaStreamclass extendsSubmissionPublisherto process incoming ByteBuffers, decode them intoFaunaEventobjects, and forward them to subscribers.
-
-
Constructor Summary
Constructors Constructor Description FaunaStream(java.lang.Class<E> elementClass, StatsCollector statsCollector)Constructs aFaunaStreaminstance with the specified event data type and stats collector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidonComplete()Completes the stream by canceling the subscription.voidonError(java.lang.Throwable throwable)Handles errors by canceling the subscription and closing the stream.voidonNext(java.util.List<java.nio.ByteBuffer> buffers)Processes incoming ByteBuffers, decodes them into Fauna events, and submits the events to subscribers.voidonSubscribe(java.util.concurrent.Flow.Subscription subscription)Handles subscription by setting the subscription and requesting data.voidsubscribe(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
-
-
-
-
Constructor Detail
-
FaunaStream
public FaunaStream(java.lang.Class<E> elementClass, StatsCollector statsCollector)
Constructs aFaunaStreaminstance with the specified event data type and stats collector.- Parameters:
elementClass- The class of the event data type.statsCollector- TheStatsCollectorto 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:
subscribein interfacejava.util.concurrent.Flow.Publisher<E>- Overrides:
subscribein classjava.util.concurrent.SubmissionPublisher<FaunaEvent<E>>- Parameters:
subscriber- TheFlow.Subscriberto 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:
onSubscribein interfacejava.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:
onNextin interfacejava.util.concurrent.Flow.Subscriber<E>- Parameters:
buffers- The list ofByteBuffers 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:
onErrorin interfacejava.util.concurrent.Flow.Subscriber<E>- Parameters:
throwable- TheThrowableencountered during stream processing.
-
onComplete
public void onComplete()
Completes the stream by canceling the subscription.- Specified by:
onCompletein interfacejava.util.concurrent.Flow.Subscriber<E>
-
-