Class UmaDbAsyncClientImpl
- All Implemented Interfaces:
UmaDbAsyncClient, AutoCloseable
UmaDbAsyncClient.
Unary calls go through the asynchronous stub rather than the futures stub: the futures
stub hands back a Guava ListenableFuture, which would both leak Guava into the
public API and give no way to make cancellation reach the wire. Driving the async stub
inside a Context.CancellableContext solves both, and uses the same
cancellation mechanism as the streaming calls.
This class is not intended to be used directly by client code.
Clients should construct instances via UmaDbClientBuilder.buildAsync().
-
Constructor Summary
ConstructorsConstructorDescriptionUmaDbAsyncClientImpl(String host, int port, boolean tlsEnabled, String caFilePath, String apiKey, Executor executor) Creates a new asynchronous client implementation. -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Establishes a connection to the UmaDB server.Returns the position of the most recent event in the event store.getTrackingInfo(String source) Returns the last recorded position for a named source.handle(AppendRequest appendRequest) Appends events to the event store.handle(ReadRequest readRequest, UmaDbStreamObserver<ReadResponse> observer) Reads events, delivering each batch to the given observer.voidshutdown()Shuts the client down, cancelling any live streams and closing the connection.subscribe(SubscribeRequest subscribeRequest, UmaDbStreamObserver<SubscribeResponse> observer) Opens a continuous subscription, delivering each batch to the given observer.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface UmaDbAsyncClient
close
-
Constructor Details
-
UmaDbAsyncClientImpl
public UmaDbAsyncClientImpl(String host, int port, boolean tlsEnabled, String caFilePath, String apiKey, Executor executor) Creates a new asynchronous client implementation.- Parameters:
host- UmaDB server hostport- UmaDB server porttlsEnabled- indicates whether an encrypted communication (TLS) is to be usedcaFilePath- optional path to a CA certificate for TLSapiKey- optional API key (requires TLS)executor- optional executor for gRPC callbacks;nulluses the gRPC default- Throws:
IllegalArgumentException- if arguments are invalid or insecure
-
-
Method Details
-
connect
public void connect()Description copied from interface:UmaDbAsyncClientEstablishes a connection to the UmaDB server.This method must be called before performing any operations. It is idempotent.
- Specified by:
connectin interfaceUmaDbAsyncClient
-
handle
Description copied from interface:UmaDbAsyncClientAppends events to the event store.- Specified by:
handlein interfaceUmaDbAsyncClient- Parameters:
appendRequest- the request describing the events to append- Returns:
- a future completing with the position of the last appended event, or
completing exceptionally with a
UmaDbExceptioncause
-
getHeadPosition
Description copied from interface:UmaDbAsyncClientReturns the position of the most recent event in the event store.- Specified by:
getHeadPositionin interfaceUmaDbAsyncClient- Returns:
- a future completing with the sequence number of the latest event
-
getTrackingInfo
Description copied from interface:UmaDbAsyncClientReturns the last recorded position for a named source.- Specified by:
getTrackingInfoin interfaceUmaDbAsyncClient- Parameters:
source- the unique identifier of the consumer or projection- Returns:
- a future completing with the position the source has processed up to, or
Optional.empty()if no tracking info exists for it
-
handle
Description copied from interface:UmaDbAsyncClientReads events, delivering each batch to the given observer.The stream ends, with
UmaDbStreamObserver.onCompleted(), once the head position captured when the request was received has been reached. To keep receiving events as they are appended, useUmaDbAsyncClient.subscribe(SubscribeRequest, UmaDbStreamObserver)instead.- Specified by:
handlein interfaceUmaDbAsyncClient- Parameters:
readRequest- the request describing which events to readobserver- receives the batches; must not benull- Returns:
- a handle for controlling demand and cancelling the stream
-
subscribe
public UmaDbStream subscribe(SubscribeRequest subscribeRequest, UmaDbStreamObserver<SubscribeResponse> observer) Description copied from interface:UmaDbAsyncClientOpens a continuous subscription, delivering each batch to the given observer.The subscription replays already-recorded events matching the request and then continues to deliver new events as they are appended. It does not end on its own — call
UmaDbStream.cancel()orUmaDbAsyncClient.shutdown()to stop it.- Specified by:
subscribein interfaceUmaDbAsyncClient- Parameters:
subscribeRequest- the request describing which events to subscribe toobserver- receives the batches; must not benull- Returns:
- a handle for controlling demand and cancelling the subscription
-
shutdown
public void shutdown()Description copied from interface:UmaDbAsyncClientShuts the client down, cancelling any live streams and closing the connection.Idempotent. After calling this the client should not be used again; further calls fail through the returned future or the observer rather than by throwing.
- Specified by:
shutdownin interfaceUmaDbAsyncClient
-