public abstract class GrpcMessagingConnection extends Object implements io.grpc.stub.StreamObserver<TransportMessage>
GrpcMessagingConnection
implementation based on Alluxio gRPC messaging.Modifier and Type | Class and Description |
---|---|
protected static class |
GrpcMessagingConnection.ConnectionOwner
Defines the owner of connection.
|
protected static class |
GrpcMessagingConnection.ContextualFuture<T>
A future with catalyst thread context.
|
protected static class |
GrpcMessagingConnection.HandlerHolder
Holds message handler and catalyst thread context.
|
Constructor and Description |
---|
GrpcMessagingConnection(GrpcMessagingConnection.ConnectionOwner connectionOwner,
String transportId,
GrpcMessagingContext context,
ExecutorService executor,
long requestTimeoutMs)
Creates a connection object.
|
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Void> |
close()
Closes the connection.
|
<T,U> GrpcMessagingConnection |
handler(Class<T> type,
java.util.function.Consumer<T> handler)
Registers a new message handler.
|
<T,U> GrpcMessagingConnection |
handler(Class<T> type,
java.util.function.Function<T,CompletableFuture<U>> handler)
Registers a new message handler.
|
protected void |
handleResponseMessage(TransportMessage response) |
Listener<GrpcMessagingConnection> |
onClose(java.util.function.Consumer<GrpcMessagingConnection> listener)
Adds a close listener.
|
void |
onCompleted() |
void |
onError(Throwable t) |
Listener<Throwable> |
onException(java.util.function.Consumer<Throwable> listener)
Adds an exception listener.
|
void |
onNext(TransportMessage message) |
CompletableFuture<Void> |
send(Object request)
Sends a request.
|
<T,U> CompletableFuture<U> |
sendAndReceive(T request)
Sends a request and receives a response.
|
void |
setTargetObserver(io.grpc.stub.StreamObserver<TransportMessage> targetObserver)
Sets the stream observer for target.
|
String |
toString() |
public GrpcMessagingConnection(GrpcMessagingConnection.ConnectionOwner connectionOwner, String transportId, GrpcMessagingContext context, ExecutorService executor, long requestTimeoutMs)
setTargetObserver(io.grpc.stub.StreamObserver<alluxio.grpc.TransportMessage>)
should be called explicitly before using the connection.connectionOwner
- owner of connectiontransportId
- transport level Idcontext
- catalyst thread contextexecutor
- transport executorrequestTimeoutMs
- timeout in milliseconds for requestspublic void setTargetObserver(io.grpc.stub.StreamObserver<TransportMessage> targetObserver)
targetObserver
- target's stream observerpublic CompletableFuture<Void> send(Object request)
request
- the request to sendpublic <T,U> CompletableFuture<U> sendAndReceive(T request)
T
- Request typeU
- Response typerequest
- the request to sendpublic <T,U> GrpcMessagingConnection handler(Class<T> type, java.util.function.Consumer<T> handler)
T
- the class and handler typeU
- the result typetype
- type of the handlerhandler
- the actual handler to registerpublic <T,U> GrpcMessagingConnection handler(Class<T> type, java.util.function.Function<T,CompletableFuture<U>> handler)
T
- the class and handler typeU
- the result typetype
- type of the handlerhandler
- the actual handler to registerprotected void handleResponseMessage(TransportMessage response)
public Listener<Throwable> onException(java.util.function.Consumer<Throwable> listener)
listener
- the listener to addpublic Listener<GrpcMessagingConnection> onClose(java.util.function.Consumer<GrpcMessagingConnection> listener)
listener
- the listener to addpublic CompletableFuture<Void> close()
public void onNext(TransportMessage message)
onNext
in interface io.grpc.stub.StreamObserver<TransportMessage>
public void onError(Throwable t)
onError
in interface io.grpc.stub.StreamObserver<TransportMessage>
public void onCompleted()
onCompleted
in interface io.grpc.stub.StreamObserver<TransportMessage>
Copyright © 2023. All Rights Reserved.