nl.topicus.jdbc.shaded.io.grpc.stub.CallStreamObserver Maven / Gradle / Ivy
Show all versions of spanner-jdbc Show documentation
/*
* Copyright 2016, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.topicus.jdbc.shaded.io.grpc.stub;
import nl.topicus.jdbc.shaded.com.google.errorprone.annotations.DoNotMock;
import nl.topicus.jdbc.shaded.io.grpc.ExperimentalApi;
/**
* A refinement of StreamObserver provided by the GRPC runtime to the application that allows for
* more complex interactions with call behavior.
*
* In any call there are logically two {@link StreamObserver} implementations:
*
* - 'inbound' - which the GRPC runtime calls when it receives messages from the
* remote peer. This is implemented by the application.
*
* - 'outbound' - which the GRPC runtime provides to the application which it uses to
* send messages to the remote peer.
*
*
*
* Implementations of this class represent the 'outbound' message stream.
*
*
Like {@code StreamObserver}, implementations are not required to be thread-safe; if multiple
* threads will be writing to an instance concurrently, the application must synchronize its calls.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1788")
@DoNotMock
public abstract class CallStreamObserver implements StreamObserver {
/**
* If {@code true}, indicates that the observer is capable of sending additional messages
* without requiring excessive buffering internally. This value is just a suggestion and the
* application is free to ignore it, however doing so may result in excessive buffering within the
* observer.
*/
public abstract boolean isReady();
/**
* Set a {@link Runnable} that will be executed every time the stream {@link #isReady()} state
* changes from {@code false} to {@code true}. While it is not guaranteed that the same
* thread will always be used to execute the {@link Runnable}, it is guaranteed that executions
* are serialized with calls to the 'inbound' {@link StreamObserver}.
*
* On client-side this method may only be called during {@link
* ClientResponseObserver#beforeStart}. On server-side it may only be called during the initial
* call to the application, before the service returns its {@code StreamObserver}.
*
*
Note that the handler may be called some time after {@link #isReady} has transitioned to
* true as other callbacks may still be executing in the 'inbound' observer.
*
* @param onReadyHandler to call when peer is ready to receive more messages.
*/
public abstract void setOnReadyHandler(Runnable onReadyHandler);
/**
* Disables automatic flow control where a token is returned to the peer after a call
* to the 'inbound' {@link nl.topicus.jdbc.shaded.io.grpc.stub.StreamObserver#onNext(Object)} has completed. If disabled
* an application must make explicit calls to {@link #request} to receive messages.
*
*
On client-side this method may only be called during {@link
* ClientResponseObserver#beforeStart}. On server-side it may only be called during the initial
* call to the application, before the service returns its {@code StreamObserver}.
*
*
Note that for cases where the runtime knows that only one inbound message is allowed
* calling this method will have no effect and the runtime will always permit one and only
* one message. This is true for:
*
* - {@link nl.topicus.jdbc.shaded.io.grpc.MethodDescriptor.MethodType#UNARY} operations on both the
* client and server.
*
* - {@link nl.topicus.jdbc.shaded.io.grpc.MethodDescriptor.MethodType#CLIENT_STREAMING} operations on the server.
*
* - {@link nl.topicus.jdbc.shaded.io.grpc.MethodDescriptor.MethodType#SERVER_STREAMING} operations on the client.
*
*
*
*/
public abstract void disableAutoInboundFlowControl();
/**
* Requests the peer to produce {@code count} more messages to be delivered to the 'inbound'
* {@link StreamObserver}.
*
* This method is safe to call from multiple threads without external synchronization.
*
* @param count more messages
*/
public abstract void request(int count);
/**
* Sets message compression for subsequent calls to {@link #onNext}.
*
* @param enable whether to enable compression.
*/
public abstract void setMessageCompression(boolean enable);
}