Package io.grpc.stub

Class ServerCalls.ServerCallStreamObserverImpl<ReqT,​RespT>

    • Field Detail

      • serverStreamingOrBidi

        private final boolean serverStreamingOrBidi
      • cancelled

        volatile boolean cancelled
      • frozen

        private boolean frozen
      • autoRequestEnabled

        private boolean autoRequestEnabled
      • sentHeaders

        private boolean sentHeaders
      • onReadyHandler

        private java.lang.Runnable onReadyHandler
      • onCancelHandler

        private java.lang.Runnable onCancelHandler
      • aborted

        private boolean aborted
      • completed

        private boolean completed
      • onCloseHandler

        private java.lang.Runnable onCloseHandler
    • Constructor Detail

      • ServerCallStreamObserverImpl

        ServerCallStreamObserverImpl​(ServerCall<ReqT,​RespT> call,
                                     boolean serverStreamingOrBidi)
    • Method Detail

      • freeze

        private void freeze()
      • setCompression

        public void setCompression​(java.lang.String compression)
        Description copied from class: ServerCallStreamObserver
        Sets the compression algorithm to use for the call. May only be called before sending any messages. Default gRPC servers support the "gzip" compressor.

        It is safe to call this even if the client does not support the compression format chosen. The implementation will handle negotiation with the client and may fall back to no compression.

        Specified by:
        setCompression in class ServerCallStreamObserver<RespT>
        Parameters:
        compression - the compression algorithm to use.
      • onNext

        public void onNext​(RespT response)
        Description copied from interface: StreamObserver
        Receives a value from the stream.

        Can be called many times but is never called after StreamObserver.onError(Throwable) or StreamObserver.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 StreamObserver.onError(Throwable) with the caught exception prior to propagating it.

        Parameters:
        response - the value passed to the stream
      • onError

        public void onError​(java.lang.Throwable t)
        Description copied from interface: StreamObserver
        Receives a terminating error from the stream.

        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).

        Parameters:
        t - the error occurred on the stream
      • onCompleted

        public void onCompleted()
        Description copied from interface: StreamObserver
        Receives a notification of successful stream completion.

        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.

      • setOnReadyHandler

        public void setOnReadyHandler​(java.lang.Runnable r)
        Description copied from class: ServerCallStreamObserver
        Set a Runnable that will be executed every time the stream ServerCallStreamObserver.isReady() state changes from false to true. While it is not guaranteed that the same thread will always be used to execute the Runnable, it is guaranteed that executions are serialized with calls to the 'inbound' StreamObserver.

        May only be called during the initial call to the application, before the service returns its StreamObserver.

        Because there is a processing delay to deliver this notification, it is possible for concurrent writes to cause isReady() == false within this callback. Handle "spurious" notifications by checking isReady()'s current value instead of assuming it is now true. If isReady() == false the normal expectations apply, so there would be another onReadyHandler callback.

        Specified by:
        setOnReadyHandler in class ServerCallStreamObserver<RespT>
        Parameters:
        r - to call when peer is ready to receive more messages.
      • isCancelled

        public boolean isCancelled()
        Description copied from class: ServerCallStreamObserver
        Returns true when the call is cancelled and the server is encouraged to abort processing to save resources, since the client will not be processing any further methods. Cancellations can be caused by timeouts, explicit cancellation by client, network errors, and similar.

        This method may safely be called concurrently from multiple threads.

        Specified by:
        isCancelled in class ServerCallStreamObserver<RespT>
      • setOnCancelHandler

        public void setOnCancelHandler​(java.lang.Runnable onCancelHandler)
        Description copied from class: ServerCallStreamObserver
        Sets a Runnable to be called if the call is cancelled and the server is encouraged to abort processing to save resources, since the client will not process any further messages. Cancellations can be caused by timeouts, explicit cancellation by the client, network errors, etc.

        It is guaranteed that execution of the Runnable is serialized with calls to the 'inbound' StreamObserver. That also means that the callback will be delayed if other callbacks are running; if one of those other callbacks runs for a significant amount of time it can poll ServerCallStreamObserver.isCancelled(), which is not delayed.

        This method may only be called during the initial call to the application, before the service returns its StreamObserver.

        Setting the onCancelHandler will suppress the on-cancel exception thrown by StreamObserver.onNext(V). If the caller is already handling cancellation via polling or cannot substantially benefit from observing cancellation, using a no-op onCancelHandler is useful just to suppress the onNext() exception.

        Specified by:
        setOnCancelHandler in class ServerCallStreamObserver<RespT>
        Parameters:
        onCancelHandler - to call when client has cancelled the call.
      • setOnReadyThreshold

        public void setOnReadyThreshold​(int numBytes)
        Description copied from class: ServerCallStreamObserver
        A hint to the call that specifies how many bytes must be queued before ServerCallStreamObserver.isReady() will return false. A call may ignore this property if unsupported. This may only be set during stream initialization before any messages are set.
        Overrides:
        setOnReadyThreshold in class ServerCallStreamObserver<RespT>
        Parameters:
        numBytes - The number of bytes that must be queued. Must be a positive integer.
      • request

        public void request​(int count)
        Description copied from class: ServerCallStreamObserver
        Requests the peer to produce count more messages to be delivered to the 'inbound' StreamObserver.

        This method is safe to call from multiple threads without external synchronization.

        Specified by:
        request in class ServerCallStreamObserver<RespT>
        Parameters:
        count - more messages
      • setOnCloseHandler

        public void setOnCloseHandler​(java.lang.Runnable onCloseHandler)
        Description copied from class: ServerCallStreamObserver
        Sets a Runnable to be executed when the call is closed cleanly from the server's point of view: either StreamObserver.onCompleted() or StreamObserver.onError(Throwable) has been called, all the messages and trailing metadata have been sent and the stream has been closed. Note however that the client still may have not received all the messages due to network delay, client crashes, and cancellation races.

        Exactly one of onCloseHandler and onCancelHandler is guaranteed to be called when the RPC terminates.

        It is guaranteed that execution of onCloseHandler is serialized with calls to the 'inbound' StreamObserver. That also means that the callback will be delayed if other callbacks are running.

        This method may only be called during the initial call to the application, before the service returns its request observer.

        Overrides:
        setOnCloseHandler in class ServerCallStreamObserver<RespT>
        Parameters:
        onCloseHandler - to execute when the call has been closed cleanly.