Just a second...

Publishing using stateful topics

Stateful topics are topics that store a current value in the Diffusion™ server. You can publish using stateful topics in a simple way or as part of a more complex transactional update.

This section covers working with topics that have associated topic data that extends the PublishingTopicData interface.

Simple updates to a stateful topic

Use the updateAndPublish or updateAndPublishFromDelta method on the topic data of a stateful topic to update the topic state. Updating the topic data of a stateful topic publishes a delta to all subscribed client that includes the changes to the topic data.

topic.getData().updateAndPublish(update);
// OR
topic.getData().updateAndPublishFromDelta(deltaUpdate);

Transactional updates to a stateful topic

Stateful topics can be updated transactionally by bracketing the updates with the startUpdate and endUpdate methods of the associated topic data.

Combining updates to the topic data as part of a single transaction can be useful when the stateful topic is a record topic that has multiple records and fields that can be updated from separate sources. These fields can be updated separately within the transaction, but all updates in the topic state are published to the subscribing clients at the same time.

// Start the transaction
data.startUpdate();
try {
     // Make multiple updates as part of a single transaction
     data.update(firstUpdate);
     data.update(secondUpdate);
     data.update(thirdUpdate);
     data.update(fourthUpdate);
     data.update(fifthUpdate);
     
     // Publish the updates that have been made in this transaction
     if (data.hasChanges()){
         data.publishMessage(data.generateDeltaMessage());
     }
}
finally {
     // Complete the transaction
     data.endUpdate()
}