@InternalApi public class ReframingResponseObserver<InnerT,OuterT> extends StateCheckingResponseObserver<InnerT>
ResponseObservers. It is intended for situations when a
stream needs to be transformed in such a way where the incoming responses do not map 1:1 to the
output responses.
This class manages back pressure between M upstream responses and N downstream responses. It
buffers responses when M > N and spools them when M < N. The downstream responses will be
delivered via either the upstream thread or the downstream thread that called request(); in
either case, the downstream methods will be invoked sequentially. Neither the downstream ResponseObserver nor the Reframer need to be threadsafe.
Expected usage:
class OuterStreamingCallable extends ServerStreamingCallable<Request, FullResponse> {
private final ServerStreamingCallable<Request, Chunk> innerCallable;
OuterStreamingCallable(ServerStreamingCallable<Request, Chunk> innerCallable) {
this.innerCallable = innerCallable;
}
public void call(Request request, ResponseObserver<FullResponse> outerResponseObserver,
ApiCallContext context) {
Reframer<Chunk, FullResponse> myReframer = new Reframer<>();
innerCallable.call(request, new ReframingResponseObserver(myReframer, outerResponseObserver),
context);
}
}
| Constructor and Description |
|---|
ReframingResponseObserver(ResponseObserver<OuterT> observer,
Reframer<OuterT,InnerT> reframer) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
onCompleteImpl()
Process inner/upstream callable's onComplete notification.
|
protected void |
onErrorImpl(Throwable t)
Process inner/upstream callable's onError notification.
|
protected void |
onResponseImpl(InnerT response)
Accept a new response from inner/upstream callable.
|
protected void |
onStartImpl(StreamController controller)
Callback that will be notified when the inner/upstream callable starts.
|
onComplete, onError, onResponse, onStartpublic ReframingResponseObserver(ResponseObserver<OuterT> observer, Reframer<OuterT,InnerT> reframer)
protected void onStartImpl(StreamController controller)
onStartImpl in class StateCheckingResponseObserver<InnerT>controller - The controller for the upstream stream.protected void onResponseImpl(InnerT response)
Reframer in the delivery loop and the output will be delivered to the downstream ResponseObserver.
If the delivery loop is stopped, this will restart it.
onResponseImpl in class StateCheckingResponseObserver<InnerT>protected void onErrorImpl(Throwable t)
If the delivery loop is stopped, this will restart it.
onErrorImpl in class StateCheckingResponseObserver<InnerT>protected void onCompleteImpl()
If the delivery loop is stopped, this will restart it.
onCompleteImpl in class StateCheckingResponseObserver<InnerT>Copyright © 2019 Google LLC. All rights reserved.