Module mutiny.zero
Package mutiny.zero

Interface Tube<T>

Type Parameters:
T - the items type

public interface Tube<T>
A Tube is a general-purpose abstraction for creating Flow.Publisher.

Items, errors and completion signals can be sent using this interface. It is possible to be notified of requests, cancellations and termination.

A Tube can be shared between multiple threads, and sending items from concurrent threads is done serially as per reactive stream semantics.

If in doubt about which abstraction to use for creating a Flow.Publisher with ZeroPublisher then choose a Tube.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Check if the subscription has been cancelled.
    void
    Signal completion and that no more items will be sent.
    void
    Terminally signal an error.
    long
    Check the number of outstanding requests.
    send(T item)
    Send an item.
    Define an action when the subscription is cancelled.
    Define an action when items are being requested.
    Define an action on termination (completion, error or cancellation), typically for cleanup purposes.
  • Method Details

    • send

      Tube<T> send(T item)
      Send an item.
      Parameters:
      item - the item
      Returns:
      this Tube instance
    • fail

      void fail(Throwable err)
      Terminally signal an error.
      Parameters:
      err - the error
    • complete

      void complete()
      Signal completion and that no more items will be sent.
    • cancelled

      boolean cancelled()
      Check if the subscription has been cancelled.
      Returns:
      true if the subscriber has cancelled its subscription, false otherwise
    • outstandingRequests

      long outstandingRequests()
      Check the number of outstanding requests.
      Returns:
      the number of outstanding requests.
    • whenCancelled

      Tube<T> whenCancelled(Runnable action)
      Define an action when the subscription is cancelled.
      Parameters:
      action - the action
      Returns:
      this Tube
    • whenTerminates

      Tube<T> whenTerminates(Runnable action)
      Define an action on termination (completion, error or cancellation), typically for cleanup purposes.
      Parameters:
      action - the action
      Returns:
      this Tube
    • whenRequested

      Tube<T> whenRequested(LongConsumer consumer)
      Define an action when items are being requested.
      Parameters:
      consumer - the action, consuming the number of items for this request
      Returns:
      this Tube