Flow.Publisher
Stay organized with collections
Save and categorize content based on your preferences.
Known Indirect Subclasses
Flow.Processor<T, R> |
A component that acts as both a Subscriber and Publisher. |
|
A producer of items (and related control messages) received by
Subscribers. Each current Flow.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.
Public Methods
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 Flow.Subscription
. Subscribers may
enable receiving items by invoking the request
method of this Subscription, and may unsubscribe by
invoking its cancel
method.
Parameters
subscriber |
the subscriber |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eFlow.Publisher\u003c/code\u003e represents a producer of items received by \u003ccode\u003eFlow.Subscriber\u003c/code\u003e instances, delivering items in the same order to each subscriber.\u003c/p\u003e\n"],["\u003cp\u003eIf an error prevents item delivery, subscribers receive an \u003ccode\u003eonError\u003c/code\u003e signal, followed by no further messages; otherwise, they receive an \u003ccode\u003eonComplete\u003c/code\u003e signal when no more items are expected.\u003c/p\u003e\n"],["\u003cp\u003ePublishers can differ in how they handle drops (e.g., resource limitations) and whether new subscribers receive previously produced items.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003esubscribe\u003c/code\u003e method allows adding a subscriber, which can then request items and unsubscribe using the provided \u003ccode\u003eFlow.Subscription\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eSubscribing with a \u003ccode\u003enull\u003c/code\u003e subscriber or facing policy violations during subscription results in an \u003ccode\u003eIllegalStateException\u003c/code\u003e or a \u003ccode\u003eNullPointerException\u003c/code\u003e, respectively, sent to the subscriber's \u003ccode\u003eonError\u003c/code\u003e method.\u003c/p\u003e\n"]]],[],null,["# Flow.Publisher\n\npublic static interface **Flow.Publisher** \n\n|---|---|---|\n| Known Indirect Subclasses [Flow.Processor](../../../../reference/java/util/concurrent/Flow.Processor.html)\\\u003cT, R\\\u003e |------------------------------------------------------------------------------------------|-----------------------------------------------------------| | [Flow.Processor](../../../../reference/java/util/concurrent/Flow.Processor.html)\\\u003cT, R\\\u003e | A component that acts as both a Subscriber and Publisher. | |||\n\nA producer of items (and related control messages) received by\nSubscribers. Each current [Flow.Subscriber](../../../../reference/java/util/concurrent/Flow.Subscriber.html) 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*](/j2objc/javadoc/jre/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\n### Public Method Summary\n\n|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [subscribe](../../../../reference/java/util/concurrent/Flow.Publisher.html#subscribe(java.util.concurrent.Flow.Subscriber\u003c?%20super%20T\u003e))([Subscriber](../../../../reference/java/util/concurrent/Flow.Subscriber.html)\\\u003c? super T\\\u003e subscriber) Adds the given Subscriber if possible. |\n\nPublic Methods\n--------------\n\n#### public abstract void\n**subscribe**\n([Subscriber](../../../../reference/java/util/concurrent/Flow.Subscriber.html)\\\u003c? super T\\\u003e subscriber)\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.html).\nOtherwise, the Subscriber's `onSubscribe` method is\ninvoked with a new [Flow.Subscription](../../../../reference/java/util/concurrent/Flow.Subscription.html). Subscribers may\nenable receiving items by invoking the `request`\nmethod of this Subscription, and may unsubscribe by\ninvoking its `cancel` method. \n\n##### Parameters\n\n| subscriber | the subscriber |\n|------------|----------------|\n\n##### Throws\n\n| [NullPointerException](../../../../reference/java/lang/NullPointerException.html) | if subscriber is null |\n|-----------------------------------------------------------------------------------|-----------------------|"]]