Package org.nuxeo.runtime.pubsub
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
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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this broker and releases resources.abstract T
Deserializes anInputStream
into a message, ornull
.void
initialize
(String topic, String discriminator) Initializes the broker.abstract void
receivedMessage
(T message) Callback implementing the delivery of a message from another node.protected int
scanDiscriminator
(byte[] message) Scans for the discriminator and returns the payload start offset.void
sendMessage
(T message) Sends a message to other nodes.protected void
subscriber
(String topic, byte[] bytes) PubSubService subscriber, called from a separate thread.
-
Field Details
-
topic
-
discriminatorBytes
protected byte[] discriminatorBytes -
DISCRIMINATOR_SEP
protected static final byte DISCRIMINATOR_SEP- See Also:
-
-
Constructor Details
-
AbstractPubSubBroker
public AbstractPubSubBroker()
-
-
Method Details
-
deserialize
Deserializes anInputStream
into a message, ornull
.- Throws:
IOException
-
initialize
Initializes the broker.- Parameters:
topic
- the topicdiscriminator
- the discriminator
-
close
public void close()Closes this broker and releases resources. -
sendMessage
Sends a message to other nodes. -
subscriber
PubSubService subscriber, called from a separate thread. -
receivedMessage
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
-