Class BufferedPersistentStreamSegment
- java.lang.Object
-
- io.axoniq.axonserver.connector.impl.FlowControlledStream<T,R>
-
- io.axoniq.axonserver.connector.impl.FlowControlledBuffer<T,R>
-
- io.axoniq.axonserver.connector.impl.AbstractBufferedStream<PersistentStreamEvent,StreamRequest>
-
- io.axoniq.axonserver.connector.event.impl.BufferedPersistentStreamSegment
-
- All Implemented Interfaces:
PersistentStreamSegment,ResultStream<PersistentStreamEvent>,io.grpc.stub.ClientResponseObserver<StreamRequest,PersistentStreamEvent>,io.grpc.stub.StreamObserver<PersistentStreamEvent>,AutoCloseable
public class BufferedPersistentStreamSegment extends AbstractBufferedStream<PersistentStreamEvent,StreamRequest> implements PersistentStreamSegment
Implementation of thePersistentStreamSegment.
-
-
Field Summary
-
Fields inherited from interface io.axoniq.axonserver.connector.event.PersistentStreamSegment
PENDING_WORK_DONE_MARKER
-
-
Constructor Summary
Constructors Constructor Description BufferedPersistentStreamSegment(String streamId, int segment, int bufferSize, int refillBatch, LongConsumer progressCallback, Consumer<String> errorCallback)Constructs aBufferedPersistentStreamSegment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacknowledge(long token)Sends the last processed token for this segment to Axon Server.protected StreamRequestbuildFlowControlMessage(FlowControl flowControl)Build a flow control message of typeOUTbased on the givenflowControl.voidclose()Requests the current stream to be closed.voiderror(String error)booleanisClosed()Check whether this buffer has been closed offvoidonAvailable(Runnable callback)Sets the givencallbackto execute when data is available for reading, or the stream has been closed.voidonCompleted()voidonSegmentClosed(Runnable callback)Registers a callback that will be invoked when Axon Server closes the segment within the persistent stream connection.intsegment()Returns the segment number of the stream.protected PersistentStreamEventterminalMessage()Builds a terminal message of typeTspecifying when the this stream is closed.StringtoString()-
Methods inherited from class io.axoniq.axonserver.connector.impl.AbstractBufferedStream
getError, next, nextIfAvailable, nextIfAvailable, onCloseRequested, onError, onNext, peek
-
Methods inherited from class io.axoniq.axonserver.connector.impl.FlowControlledBuffer
beforeStart, getErrorResult, take, tryTake, tryTake, tryTake, tryTakeNow
-
Methods inherited from class io.axoniq.axonserver.connector.impl.FlowControlledStream
buildInitialFlowControlMessage, enableFlowControl, markConsumed, outboundStream
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.axoniq.axonserver.connector.ResultStream
getError, next, nextIfAvailable, nextIfAvailable, peek
-
-
-
-
Constructor Detail
-
BufferedPersistentStreamSegment
public BufferedPersistentStreamSegment(String streamId, int segment, int bufferSize, int refillBatch, LongConsumer progressCallback, Consumer<String> errorCallback)
Constructs aBufferedPersistentStreamSegment.- Parameters:
streamId- the id of the persistent streamsegment- the index of the segmentbufferSize- the number of events to buffer locallyrefillBatch- the number of events to be consumed prior to refilling the bufferprogressCallback- the callback to invoke for acknowledging processed events
-
-
Method Detail
-
onSegmentClosed
public void onSegmentClosed(Runnable callback)
Description copied from interface:PersistentStreamSegmentRegisters a callback that will be invoked when Axon Server closes the segment within the persistent stream connection. This happens when the number of segments in the persistent stream has changed or when Axon Server assigns a segment to another client.- Specified by:
onSegmentClosedin interfacePersistentStreamSegment- Parameters:
callback- the callback to register
-
onCompleted
public void onCompleted()
- Specified by:
onCompletedin interfaceio.grpc.stub.StreamObserver<PersistentStreamEvent>- Overrides:
onCompletedin classAbstractBufferedStream<PersistentStreamEvent,StreamRequest>
-
acknowledge
public void acknowledge(long token)
Description copied from interface:PersistentStreamSegmentSends the last processed token for this segment to Axon Server. Clients may choose to notify each processed event, or to only sent progress information after a number of processed events.- Specified by:
acknowledgein interfacePersistentStreamSegment- Parameters:
token- the last processed token for this segment
-
error
public void error(String error)
- Specified by:
errorin interfacePersistentStreamSegment
-
isClosed
public boolean isClosed()
Description copied from class:FlowControlledBufferCheck whether this buffer has been closed off- Specified by:
isClosedin interfaceResultStream<PersistentStreamEvent>- Overrides:
isClosedin classAbstractBufferedStream<PersistentStreamEvent,StreamRequest>- Returns:
trueif this buffer is closed,false otherwise- See Also:
ResultStream.getError()
-
segment
public int segment()
Description copied from interface:PersistentStreamSegmentReturns the segment number of the stream.- Specified by:
segmentin interfacePersistentStreamSegment- Returns:
- the segment number of this stream
-
close
public void close()
Description copied from interface:ResultStreamRequests the current stream to be closed. It is up to the publishing end of the stream to honor the request.Any elements received before closing are still available for reading.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceResultStream<PersistentStreamEvent>- Overrides:
closein classAbstractBufferedStream<PersistentStreamEvent,StreamRequest>
-
onAvailable
public void onAvailable(Runnable callback)
Description copied from interface:ResultStreamSets the givencallbackto execute when data is available for reading, or the stream has been closed. Note that any registration will replace the previous one.The callback is invoked in the publisher's thread. Invocations should be as short as possible, preferably delegating to a reader thead, instead of accessing the entries directly.
- Specified by:
onAvailablein interfaceResultStream<PersistentStreamEvent>- Overrides:
onAvailablein classAbstractBufferedStream<PersistentStreamEvent,StreamRequest>- Parameters:
callback- a {Runnable} toRunnable.run()when the next entry becomes available ornullto disable callbacks
-
terminalMessage
protected PersistentStreamEvent terminalMessage()
Description copied from class:FlowControlledBufferBuilds a terminal message of typeTspecifying when the this stream is closed.- Specified by:
terminalMessagein classFlowControlledBuffer<PersistentStreamEvent,StreamRequest>- Returns:
- a terminal message of type
Tspecifying when the this stream is closed
-
buildFlowControlMessage
protected StreamRequest buildFlowControlMessage(FlowControl flowControl)
Description copied from class:FlowControlledStreamBuild a flow control message of typeOUTbased on the givenflowControl.- Specified by:
buildFlowControlMessagein classFlowControlledStream<PersistentStreamEvent,StreamRequest>- Parameters:
flowControl- theFlowControlmessage used to base this implementation's flow control message on- Returns:
- the message used by this implementation to request new entries of type
IN
-
-