Stay organized with collections
Save and categorize content based on your preferences.
Flow.Publisher
public
static
interface
Flow.Publisher
java.util.concurrent.Flow.Publisher<T>
|
Known indirect subclasses
|
A producer of items (and related control messages) received by
Subscribers. Each current Subscriber
receives the same
items (via method onNext
) in the same order, unless
drops or errors are encountered. If a Publisher encounters an
error that does not allow items to be issued to a Subscriber,
that Subscriber receives onError
, and then receives no
further messages. Otherwise, when it is known that no further
messages will be issued to it, a subscriber receives onComplete
. Publishers ensure that Subscriber method
invocations for each subscription are strictly ordered in happens-before
order.
Publishers may vary in policy about whether drops (failures
to issue an item because of resource limitations) are treated
as unrecoverable errors. Publishers may also vary about
whether Subscribers receive items that were produced or
available before they subscribed.
Summary
Public methods |
abstract
void
|
subscribe(Subscriber<? super T> subscriber)
Adds the given Subscriber if possible.
|
Public methods
subscribe
public abstract void subscribe (Subscriber<? super T> subscriber)
Adds the given Subscriber if possible. If already
subscribed, or the attempt to subscribe fails due to policy
violations or errors, the Subscriber's onError
method is invoked with an IllegalStateException
.
Otherwise, the Subscriber's onSubscribe
method is
invoked with a new Subscription
. Subscribers may
enable receiving items by invoking the request
method of this Subscription, and may unsubscribe by
invoking its cancel
method.
Parameters |
subscriber |
Subscriber : the subscriber |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# Flow.Publisher\n\nAdded in [API level 30](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \n\nFlow.Publisher\n==============\n\n\n`\npublic\nstatic\n\n\ninterface\nFlow.Publisher\n`\n\n\n`\n\n\n`\n\n|------------------------------------------|\n| java.util.concurrent.Flow.Publisher\\\u003cT\\\u003e |\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [Flow.Processor](/reference/java/util/concurrent/Flow.Processor)\\\u003cT, R\\\u003e, [SubmissionPublisher](/reference/java/util/concurrent/SubmissionPublisher)\\\u003cT\\\u003e |---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Flow.Processor](/reference/java/util/concurrent/Flow.Processor)\\\u003cT, R\\\u003e | A component that acts as both a Subscriber and Publisher. | | [SubmissionPublisher](/reference/java/util/concurrent/SubmissionPublisher)\\\u003cT\\\u003e | A [Flow.Publisher](/reference/java/util/concurrent/Flow.Publisher) that asynchronously issues submitted (non-null) items to current subscribers until it is closed. | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA producer of items (and related control messages) received by\nSubscribers. Each current [Subscriber](/reference/java/util/concurrent/Flow.Subscriber) receives the same\nitems (via method `onNext`) in the same order, unless\ndrops or errors are encountered. If a Publisher encounters an\nerror that does not allow items to be issued to a Subscriber,\nthat Subscriber receives `onError`, and then receives no\nfurther messages. Otherwise, when it is known that no further\nmessages will be issued to it, a subscriber receives `onComplete`. Publishers ensure that Subscriber method\ninvocations for each subscription are strictly ordered in [*happens-before*](/reference/java/util/concurrent/package-summary#MemoryVisibility)\norder.\n\nPublishers may vary in policy about whether drops (failures\nto issue an item because of resource limitations) are treated\nas unrecoverable errors. Publishers may also vary about\nwhether Subscribers receive items that were produced or\navailable before they subscribed.\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[subscribe](/reference/java/util/concurrent/Flow.Publisher#subscribe(java.util.concurrent.Flow.Subscriber\u003c?%20super%20T\u003e))`(`[Subscriber](/reference/java/util/concurrent/Flow.Subscriber)`\u003c? super T\u003e subscriber) ` Adds the given Subscriber if possible. |\n\nPublic methods\n--------------\n\n### subscribe\n\nAdded in [API level 30](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void subscribe (Subscriber\u003c? super T\u003e subscriber)\n```\n\nAdds the given Subscriber if possible. If already\nsubscribed, or the attempt to subscribe fails due to policy\nviolations or errors, the Subscriber's `onError`\nmethod is invoked with an [IllegalStateException](/reference/java/lang/IllegalStateException).\nOtherwise, the Subscriber's `onSubscribe` method is\ninvoked with a new [Subscription](/reference/java/util/concurrent/Flow.Subscription). Subscribers may\nenable receiving items by invoking the `request`\nmethod of this Subscription, and may unsubscribe by\ninvoking its `cancel` method.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|--------------|-------------------------------------|\n| `subscriber` | `Subscriber`: the subscriber \u003cbr /\u003e |\n\n| Throws ||\n|-------------------------------------------------------------------|-----------------------|\n| [NullPointerException](/reference/java/lang/NullPointerException) | if subscriber is null |"]]