Class AbstractStream

  • All Implemented Interfaces:
    Stream
    Direct Known Subclasses:
    AbstractClientStream, AbstractServerStream

    public abstract class AbstractStream
    extends java.lang.Object
    implements Stream
    The stream and stream state as used by the application. Must only be called from the sending application thread.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  AbstractStream.TransportState
      Stream state as used by the transport.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractStream()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void endOfMessages()
      Closes the underlying framer.
      void flush()
      Flushes any internally buffered messages to the remote end-point.
      protected abstract Framer framer()
      The framer to use for sending messages.
      boolean isReady()
      If true, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally.
      protected void onSendingBytes​(int numBytes)
      Event handler to be called by the subclass when a number of bytes are being queued for sending to the remote endpoint.
      void optimizeForDirectExecutor()
      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 setCompressor​(Compressor compressor)
      Sets the compressor on the framer.
      void setMessageCompression​(boolean enable)
      Enables per-message compression, if an encoding type has been negotiated.
      protected void setOnReadyThreshold​(int numBytes)
      A hint to the stream that specifies how many bytes must be queued before isReady() will return false.
      protected abstract AbstractStream.TransportState transportState()
      Obtain the transport state corresponding to this stream.
      void writeMessage​(java.io.InputStream message)
      Writes a message payload to the remote end-point.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractStream

        public AbstractStream()
    • Method Detail

      • framer

        protected abstract Framer framer()
        The framer to use for sending messages.
      • transportState

        protected abstract AbstractStream.TransportState transportState()
        Obtain the transport state corresponding to this stream. Each stream must have its own unique transport state.
      • optimizeForDirectExecutor

        public void optimizeForDirectExecutor()
        Description copied from interface: Stream
        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.
        Specified by:
        optimizeForDirectExecutor in interface Stream
      • setMessageCompression

        public final void setMessageCompression​(boolean enable)
        Description copied from interface: Stream
        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.
        Specified by:
        setMessageCompression in interface Stream
      • request

        public final void request​(int numMessages)
        Description copied from interface: Stream
        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.
        Specified by:
        request in interface Stream
        Parameters:
        numMessages - the requested number of messages to be delivered to the listener.
      • writeMessage

        public final void writeMessage​(java.io.InputStream message)
        Description copied from interface: Stream
        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 Stream.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().

        Specified by:
        writeMessage in interface Stream
        Parameters:
        message - stream containing the serialized message to be sent
      • flush

        public final void flush()
        Description copied from interface: Stream
        Flushes any internally buffered messages to the remote end-point.
        Specified by:
        flush in interface Stream
      • setOnReadyThreshold

        protected void setOnReadyThreshold​(int numBytes)
        A hint to the stream that specifies how many bytes must be queued before 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.
      • endOfMessages

        protected final void endOfMessages()
        Closes the underlying framer. Should be called when the outgoing stream is gracefully closed (half closure on client; closure on server).
      • setCompressor

        public final void setCompressor​(Compressor compressor)
        Description copied from interface: Stream
        Sets the compressor on the framer.
        Specified by:
        setCompressor in interface Stream
        Parameters:
        compressor - the compressor to use
      • isReady

        public boolean isReady()
        Description copied from interface: Stream
        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.

        Specified by:
        isReady in interface Stream
      • onSendingBytes

        protected final void onSendingBytes​(int numBytes)
        Event handler to be called by the subclass when a number of bytes are being queued for sending to the remote endpoint.
        Parameters:
        numBytes - the number of bytes being sent.