Package io.grpc.stub
The gRPC Java API is split into two main parts: The stub layer and the call layer. The stub layer is a wrapper around the call layer.
In the most common case of gRPC over Protocol Buffers, stub classes are automatically generated from service definition .proto files by the Protobuf compiler. See gRPC Java Generated Code Guide .
The server side stub classes are abstract classes with RPC methods for the server application
to implement/override. These classes internally use ServerCalls
to interact
with the call layer. The RPC methods consume a StreamObserver
object
responseObserver
as one of its arguments. When users are implementing/override these
methods in the server application, they may call the onNext()
, onError()
and onCompleted()
methods on the responseObserver
argument to send out a response message, error and completion notification respectively. If the
RPC is client-streaming or bidirectional-streaming, the abstract RPC method should return a
requestObserver
which is also a StreamObserver
object. User should
typically implement the onNext()
, onError()
and onCompleted()
callbacks of requestObserver
to define how the server application would
react when receiving a message, error and completion notification respectively from the client
side.
The client side stub classes are implementations of AbstractStub
that
provide the RPC methods for the client application to call. The RPC methods in the client stubs
internally use ClientCalls
to interact with the call layer. For asynchronous
stubs, the RPC methods also consume a StreamObserver
object
responseObserver
as one of its arguments, and moreover for client-streaming or
bidirectional-streaming, also return a requestObserver
which is also a StreamObserver
object. In contrast to the server side, users should implement the
onNext()
, onError()
and onCompleted()
callbacks of
responseObserver
to define what the client application would do when receiving a response
message, error and completion notification respectively from the server side, and then pass the
responseObserver
to the RPC method in the client stub. If the RPC method returns a
requestObserver
, users should call the onNext()
,
onError()
and onCompleted()
methods on the requestObserver
to
send out a request message, error and completion notification respectively.
-
Interface Summary Interface Description AbstractStub.StubFactory<T extends AbstractStub<T>> A factory class for stub.ClientResponseObserver<ReqT,RespT> Specialization ofStreamObserver
implemented by clients in order to interact with the advanced features of a call such as flow-control.ServerCalls.BidiStreamingMethod<ReqT,RespT> Adaptor to a bidirectional streaming method.ServerCalls.ClientStreamingMethod<ReqT,RespT> Adaptor to a client streaming method.ServerCalls.ServerStreamingMethod<ReqT,RespT> Adaptor to a server streaming method.ServerCalls.UnaryMethod<ReqT,RespT> Adaptor to a unary call method.StreamObserver<V> Receives notifications from an observable stream of messages. -
Class Summary Class Description AbstractAsyncStub<S extends AbstractAsyncStub<S>> Stub implementations for async stubs.AbstractBlockingStub<S extends AbstractBlockingStub<S>> Stub implementations for blocking stubs.AbstractFutureStub<S extends AbstractFutureStub<S>> Stub implementations for future stubs.AbstractStub<S extends AbstractStub<S>> Common base type for stub implementations.CallStreamObserver<V> A refinement of StreamObserver provided by the GRPC runtime to the application (the client or the server) that allows for more complex interactions with call behavior.ClientCalls Utility functions for processing different call idioms.ClientCallStreamObserver<ReqT> A refinement ofCallStreamObserver
that allows for lower-level interaction with client calls.MetadataUtils Utility functions for binding and receiving headers.ServerCalls Utility functions for adaptingServerCallHandler
s to application service implementation, meant to be used by the generated code.ServerCallStreamObserver<RespT> A refinement ofCallStreamObserver
to allows for interaction with call cancellation events on the server side.StreamObservers Deprecated. Of questionable utility and generally not used.