public interface StreamObserver<V>
It is used by both the client stubs and service implementations for sending or receiving
stream messages. It is used for all MethodDescriptor.MethodType
, including
UNARY
calls. For outgoing messages, a StreamObserver
is provided by the GRPC
library to the application. For incoming messages, the application implements the
StreamObserver
and passes it to the GRPC library for receiving.
Implementations are not required to be thread-safe (but should be
thread-compatible).
Separate StreamObserver
s do
not need to be synchronized together; incoming and outgoing directions are independent.
Since individual StreamObserver
s are not thread-safe, if multiple threads will be
writing to a StreamObserver
concurrently, the application must synchronize calls.
Modifier and Type | Method and Description |
---|---|
void |
onCompleted()
Receives a notification of successful stream completion.
|
void |
onError(Throwable t)
Receives a terminating error from the stream.
|
void |
onNext(V value)
Receives a value from the stream.
|
void onNext(V value)
Can be called many times but is never called after onError(Throwable)
or onCompleted()
are called.
Unary calls must invoke onNext at most once. Clients may invoke onNext at most once for server streaming calls, but may receive many onNext callbacks. Servers may invoke onNext at most once for client streaming calls, but may receive many onNext callbacks.
If an exception is thrown by an implementation the caller is expected to terminate the
stream by calling onError(Throwable)
with the caught exception prior to
propagating it.
value
- the value passed to the streamvoid onError(Throwable t)
May only be called once and if called it must be the last method called. In particular if an
exception is thrown by an implementation of onError
no further calls to any method are
allowed.
t
should be a StatusException
or StatusRuntimeException
, but other Throwable
types are possible. Callers should
generally convert from a Status
via Status.asException()
or
Status.asRuntimeException()
. Implementations should generally convert to a
Status
via Status.fromThrowable(Throwable)
.
t
- the error occurred on the streamvoid onCompleted()
May only be called once and if called it must be the last method called. In particular if an
exception is thrown by an implementation of onCompleted
no further calls to any method
are allowed.