Class AbstractPubSubBroker<T extends SerializableMessage>

java.lang.Object
org.nuxeo.runtime.pubsub.AbstractPubSubBroker<T>
Direct Known Subclasses:
AbstractPubSubInvalidationsAccumulator, CacheServiceImpl.AbstractCachePubSubInvalidator, ClusterActionPubSub, ClusterActionServiceImpl.ClusterActionPubSub, ElasticSearchAdminImpl.ReindexingPubSub, MigrationServiceImpl.MigrationInvalidator, TemplateProcessorComponent.TemplateProcessorInvalidator, WOPIServiceImpl.WOPIDiscoveryInvalidator

public abstract class AbstractPubSubBroker<T extends SerializableMessage> extends Object
Encapsulates message sending and receiving through the PubSubService.

All nodes that use the same topic will receive the same messages. The discriminator is used to distinguish nodes between one another, and to avoid that a node receives the messages it send itself.

An actual implementation must implement the method deserialize(java.io.InputStream) (usually by delegating to a static method in the AbstractPubSubBroker message class), and the receivedMessage(T) callback.

The public API is sendMessage(T), and the receivedMessage(T) callback.

Since:
9.3
  • Field Details

    • topic

      protected String topic
    • discriminatorBytes

      protected byte[] discriminatorBytes
    • DISCRIMINATOR_SEP

      protected static final byte DISCRIMINATOR_SEP
      See Also:
  • Constructor Details

    • AbstractPubSubBroker

      public AbstractPubSubBroker()
  • Method Details

    • deserialize

      public abstract T deserialize(InputStream in) throws IOException
      Deserializes an InputStream into a message, or null.
      Throws:
      IOException
    • initialize

      public void initialize(String topic, String discriminator)
      Initializes the broker.
      Parameters:
      topic - the topic
      discriminator - the discriminator
    • close

      public void close()
      Closes this broker and releases resources.
    • sendMessage

      public void sendMessage(T message)
      Sends a message to other nodes.
    • subscriber

      protected void subscriber(String topic, byte[] bytes)
      PubSubService subscriber, called from a separate thread.
    • receivedMessage

      public abstract void receivedMessage(T message)
      Callback implementing the delivery of a message from another node.
      Parameters:
      message - the received message
    • scanDiscriminator

      protected int scanDiscriminator(byte[] message)
      Scans for the discriminator and returns the payload start offset.
      Returns:
      payload start offset, or -1 if the discriminator is local or if the message is invalid