org.reactivestreams.api.Producer Maven / Gradle / Ivy
package org.reactivestreams.api;
import org.reactivestreams.spi.Publisher;
/**
* A Producer is the logical source of elements of a given type.
* The underlying implementation is done by way of a {@link org.reactivestreams.spi.Publisher Publisher}.
* This interface is the user-level API for a source while a Publisher is the
* SPI.
*
* Implementations of this interface will typically offer domain- or language-specific
* methods for transforming or otherwise interacting with the produced stream of elements.
*/
public interface Producer {
/**
* Get the underlying {@link org.reactivestreams.spi.Publisher Publisher} for this Producer. This method should only be used by
* implementations of this API.
* @return the underlying publisher for this producer
*/
public Publisher getPublisher();
/**
* Connect the given consumer to this producer. This means that the
* Subscriber underlying the {@link org.reactivestreams.api.Consumer Consumer} subscribes to this Producer’s
* underlying {@link org.reactivestreams.spi.Publisher Publisher}, which will initiate the transfer of the produced
* stream of elements from producer to consumer until either of three things
* happen:
*
*
* - The stream ends normally (no more elements available).
* - The producer encounters a fatal error condition.
* - The consumer cancels the reception of more elements.
*
* @param consumer The consumer to register with this producer.
*/
public void produceTo(Consumer consumer);
}