All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vlingo.reactivestreams.Stream Maven / Gradle / Ivy

There is a newer version: 1.7.5
Show newest version
package io.vlingo.reactivestreams;

/**
 * A {@code Stream} protocol implemented by the publisher side and
 * started by the subscribing side using a {@code Sink} as inflow.
 */
public interface Stream {
  /** The default rate of flow bursts. */
  public static final long DefaultFlowRate = 100;

  /** The default interval to poll the {@code Source}. */
  public static final int DefaultProbeInterval = PublisherConfiguration.DefaultProbeInterval;

  /** The fast interval to poll the {@code Source}. */
  public static int FastProbeInterval = PublisherConfiguration.FastProbeInterval;

  /** The fastest interval to poll the {@code Source}. */
  public static int FastestProbeInterval = PublisherConfiguration.FastestProbeInterval;

  /**
   * Potentially changes the underlying {@code Subscriber}'s {@code flowElementsRate}
   * if its current is not equal to the {@code flowElementsRate}.
   * @param flowElementsRate the long rate at which new elements will flow into the {@code Sink}
   */
  void request(final long flowElementsRate);

  /**
   * Starts the flow from {@code Publisher} to {@code Subscriber}, which in turn flows the
   * elements to the {@code sink}. The {@code DefaultFlowRate} and {@code DefaultProbeInterval}
   * are used.
   * @param sink the {@code Sink} to which the {@code Subscriber} pushes elements
   * @param  the type of the elements that the Sink intakes
   */
   void flowInto(final Sink sink);

  /**
   * Starts the flow from {@code Publisher} to {@code Subscriber} at the rate of
   * {@code flowElementsRate}, which in turn flows the elements to the {@code sink}.
   * The {@code DefaultProbeInterval} is used.
   * @param sink the {@code Sink} to which the {@code Subscriber} pushes elements
   * @param flowElementsRate the long limit of elements to push to the Sink at any one time
   * @param  the type of the elements that the Sink intakes
   */
   void flowInto(final Sink sink, final long flowElementsRate);

  /**
   * Starts the flow from {@code Publisher} to {@code Subscriber} at the rate of
   * {@code flowElementsRate}, which in turn flows the elements to the {@code sink}.
   * The {@code Publisher} will poll for new elements on every {@code probeInterval}.
   * @param sink the {@code Sink} to which the {@code Subscriber} pushes elements
   * @param flowElementsRate the long limit of elements to push to the Sink at any one time
   * @param probeInterval the int indicating how often the {@code Publisher} should poll its {@code Source}
   * @param  the type of the elements that the Sink intakes
   */
   void flowInto(final Sink sink, final long flowElementsRate, final int probeInterval);

  /**
   * Sends a message to the {@code Publisher} to stop polling elements from its
   * {@code Source} and pushing them to the {@code Sink} by way of the {@code Subscriber}.
   * Note that some elements may have already been pushed to the {@code Subscriber} but
   * have not yet fully flowed to the {@code Sink}. This means you cannot assume that
   * flow will stop immediately.
   */
  void stop();
}