Class CachedPublisher


  • public class CachedPublisher
    extends java.lang.Object

    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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearCache()
      Clears the cache held by this publisher.
      com.caplin.datasource.messaging.MessageFactory getMessageFactory()
      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​(java.lang.String subject)
      Sends a NotFound and removes any subscription from the cache.
      void sendNotStale​(java.lang.String subject)
      Sets the status of a subject to NotStale.
      void sendNotStale​(java.lang.String subject, java.lang.String message)
      Sets the status of a subject to NotStale.
      void sendStale​(java.lang.String subject)
      Sets the status of a subject to Stale.
      void sendStale​(java.lang.String subject, java.lang.String message)
      Sets the status of a subject to Stale.
      void sendUnavailable​(java.lang.String subject)
      Sends a Unavailable and removes any subscription from the cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • 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

        public void sendNotFound​(java.lang.String subject)
        Sends a NotFound and removes any subscription from the cache.
        Parameters:
        subject - The subject to send the NotFound for.
      • sendUnavailable

        public void sendUnavailable​(java.lang.String subject)
        Sends a Unavailable and removes any subscription from the cache.
        Parameters:
        subject - The subject to send the Unavailable for.
      • sendStale

        public void sendStale​(java.lang.String subject)

        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(String)
      • sendStale

        public void sendStale​(java.lang.String subject,
                              java.lang.String message)

        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:
        sendStale(String)
      • sendNotStale

        public void sendNotStale​(java.lang.String subject)

        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(String)
      • sendNotStale

        public void sendNotStale​(java.lang.String subject,
                                 java.lang.String message)

        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:
        sendNotStale(String)
      • 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.