Class CachedPublisher
Provides a mechanism for publishing messages and events; maintains a cache so that new subscribers can be serviced with existing messages automatically.
Messages can be published using publishMessage(com.caplin.datasource.messaging.Message)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the cache held by this publisher.com.caplin.datasource.messaging.MessageFactory
Returns the message factory that can be used to create messages, error and status events.void
publishErrorEvent
(com.caplin.datasource.SubjectErrorEvent subjectErrorEvent) Publishes a SubjectErrorEvent to all peers subscribed to the subject of the event.void
publishMessage
(com.caplin.datasource.messaging.Message message) Publishes a message to all peers that are subscribed to the subject of the message.void
publishStatusEvent
(com.caplin.datasource.SubjectStatusEvent subjectStatusEvent) Publishes a SubjectStatusEvent to all peers subscribed to the subject of the event.void
sendNotFound
(String subject) Sends a NotFound and removes any subscription from the cache.void
sendNotStale
(String subject) Sets the status of a subject to NotStale.void
sendNotStale
(String subject, String message) Sets the status of a subject to NotStale.void
Sets the status of a subject to Stale.void
Sets the status of a subject to Stale.void
sendUnavailable
(String subject) Sends a Unavailable and removes any subscription from the cache.
-
Method Details
-
publishMessage
public void publishMessage(com.caplin.datasource.messaging.Message message) Publishes a message to all peers that are subscribed to the subject of the message.The cache will be updated with the new fields from this message, but will also retain any fields that are present in the previously sent message that are not present in this message.
- Parameters:
message
- The message to publish.
-
sendNotFound
Sends a NotFound and removes any subscription from the cache.- Parameters:
subject
- The subject to send the NotFound for.
-
sendStale
Sets the status of a subject to Stale.
If the subject is not currently marked as Stale, a Stale message will be sent. If the subject is already marked as Stale when this method is called then no message is sent.
- Parameters:
subject
- The subject to set the status to Stale for.- See Also:
-
sendStale
Sets the status of a subject to Stale.
If the subject is not currently marked as Stale, a Stale message will be sent. If the subject is already marked as Stale when this method is called then no message is sent.
- Parameters:
subject
- The subject to set the status to Stale for.message
- The message to add to the status.- See Also:
-
sendNotStale
Sets the status of a subject to NotStale.
If the subject is not currently marked as NotStale, a NotStale message will be sent. If the subject is already marked as NotStale when this method is called then no message is sent.
- Parameters:
subject
- The subject to set the status to NotStale for.- See Also:
-
sendNotStale
Sets the status of a subject to NotStale.
If the subject is not currently marked as NotStale, a NotStale message will be sent. If the subject is already marked as NotStale when this method is called then no message is sent.
- Parameters:
subject
- The subject to set the status to NotStale for.message
- The message to add to the status.- See Also:
-
publishErrorEvent
public void publishErrorEvent(com.caplin.datasource.SubjectErrorEvent subjectErrorEvent) Publishes a SubjectErrorEvent to all peers subscribed to the subject of the event.- Parameters:
subjectErrorEvent
- The error event to publish.- See Also:
-
SubjectErrorEvent
-
publishStatusEvent
public void publishStatusEvent(com.caplin.datasource.SubjectStatusEvent subjectStatusEvent) Publishes a SubjectStatusEvent to all peers subscribed to the subject of the event.- Parameters:
subjectStatusEvent
- The status event to publish.- See Also:
-
SubjectStatusEvent
-
getMessageFactory
public com.caplin.datasource.messaging.MessageFactory getMessageFactory()Returns the message factory that can be used to create messages, error and status events.- Returns:
- The MessageFactory for this DataSource.
-
clearCache
public void clearCache()Clears the cache held by this publisher. It's important to clear the cache whenever there is a status event received by the DataSource.
-