use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class CollectionNode method childNodeDeleted.
/**
* Notification that a child node was deleted from this node. Trigger notifications
* to node subscribers whose subscription type is {@link NodeSubscription.Type#nodes} and
* have the proper depth.
*
* @param child the deleted node that was removed from this node.
*/
void childNodeDeleted(Node child) {
// Build packet to broadcast to subscribers
Message message = new Message();
Element event = message.addChildElement("event", "http://jabber.org/protocol/pubsub#event");
event.addElement("delete").addAttribute("node", child.getNodeID());
// Broadcast event notification to subscribers
broadcastCollectionNodeEvent(child, message);
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class LeafNode method purge.
/**
* Purges items that were published to the node. Only owners can request this operation.
* This operation is only available for nodes configured to store items in the database. All
* published items will be deleted with the exception of the last published item.
*/
public void purge() {
PubSubPersistenceManager.purgeNode(this);
// Broadcast purge notification to subscribers
// Build packet to broadcast to subscribers
Message message = new Message();
Element event = message.addChildElement("event", "http://jabber.org/protocol/pubsub#event");
Element items = event.addElement("purge");
items.addAttribute("node", nodeID);
// Send notification that the node configuration has changed
broadcastNodeEvent(message, false);
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class LeafNode method publishItems.
/**
* Publishes the list of items to the node. Event notifications will be sent to subscribers
* for the new published event. The published event may or may not include an item. When the
* node is not persistent and does not require payloads then an item is not going to be created
* nore included in the event notification.<p>
*
* When an affiliate has many subscriptions to the node, the affiliate will get a
* notification for each set of items that affected the same list of subscriptions.<p>
*
* When an item is included in the published event then a new {@link PublishedItem} is
* going to be created and added to the list of published item. Each published item will
* have a unique ID in the node scope. The new published item will be added to the end
* of the published list to keep the cronological order. When the max number of published
* items is exceeded then the oldest published items will be removed.<p>
*
* For performance reasons the newly added published items and the deleted items (if any)
* are saved to the database using a background thread. Sending event notifications to
* node subscribers may also use another thread to ensure good performance.<p>
*
* @param publisher the full JID of the user that sent the new published event.
* @param itemElements list of dom4j elements that contain info about the published items.
*/
public void publishItems(JID publisher, List<Element> itemElements) {
List<PublishedItem> newPublishedItems = new ArrayList<>();
if (isItemRequired()) {
String itemID;
Element payload;
PublishedItem newItem;
for (Element item : itemElements) {
itemID = item.attributeValue("id");
List entries = item.elements();
payload = entries.isEmpty() ? null : (Element) entries.get(0);
// Make sure that the published item has a unique ID if NOT assigned by publisher
if (itemID == null) {
itemID = genIdSeed + sequenceCounter.getAndIncrement();
}
// Create a new published item
newItem = new PublishedItem(this, publisher, itemID, new Date(CacheFactory.getClusterTime()));
newItem.setPayload(payload);
// Add the new item to the list of published items
newPublishedItems.add(newItem);
setLastPublishedItem(newItem);
// queue is going to be processed by another thread
if (isPersistPublishedItems()) {
PubSubPersistenceManager.savePublishedItem(newItem);
}
}
}
// Build event notification packet to broadcast to subscribers
Message message = new Message();
Element event = message.addChildElement("event", "http://jabber.org/protocol/pubsub#event");
// Broadcast event notification to subscribers and parent node subscribers
Set<NodeAffiliate> affiliatesToNotify = new HashSet<>(affiliates);
// Get affiliates that are subscribed to a parent in the hierarchy of parent nodes
for (CollectionNode parentNode : getParents()) {
for (NodeSubscription subscription : parentNode.getSubscriptions()) {
affiliatesToNotify.add(subscription.getAffiliate());
}
}
// TODO Use another thread for this (if # of subscribers is > X)????
for (NodeAffiliate affiliate : affiliatesToNotify) {
affiliate.sendPublishedNotifications(message, event, this, newPublishedItems);
}
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class Node method nodeConfigurationChanged.
/**
* The node configuration has changed. If this is the first time the node is configured
* after it was created (i.e. is not yet persistent) then do nothing. Otherwise, send
* a notification to the node subscribers informing that the configuration has changed.
*/
private void nodeConfigurationChanged() {
if (!isNotifiedOfConfigChanges() || !savedToDB) {
// of config changes is disabled
return;
}
// Build packet to broadcast to subscribers
Message message = new Message();
Element event = message.addChildElement("event", "http://jabber.org/protocol/pubsub#event");
Element config = event.addElement("configuration");
config.addAttribute("node", nodeID);
if (deliverPayloads) {
config.add(getConfigurationChangeForm().getElement());
}
// Send notification that the node configuration has changed
broadcastNodeEvent(message, false);
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class StreamManager method onClose.
public void onClose(PacketRouter router, JID serverAddress) {
// Re-deliver unacknowledged stanzas from broken stream (XEP-0198)
synchronized (this) {
if (isEnabled()) {
// disable stream management.
namespace = null;
for (StreamManager.UnackedPacket unacked : unacknowledgedServerStanzas) {
if (unacked.packet instanceof Message) {
Message m = (Message) unacked.packet;
if (m.getExtension("delay", "urn:xmpp:delay") == null) {
Element delayInformation = m.addChildElement("delay", "urn:xmpp:delay");
delayInformation.addAttribute("stamp", XMPPDateTimeFormat.format(unacked.timestamp));
delayInformation.addAttribute("from", serverAddress.toBareJID());
}
router.route(unacked.packet);
}
}
}
}
}
Aggregations