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
public abstract class AbstractPubSubBroker<T extends SerializableMessage> extends Object
Encapsulates message sending and receiving through thePubSubService.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 theAbstractPubSubBrokermessage class), and thereceivedMessage(T)callback.The public API is
sendMessage(T), and thereceivedMessage(T)callback.- Since:
- 9.3
-
-
Field Summary
Fields Modifier and Type Field Description protected static byteDISCRIMINATOR_SEPprotected byte[]discriminatorBytesprotected Stringtopic
-
Constructor Summary
Constructors Constructor Description AbstractPubSubBroker()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this broker and releases resources.abstract Tdeserialize(InputStream in)Deserializes anInputStreaminto a message, ornull.voidinitialize(String topic, String discriminator)Initializes the broker.abstract voidreceivedMessage(T message)Callback implementing the delivery of a message from another node.protected intscanDiscriminator(byte[] message)Scans for the discriminator and returns the payload start offset.voidsendMessage(T message)Sends a message to other nodes.protected voidsubscriber(String topic, byte[] bytes)PubSubService subscriber, called from a separate thread.
-
-
-
Field Detail
-
topic
protected String topic
-
discriminatorBytes
protected byte[] discriminatorBytes
-
DISCRIMINATOR_SEP
protected static final byte DISCRIMINATOR_SEP
- See Also:
- Constant Field Values
-
-
Method Detail
-
deserialize
public abstract T deserialize(InputStream in) throws IOException
Deserializes anInputStreaminto a message, ornull.- Throws:
IOException
-
initialize
public void initialize(String topic, String discriminator)
Initializes the broker.- Parameters:
topic- the topicdiscriminator- 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
-
-