Class FlowControlledBuffer<T,R>
- java.lang.Object
-
- io.axoniq.axonserver.connector.impl.FlowControlledStream<T,R>
-
- io.axoniq.axonserver.connector.impl.FlowControlledBuffer<T,R>
-
- Type Parameters:
T- the type of results this implementation buffersR- the type of message used for flow control in this buffer
- All Implemented Interfaces:
io.grpc.stub.ClientResponseObserver<R,T>,io.grpc.stub.StreamObserver<T>
- Direct Known Subclasses:
AbstractBufferedStream,BufferedAggregateEventStream
public abstract class FlowControlledBuffer<T,R> extends FlowControlledStream<T,R>
Abstract implementation of theFlowControlledStream, adding buffering logic to the flow controlled stream.
-
-
Constructor Summary
Constructors Constructor Description FlowControlledBuffer(String clientId, int bufferSize, int refillBatch)Constructs aFlowControlledBuffer.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidbeforeStart(io.grpc.stub.ClientCallStreamObserver<R> requestStream)voidclose()ThrowablegetErrorResult()Returns the error result, if any was recorded.protected booleanisClosed()Check whether this buffer has been closed offvoidonCompleted()voidonError(Throwable t)voidonNext(T value)protected Tpeek()Retrieves, but does not remove, the first entry of this buffer, or returnsnullif the buffer is empty.protected Ttake()Take an entry of typeTfrom the buffer, waiting indefinitely.protected abstract TterminalMessage()Builds a terminal message of typeTspecifying when the this stream is closed.protected TtryTake()Try to retrieve an entry of typeTfrom the buffer, waiting indefinitely.protected TtryTake(long timeout, TimeUnit timeUnit)Try to retrieve an entry of typeTfrom the buffer, waiting for the duration oftimeoutin the giventimeUnit.protected TtryTake(long timeout, TimeUnit timeUnit, boolean exceptionOnTimeout)Try to retrieve an entry of typeTfrom the buffer, waiting for the duration oftimeoutin the giventimeUnit.protected TtryTakeNow()Try to retrieve an entry of typeTfrom the buffer immediately.-
Methods inherited from class io.axoniq.axonserver.connector.impl.FlowControlledStream
buildFlowControlMessage, buildInitialFlowControlMessage, enableFlowControl, markConsumed, outboundStream
-
-
-
-
Constructor Detail
-
FlowControlledBuffer
public FlowControlledBuffer(String clientId, int bufferSize, int refillBatch)
Constructs aFlowControlledBuffer.- Parameters:
clientId- the client identifier which initiated this bufferbufferSize- the number of entries this buffer should holdrefillBatch- the number of entries to be consumed prior to requesting new once
-
-
Method Detail
-
terminalMessage
protected abstract T terminalMessage()
Builds a terminal message of typeTspecifying when the this stream is closed.- Returns:
- a terminal message of type
Tspecifying when the this stream is closed
-
onNext
public void onNext(T value)
-
onError
public void onError(Throwable t)
-
onCompleted
public void onCompleted()
-
close
public void close()
-
getErrorResult
public Throwable getErrorResult()
Returns the error result, if any was recorded. This method may also yield a non-empty result when the buffer still contains messages for processing.- Returns:
- the error result, if any was recorded, or else
null
-
beforeStart
public void beforeStart(io.grpc.stub.ClientCallStreamObserver<R> requestStream)
- Specified by:
beforeStartin interfaceio.grpc.stub.ClientResponseObserver<T,R>- Overrides:
beforeStartin classFlowControlledStream<T,R>
-
tryTakeNow
protected T tryTakeNow()
Try to retrieve an entry of typeTfrom the buffer immediately. If none is present,nullwill be returned.- Returns:
- an entry of type
Tfrom this buffer if present, otherwisenull
-
tryTake
protected T tryTake(long timeout, TimeUnit timeUnit) throws InterruptedException
Try to retrieve an entry of typeTfrom the buffer, waiting for the duration oftimeoutin the giventimeUnit. If none is present,nullwill be returned.- Parameters:
timeout- the duration to wait for an entry to become available in the buffertimeUnit- theTimeUnitused to specify the duration together with thetimeout- Returns:
- an entry of type
Tfrom this buffer if present, otherwisenull. Timeouts will result in null as well. - Throws:
InterruptedException- while waiting for an entry to be taken
-
tryTake
protected T tryTake(long timeout, TimeUnit timeUnit, boolean exceptionOnTimeout) throws InterruptedException
Try to retrieve an entry of typeTfrom the buffer, waiting for the duration oftimeoutin the giventimeUnit. If none is present,nullwill be returned.- Parameters:
timeout- the duration to wait for an entry to become available in the buffertimeUnit- theTimeUnitused to specify the duration together with thetimeoutexceptionOnTimeout- Whether aTimeoutExceptionshould be thrown when the operation times out- Returns:
- an entry of type
Tfrom this buffer if present, otherwisenull - Throws:
InterruptedException- while waiting for an entry to be takenStreamTimeoutException- If there is no message available after waiting the allotted period
-
tryTake
protected T tryTake() throws InterruptedException
Try to retrieve an entry of typeTfrom the buffer, waiting indefinitely. If none is present because the buffer is closed,nullwill be returned.- Returns:
- an entry of type
Tfrom this buffer if present, otherwisenull - Throws:
InterruptedException- while waiting for an entry to be taken
-
take
protected T take() throws InterruptedException
Take an entry of typeTfrom the buffer, waiting indefinitely.- Returns:
- an entry of type
Tfrom this buffer - Throws:
InterruptedException- while waiting for an entry to be taken
-
peek
protected T peek()
Retrieves, but does not remove, the first entry of this buffer, or returnsnullif the buffer is empty.- Returns:
- the first entry of this buffer without removing it, or
nullif it is empty
-
isClosed
protected boolean isClosed()
Check whether this buffer has been closed off- Returns:
trueif this buffer is closed,false otherwise
-
-