public abstract class AbstractPubSubBroker<T extends SerializableMessage> extends Object
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 T message class), and the receivedMessage(T) callback.
The public API is sendMessage(T), and the receivedMessage(T) callback.
| Modifier and Type | Field and Description |
|---|---|
protected static byte |
DISCRIMINATOR_SEP |
protected byte[] |
discriminatorBytes |
protected String |
topic |
| Constructor and Description |
|---|
AbstractPubSubBroker() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this broker and releases resources.
|
abstract T |
deserialize(InputStream in)
Deserializes an
InputStream into a message, or null. |
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.
|
protected byte[] discriminatorBytes
protected static final byte DISCRIMINATOR_SEP
public AbstractPubSubBroker()
public abstract T deserialize(InputStream in) throws IOException
InputStream into a message, or null.IOExceptionpublic void initialize(String topic, String discriminator)
topic - the topicdiscriminator - the discriminatorpublic void close()
public void sendMessage(T message)
protected void subscriber(String topic, byte[] bytes)
public abstract void receivedMessage(T message)
message - the received messageprotected int scanDiscriminator(byte[] message)
Copyright © 2019 Nuxeo. All rights reserved.