Interface ServerStream

All Superinterfaces:
Stream
All Known Implementing Classes:
AbstractServerStream

public interface ServerStream extends Stream
Extension of Stream to support server-side termination semantics.

An implementation doesn't need to be thread-safe. All methods are expected to execute quickly.

  • Method Details

    • writeHeaders

      void writeHeaders(Metadata headers, boolean flush)
      Writes custom metadata as headers on the response stream sent to the client. This method may only be called once and cannot be called after calls to Stream.writeMessage(java.io.InputStream) or close(io.grpc.Status, io.grpc.Metadata).
      Parameters:
      headers - to send to client.
    • close

      void close(Status status, Metadata trailers)
      Closes the stream for both reading and writing. A status code of Status.Code.OK implies normal termination of the stream. Any other value implies abnormal termination.

      Attempts to read from or write to the stream after closing should be ignored by implementations, and should not throw exceptions.

      Parameters:
      status - details of the closure
      trailers - an additional block of metadata to pass to the client on stream closure.
    • cancel

      void cancel(Status status)
      Tears down the stream, typically in the event of a timeout. This method may be called multiple times and from any thread.
    • setDecompressor

      void setDecompressor(Decompressor decompressor)
      Sets the decompressor on the deframer. If the transport does not support compression, this may do nothing.
      Parameters:
      decompressor - the decompressor to use.
    • getAttributes

      Attributes getAttributes()
      Attributes describing stream. This is inherited from the transport attributes, and used as the basis of ServerCall.getAttributes().
      Returns:
      Attributes container
    • getAuthority

      @Nullable String getAuthority()
      Gets the authority this stream is addressed to.
      Returns:
      the authority string. null if not available.
    • setListener

      void setListener(ServerStreamListener serverStreamListener)
      Sets the server stream listener.
    • statsTraceContext

      StatsTraceContext statsTraceContext()
      The context for recording stats and traces for this stream.
    • streamId

      int streamId()
      The HTTP/2 stream id, or -1 if not supported.
    • setOnReadyThreshold

      void setOnReadyThreshold(int numBytes)
      A hint to the stream that specifies how many bytes must be queued before Stream.isReady() will return false. A stream may ignore this property if unsupported. This may only be set during stream initialization before any messages are set.
      Parameters:
      numBytes - The number of bytes that must be queued. Must be a positive integer.