Class WriteStream.WriteStreamImpl<T>

java.lang.Object
io.vertx.mutiny.core.streams.WriteStream.WriteStreamImpl<T>
All Implemented Interfaces:
MutinyDelegate, StreamBase, WriteStream<T>
Enclosing interface:
WriteStream<T>

public static class WriteStream.WriteStreamImpl<T> extends Object implements WriteStream<T>
  • Field Details

    • __typeArg_0

      public final TypeArg<T> __typeArg_0
  • Constructor Details

    • WriteStreamImpl

      public WriteStreamImpl(io.vertx.core.streams.WriteStream<T> delegate)
      Create a new instance of WriteStream.WriteStreamImpl delegating to the given (non-null) instance of WriteStream.
    • WriteStreamImpl

      public WriteStreamImpl(io.vertx.core.streams.WriteStream<T> delegate, TypeArg<T> typeArg_0)
  • Method Details

    • getDelegate

      public io.vertx.core.streams.WriteStream<T> getDelegate()
      Get the delegate instance.

      This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.

      Specified by:
      getDelegate in interface MutinyDelegate
      Specified by:
      getDelegate in interface StreamBase
      Specified by:
      getDelegate in interface WriteStream<T>
      Returns:
      the delegate instance
    • write

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> write(T data)
      Write some data to the stream.

      The data is usually put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the writeQueueFull() method before writing. This is done automatically if using a Pipe.

      When the data is moved from the queue to the actual medium, the returned Future will be completed with the write result, e.g the uni is succeeded when a server HTTP response buffer is written to the socket and failed if the remote client has closed the socket while the data was still pending for write.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Specified by:
      write in interface WriteStream<T>
      Parameters:
      data - the data to write
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • io.vertx.core.streams.WriteStream#write(T)
    • writeAndAwait

      public void writeAndAwait(T data)
      Write some data to the stream.

      The data is usually put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the writeQueueFull() method before writing. This is done automatically if using a Pipe.

      When the data is moved from the queue to the actual medium, the returned Future will be completed with the write result, e.g the underlying uni is succeeded when a server HTTP response buffer is written to the socket and failed if the remote client has closed the socket while the data was still pending for write.

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      data - the data to write
      See Also:
      • io.vertx.core.streams.WriteStream#write(T)
    • writeAndForget

      public WriteStream.WriteStreamImpl<T> writeAndForget(T data)
      Write some data to the stream.

      The data is usually put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the writeQueueFull() method before writing. This is done automatically if using a Pipe.

      When the data is moved from the queue to the actual medium, the returned Future will be completed with the write result, e.g the underlying uni is succeeded when a server HTTP response buffer is written to the socket and failed if the remote client has closed the socket while the data was still pending for write.

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Parameters:
      data - the data to write
      Returns:
      The current instance to chain operations if needed.
      See Also:
      • io.vertx.core.streams.WriteStream#write(T)
    • end

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> end()
      Ends the stream.

      Once the stream has ended, it cannot be used any more.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Specified by:
      end in interface WriteStream<T>
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • WriteStream.end()
    • endAndAwait

      public void endAndAwait()
      Ends the stream.

      Once the stream has ended, it cannot be used any more.

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      See Also:
      • WriteStream.end()
    • endAndForget

      public WriteStream.WriteStreamImpl<T> endAndForget()
      Ends the stream.

      Once the stream has ended, it cannot be used any more.

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • WriteStream.end()
    • end

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> end(T data)
      Same as end() but writes some data to the stream before ending.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Specified by:
      end in interface WriteStream<T>
      Parameters:
      data - the data to write
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • io.vertx.core.streams.WriteStream#end(T)
    • endAndAwait

      public void endAndAwait(T data)
      Same as end() but writes some data to the stream before ending.

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      data - the data to write
      See Also:
      • io.vertx.core.streams.WriteStream#end(T)
    • endAndForget

      public WriteStream.WriteStreamImpl<T> endAndForget(T data)
      Same as end() but writes some data to the stream before ending.

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Parameters:
      data - the data to write
      Returns:
      The current instance to chain operations if needed.
      See Also:
      • io.vertx.core.streams.WriteStream#end(T)
    • exceptionHandler

      public WriteStream<T> exceptionHandler(Consumer<Throwable> handler)
      Set an exception handler on the write stream.
      Specified by:
      exceptionHandler in interface StreamBase
      Specified by:
      exceptionHandler in interface WriteStream<T>
      Parameters:
      handler - the exception handler. Can be null.
      Returns:
      a reference to this, so the API can be used fluently
    • setWriteQueueMaxSize

      public WriteStream.WriteStreamImpl<T> setWriteQueueMaxSize(int maxSize)
      Set the maximum size of the write queue to maxSize. You will still be able to write to the stream even if there is more than maxSize items in the write queue. This is used as an indicator by classes such as Pipe to provide flow control.

      The value is defined by the implementation of the stream, e.g in bytes for a NetSocket, etc...

      Specified by:
      setWriteQueueMaxSize in interface WriteStream<T>
      Parameters:
      maxSize - the max size of the write stream
      Returns:
      a reference to this, so the API can be used fluently
    • writeQueueFull

      public boolean writeQueueFull()
      This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize(int)
      Specified by:
      writeQueueFull in interface WriteStream<T>
      Returns:
      true if write queue is full
    • drainHandler

      public WriteStream.WriteStreamImpl<T> drainHandler(Runnable handler)
      Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See Pipe for an example of this being used.

      The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to maxSize / 2.

      Specified by:
      drainHandler in interface WriteStream<T>
      Parameters:
      handler - the handler. Can be null.
      Returns:
      a reference to this, so the API can be used fluently