Interface Stream

All Known Subinterfaces:
ClientStream, ServerStream
All Known Implementing Classes:
AbstractClientStream, AbstractServerStream, AbstractStream, FailingClientStream, NoopClientStream

public interface Stream
A single stream of communication between two end-points within a transport.

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

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Flushes any internally buffered messages to the remote end-point.
    boolean
    If true, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally.
    void
    Provides a hint that directExecutor is being used by the listener for callbacks to the application.
    void
    request(int numMessages)
    Requests up to the given number of messages from the call to be delivered via StreamListener.messagesAvailable(StreamListener.MessageProducer).
    void
    Sets the compressor on the framer.
    void
    setMessageCompression(boolean enable)
    Enables per-message compression, if an encoding type has been negotiated.
    void
    Writes a message payload to the remote end-point.
  • Method Details

    • request

      void request(int numMessages)
      Requests up to the given number of messages from the call to be delivered via StreamListener.messagesAvailable(StreamListener.MessageProducer). No additional messages will be delivered. If the stream has a start() method, it must be called before requesting messages.
      Parameters:
      numMessages - the requested number of messages to be delivered to the listener.
    • writeMessage

      void writeMessage(InputStream message)
      Writes a message payload to the remote end-point. The bytes from the stream are immediately read by the Transport. Where possible callers should use streams that are KnownLength to improve efficiency. This method will always return immediately and will not wait for the write to complete. If the stream has a start() method, it must be called before writing any messages.

      It is recommended that the caller consult isReady() before calling this method to avoid excessive buffering in the transport.

      This method takes ownership of the InputStream, and implementations are responsible for calling InputStream.close().

      Parameters:
      message - stream containing the serialized message to be sent
    • flush

      void flush()
      Flushes any internally buffered messages to the remote end-point.
    • isReady

      boolean isReady()
      If true, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally. Otherwise, StreamListener.onReady() will be called when it turns true.

      This is just a suggestion and the application is free to ignore it, however doing so may result in excessive buffering within the transport.

    • optimizeForDirectExecutor

      void optimizeForDirectExecutor()
      Provides a hint that directExecutor is being used by the listener for callbacks to the application. No action is required. There is no requirement that this method actually matches the executor used.
    • setCompressor

      void setCompressor(Compressor compressor)
      Sets the compressor on the framer.
      Parameters:
      compressor - the compressor to use
    • setMessageCompression

      void setMessageCompression(boolean enable)
      Enables per-message compression, if an encoding type has been negotiated. If no message encoding has been negotiated, this is a no-op. By default per-message compression is enabled, but may not have any effect if compression is not enabled on the call.