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
FaunaStream
class extendsSubmissionPublisher
to process incoming ByteBuffers, decode them intoFaunaEvent
objects, and forward them to subscribers.
-
-
Constructor Summary
Constructors Constructor Description FaunaStream(java.lang.Class<E> elementClass, StatsCollector statsCollector)
Constructs aFaunaStream
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
-
-
-
-
Constructor Detail
-
FaunaStream
public FaunaStream(java.lang.Class<E> elementClass, StatsCollector statsCollector)
Constructs aFaunaStream
instance with the specified event data type and stats collector.- Parameters:
elementClass
- The class of the event data type.statsCollector
- TheStatsCollector
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 interfacejava.util.concurrent.Flow.Publisher<E>
- Overrides:
subscribe
in classjava.util.concurrent.SubmissionPublisher<FaunaEvent<E>>
- Parameters:
subscriber
- TheFlow.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 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:
onNext
in interfacejava.util.concurrent.Flow.Subscriber<E>
- Parameters:
buffers
- The list ofByteBuffer
s 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 interfacejava.util.concurrent.Flow.Subscriber<E>
- Parameters:
throwable
- TheThrowable
encountered during stream processing.
-
onComplete
public void onComplete()
Completes the stream by canceling the subscription.- Specified by:
onComplete
in interfacejava.util.concurrent.Flow.Subscriber<E>
-
-