public interface ActivePublisher extends Publisher
This implementation of Publisher
publishes updates that
are for subjects within its associated Namespace
, to all
peers that have subscribed to those subjects.
To obtain an ActivePublisher
, call the
DataSource.createActivePublisher(com.caplin.datasource.namespace.Namespace, DataProvider)
method of DataSource
.
ActivePublisher
passes all requests for subjects in the
Namespace
on to its associated
DataProvider
. However it only passes a discard request on
to the DataProvider
when all of the subscribed peers have
discarded the subject. For example, consider this sequence of events:
In this case the DataProvider
would receive two requests,
one at step 1 and another at step 2. However the
DataProvider
would only receive one discard, which would
be at step 4. The purpose of this logic is to simplify the job of the
DataProvider
. It still needs to send out a new image
whenever a new Peer
requests a subject. However, when it receives a single discard
for the subject, it can immediately stop sending out updates, since the discard indicates that
there are now no peers subscribed to that subject.
In detail, the ActivePublisher
's
DataProvider
receives a call to
DataProvider.onRequest(RequestEvent)
every time a new
peer requests a subject. The DataProvider
must respond by
calling Publisher.publishInitialMessage(Message)
to
ensure that each requesting (subscribing) peer receives an initial image. Each call to
Publisher.publishInitialMessage(Message)
sends the image
to all peers that have requested the subject since the previous call to
Publisher.publishInitialMessage(Message)
.
The DataProvider
receives a single call to
DataProvider.onDiscard(DiscardEvent)
when the last peer
discards the subject. This is the signal to the
DataProvider
that it can stop sending updates, and
unsubscribe from streaming data for the subject from the back end system. As explained above, the
DataProvider
does not receive a call to
DataProvider.onDiscard(DiscardEvent)
every time a peer
discards the subject, it just receives one call when the last peer discards the subject.
getMessageFactory, publishInitialMessage, publishMappingMessage, publishSubjectErrorEvent, publishSubjectStatusEvent, publishToSubscribedPeers
Please send bug reports and comments to Caplin support