Interface Publisher<V>
-
- Type Parameters:
V- the value type
- All Superinterfaces:
AutoCloseable
public interface Publisher<V> extends AutoCloseable
Publisher provides a means to publish values to theNamedTopic.The factory method
NamedTopic.createPublisher(Publisher.Option[])orSession.createPublisher(String)allows one to specify one or morePublisher.Options to configure thePublisher.Since the
publish(Object)method is asynchronous, there is aflush()that allows one to block until all outstandingsent valuesfor thePublisherhave completed.Channels
Topics use the concept of channels to improve scalability. This is similar to how Coherence uses partition for caches but to avoid confusion the name channel was chosen. The default is the next prime above the square root of the partition count for the underlying cache service, which for the default partition count of 257 is 17 channels.Publisherspublish messages to a channel based on their ordering configuration. Subscribers then subscribe from channels by assigning channel ownership to subscribers. An anonymous subscriber has ownership of all channels. A subscriber that is part of a subscriber group has ownership of a sub-set of the available channels.Channel count is configurable, but ideally should not be set too high nor too low. For example setting the channel count to 1, would mean that all publishers contend to publish to a single channel, and that only one subscriber in a subscriber group will be able to receive messages. Setting the channel count too high (above say the number of publishers) may mean that some channels never receive any messages and are wasted. Finding the appropriate value is admittedly non-trivial, however when faced with maxing out throughput from a publishers perspective this is a configuration that can be tweaked.
Positions
Elements in aNamedTopicare published to a channel have a uniquePositionwithin that channel. APositionis an opaque representation of the underlying position as theoretically the implementation of thePositioncould change for different types of topic. Positions are used in various places in the API, for example, positions can be committed, and they can be used to move the subscriber to backwards or forwards within channels. APositionis serializable so they can be stored and recovered to later reset a subscriber to a desired position. Positions areComparableso positions for elements can be used to determine whether how two elements related to each other within a channel.- Since:
- Coherence 14.1.1
- Author:
- jf/jk/mf 2015.06.03
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classPublisher.FailOnFullThe FailOnFull option indicates that theCompletableFuturereturned from thepublish(V)operation should complete exceptionally upon identifying that the topic is or has become full.static classPublisher.OnFailureThis option controls how aPublisherhandles a failure of an individualpublish(V)call.static interfacePublisher.Option<V>A marker interface to indicate that a class is a validPublisher.Optionfor aPublisher.static interfacePublisher.OrderableOrderable represents a value published byPublisherthat has a natural ordering.static classPublisher.OrderBy<V>The OrderBy option specifies the ordering of async operations with respect to one another.static classPublisher.OrderById<V>Publisher.OrderByoption ensures ordering ofsent valuesacross all threads which share the sameorderId.static classPublisher.OrderByNone<V>Publisher.OrderByoption enforces no specific ordering betweensent valuesallowing for the greatest level of parallelism.static classPublisher.OrderByRoundRobin<V>Publisher.OrderByoption which computes the unit-of-order such that each message is sent to the next channel in a round-robin order.static classPublisher.OrderByThread<V>Publisher.OrderByoption which ensures that a sequence ofsent valuesissued by a single thread will complete in order.static classPublisher.OrderByValue<V>Publisher.OrderByoption which computes the unit-of-order based on applyingconstructor'sorderIdFunction parameteronsent value.static interfacePublisher.StatusThe status for a successfully published element.
-
Field Summary
Fields Modifier and Type Field Description static StringPROP_CHANNEL_COUNTThe system property to use to configure a default publisher channel count.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description voidclose()Close thisPublisher.CompletableFuture<Void>flush()Obtain aCompletableFuturethat will be complete when all of the currently outstanding publish operations complete.intgetChannelCount()Returns the number of channels in the underlyingNamedTopicthat can be published to.FlowControlgetFlowControl()Return theFlowControlobject governing this publisher.NamedTopic<V>getNamedTopic()Returns the underlyingNamedTopicthat thisPublisherpublishes to.booleanisActive()Specifies whether or not thePublisheris active.voidonClose(Runnable action)Add an action to be executed when thisPublisheris closed.CompletableFuture<Publisher.Status>publish(V value)Asynchronously publish the specified value to the topic.default CompletableFuture<Void>send(V value)Deprecated.Usepublish(Object)which returns metadata about the published value
-
-
-
Field Detail
-
PROP_CHANNEL_COUNT
static final String PROP_CHANNEL_COUNT
The system property to use to configure a default publisher channel count.- See Also:
- Constant Field Values
-
-
Method Detail
-
send
@Deprecated default CompletableFuture<Void> send(V value)
Deprecated.Usepublish(Object)which returns metadata about the published valueAsynchronously publish the specified value to the topic.Cancellationof the returned future is best effort and is not guaranteed to stop the corresponding publication of the value, for example example the request may already be on the wire and being processed on a storage member.- Parameters:
value- the value to add to the topic- Returns:
- a
CompletableFuturewhich can be used to identify when the value has been delivered to the topic - Throws:
IllegalStateException- if this Publisher is closed or the parent topic has been released or destroyed
-
publish
CompletableFuture<Publisher.Status> publish(V value)
Asynchronously publish the specified value to the topic.Cancellationof the returned future is best effort and is not guaranteed to stop the corresponding publication of the value, for example example the request may already be on the wire and being processed on a storage member.Published messages will be recieved by subscribers in order determined by the
Publisher.OrderByoption used to create thisPublisher. Message ordering can also be controlled by publishing values that implement thePublisher.Orderableinterface, in which case the order identifier provided by thePublisher.Orderablevalue will override any ordering configured for thePublisher.- Parameters:
value- the value to add to the topic- Returns:
- a
CompletableFuturecontaining thePublisher.Status, which can be used to identify when the value has been delivered to the topic and the position it was added to the topic - Throws:
IllegalStateException- if this Publisher is closed or the parent topic has been released or destroyed
-
getFlowControl
FlowControl getFlowControl()
Return theFlowControlobject governing this publisher.- Returns:
- the FlowControl object.
-
flush
CompletableFuture<Void> flush()
Obtain aCompletableFuturethat will be complete when all of the currently outstanding publish operations complete.The returned
CompletableFuturewill always complete normally, even if the outstanding operations complete exceptionally.- Returns:
- a
CompletableFuturethat will be completed when all of the currently outstanding publish operations are complete
-
close
void close()
Close thisPublisher.This is a blocking method and will wait until all outstanding
CompletableFutures returned from previous calls topublish(Object)have completed before returning.- Specified by:
closein interfaceAutoCloseable
-
onClose
void onClose(Runnable action)
Add an action to be executed when thisPublisheris closed.- Parameters:
action- the action to execute
-
getChannelCount
int getChannelCount()
Returns the number of channels in the underlyingNamedTopicthat can be published to.- Returns:
- the number of channels in the underlying
NamedTopicthat can be published to
-
getNamedTopic
NamedTopic<V> getNamedTopic()
Returns the underlyingNamedTopicthat thisPublisherpublishes to.- Returns:
- the underlying
NamedTopicthat thisPublisherpublishes to
-
isActive
boolean isActive()
Specifies whether or not thePublisheris active.- Returns:
- true if the NamedCache is active; false otherwise
-
-