Class AbstractIncomingInstructionStream<IN,OUT>
- java.lang.Object
-
- io.axoniq.axonserver.connector.impl.FlowControlledStream<IN,OUT>
-
- io.axoniq.axonserver.connector.impl.AbstractIncomingInstructionStream<IN,OUT>
-
- Type Parameters:
IN- the type of instructions received by this streamOUT- the type of instructions returned by this stream
- All Implemented Interfaces:
io.grpc.stub.ClientResponseObserver<OUT,IN>,io.grpc.stub.StreamObserver<IN>
public abstract class AbstractIncomingInstructionStream<IN,OUT> extends FlowControlledStream<IN,OUT>
Abstract implementation of aFlowControlledStreamfor incoming message from AxonServer.- Since:
- 4.4
- Author:
- Allard Buijze
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractIncomingInstructionStream(String clientId, int permits, int permitsBatch, Consumer<Throwable> disconnectHandler, Consumer<io.grpc.stub.CallStreamObserver<OUT>> beforeStartHandler)Construct anAbstractIncomingInstructionStream.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidbeforeStart(io.grpc.stub.ClientCallStreamObserver<OUT> requestStream)protected abstract OUTbuildAckMessage(InstructionAck ack)Builds a stream specific acknowledgment message of typeOUTbased on the givenack.protected Optional<OUT>buildResultMessage(InstructionResult result)Builds a stream specific result message of typeOUTbased on the givenresult.protected abstract InstructionHandler<IN,OUT>getHandler(IN msgIn)Retrieves anInstructionHandlercapable of handling the givenmsgIn.protected abstract StringgetInstructionId(IN instruction)Returns the instruction identifier of the giveninstruction.io.grpc.stub.ClientCallStreamObserver<OUT>getInstructionsForPlatform()Return theStreamObserverof typeOUTserving as the outbound instruction channel.voidonCompleted()voidonError(Throwable t)voidonNext(IN value)protected abstract booleanunregisterOutboundStream(io.grpc.stub.CallStreamObserver<OUT> expected)Deregisters this stream's outbound stream, granted that it matches the givenexpectedStreamObserver.-
Methods inherited from class io.axoniq.axonserver.connector.impl.FlowControlledStream
buildFlowControlMessage, buildInitialFlowControlMessage, enableFlowControl, markConsumed, outboundStream
-
-
-
-
Constructor Detail
-
AbstractIncomingInstructionStream
protected AbstractIncomingInstructionStream(String clientId, int permits, int permitsBatch, Consumer<Throwable> disconnectHandler, Consumer<io.grpc.stub.CallStreamObserver<OUT>> beforeStartHandler)
Construct anAbstractIncomingInstructionStream.- Parameters:
clientId- the client identifier whom initiated this instruction streampermits- the number of permits this stream should receivepermitsBatch- the number of permits to be consumed prior to requesting new permitsdisconnectHandler- aConsumerofThrowableinvoked when this stream errors outbeforeStartHandler- the handler to invoke when the upstream connection is available. Note that the gRPC call has not started yet at this point.
-
-
Method Detail
-
onNext
public void onNext(IN value)
-
buildAckMessage
protected abstract OUT buildAckMessage(InstructionAck ack)
Builds a stream specific acknowledgment message of typeOUTbased on the givenack.- Parameters:
ack- theInstructionAckto base the stream specific acknowledgement on- Returns:
- a stream specific acknowledgment message of type
OUTbased on the givenack
-
buildResultMessage
protected Optional<OUT> buildResultMessage(InstructionResult result)
Builds a stream specific result message of typeOUTbased on the givenresult. If theOptionalis empty, no instruction result will be sent. By default, this method returns an emptyOptional. If the concrete class supports theInstructionResultit should override this method.- Parameters:
result- theInstructionResultto base the stream specific acknowledgement on- Returns:
- a stream specific acknowledgment message of type
OUTbased on the givenresult
-
getInstructionId
protected abstract String getInstructionId(IN instruction)
Returns the instruction identifier of the giveninstruction.- Parameters:
instruction- the instruction of typeINto retrieve the instruction identifier from- Returns:
- the instruction identifier of the given
instruction
-
getHandler
protected abstract InstructionHandler<IN,OUT> getHandler(IN msgIn)
Retrieves anInstructionHandlercapable of handling the givenmsgIn.- Parameters:
msgIn- the instruction message of typeINto retrieve anInstructionHandleron- Returns:
- an
InstructionHandlercapable of handling the givenmsgIn
-
onCompleted
public void onCompleted()
-
onError
public void onError(Throwable t)
-
beforeStart
public void beforeStart(io.grpc.stub.ClientCallStreamObserver<OUT> requestStream)
- Specified by:
beforeStartin interfaceio.grpc.stub.ClientResponseObserver<IN,OUT>- Overrides:
beforeStartin classFlowControlledStream<IN,OUT>
-
getInstructionsForPlatform
public io.grpc.stub.ClientCallStreamObserver<OUT> getInstructionsForPlatform()
Return theStreamObserverof typeOUTserving as the outbound instruction channel.- Returns:
- the
StreamObserverof typeOUTserving as the outbound instruction channel
-
unregisterOutboundStream
protected abstract boolean unregisterOutboundStream(io.grpc.stub.CallStreamObserver<OUT> expected)
Deregisters this stream's outbound stream, granted that it matches the givenexpectedStreamObserver. Will returntrueif they matched andfalseotherwise.- Parameters:
expected- the expectedStreamObserverto be deregistered- Returns:
trueif the outbound stream was successfully deregistered,falseotherwise
-
-