Interface Publisher<V>
- Type Parameters:
V- the value type
- All Superinterfaces:
AutoCloseable
NamedTopic.
The factory method NamedTopic.createPublisher(Publisher.Option[]) or
Session.createPublisher(String) allows one to specify one or more
Publisher.Options to configure the Publisher.
Since the publish(Object) method is asynchronous, there is a flush() that allows one to
block until all outstanding sent values for the Publisher have 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.
Publishers publish 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 aNamedTopic are published to a channel have a unique Position within that channel.
A Position is an opaque representation of the underlying position as theoretically the implementation of
the Position could 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. A Position is serializable so they can be stored and recovered to later reset a subscriber
to a desired position. Positions are Comparable so 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 ClassesModifier and TypeInterfaceDescriptionstatic classThe FailOnFull option indicates that theCompletableFuturereturned from thepublish(V)operation should complete exceptionally upon identifying that the topic is or has become full.static enumThis option controls how aPublisherhandles a failure of an individualpublish(V)call.static interfaceA marker interface to indicate that a class is a validPublisher.Optionfor aPublisher.static interfaceOrderable represents a value published byPublisherthat has a natural ordering.static classThe OrderBy option specifies the ordering of async operations with respect to one another.static classPublisher.OrderByoption ensures ordering ofsent valuesacross all threads which share the sameorderId.static classPublisher.OrderByoption enforces no specific ordering betweensent valuesallowing for the greatest level of parallelism.static classPublisher.OrderByoption which computes the unit-of-order such that each message is sent to the next channel in a round-robin order.static classPublisher.OrderByoption which ensures that a sequence ofsent valuesissued by a single thread will complete in order.static classPublisher.OrderByoption which computes the unit-of-order based on applyingconstructor'sorderIdFunction parameteronsent value.static interfaceThe status for a successfully published element. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe system property to use to configure a default publisher channel count. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close thisPublisher.flush()Obtain aCompletableFuturethat will be complete when all of the currently outstanding publish operations complete.intReturns the number of channels in the underlyingNamedTopicthat can be published to.Return theFlowControlobject governing this publisher.Returns the underlyingNamedTopicthat thisPublisherpublishes to.booleanisActive()Specifies whether or not thePublisheris active.voidAdd an action to be executed when thisPublisheris closed.Asynchronously publish the specified value to the topic.default CompletableFuture<Void> Deprecated.
-
Field Details
-
PROP_CHANNEL_COUNT
The system property to use to configure a default publisher channel count.- See Also:
-
-
Method Details
-
send
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
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
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
-
publish(Object)which returns metadata about the published value