Package org.jivesoftware.openfire.pubsub
Class CachingPubsubPersistenceProvider
java.lang.Object
org.jivesoftware.openfire.pubsub.CachingPubsubPersistenceProvider
- All Implemented Interfaces:
PubSubPersistenceProvider
A persistence provider for Pub/Sub functionality that adds caching behavior. Instead of 'writing through' to the
persistence layer, the caching implementation will create batches of operations (optimizing away redundant actions).
Additionally, recently accessed published data items are cached. This improves performance when processing many
pub/sub operations (node modifications, item publications, etc).
This provider itself does not persist data. Instead, it uses a different persistence provider as a delegate to
perform these actions.
- Author:
- Guus der Kinderen, guus@goodbytes.nl
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SystemProperty<Class>The class definition used to instantiate the delegate, used by this instance to interact with persistent data storage.static final SystemProperty<Duration>Flush timer delay is configurable, but not less than 20 seconds (default: 2 mins)static final SystemProperty<Integer>Maximum number of published items allowed in the write cache before being flushed to the database. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbulkPublishedItems(List<PublishedItem> addList, List<PublishedItem> delList) Writes large changesets, using batches and transactions when available.voidcreateAffiliation(Node node, NodeAffiliate affiliate) Creates a new affiliation of the user in the node.voidcreateDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, DefaultNodeConfiguration config) Creates a new default node configuration for the specified service.voidcreateNode(Node node) Schedules the node to be created in the database.voidcreateSubscription(Node node, NodeSubscription subscription) Adds the new subscription of the user to the node to the database.findDirectlySubscribedNodes(org.xmpp.packet.JID address) Returns identifiers for all pubsub nodes to which the provided address is a direct subscriber.voidflushPendingChanges(boolean sendToCluster) Persists any changes that have been applied to the caches by invoking the relevant methods of the delegate.voidflushPendingChanges(Node.UniqueIdentifier nodeUniqueId) voidflushPendingChanges(Node.UniqueIdentifier nodeUniqueId, boolean sendToCluster) getLastPublishedItem(LeafNode node) Fetches the last published item (by creation date) for the specified node.getPublishedItem(LeafNode node, PublishedItem.UniqueIdentifier itemIdentifier) Fetches a published item (by ID) for a node.getPublishedItems(LeafNode node) Fetches all the results for the specified node, limited byLeafNode.getMaxPublishedItems().getPublishedItems(LeafNode node, int maxRows) Fetches all the results for the specified node, limited byLeafNode.getMaxPublishedItems().voidStarts the provider.loadDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, boolean isLeafType) Loads from the database the default node configuration for the specified node type and pubsub service.voidloadNode(PubSubService service, Node.UniqueIdentifier nodeIdentifier) Loads all nodes from the database and adds them to the PubSub service.voidloadNodes(PubSubService service) Loads all nodes from the database and adds them to the PubSub service.loadPEPServiceFromDB(org.xmpp.packet.JID jid) Loads a PEP service from the database, if it exists.voidloadSubscription(Node node, String subId) Loads a subscription from the database, storing it in the provided node.voidDeletes all published items of a node.voidremoveAffiliation(Node node, NodeAffiliate affiliate) Removes the affiliation and subscription state of the user from the DB.voidremoveNode(Node node) Schedules the node to be removed in the database.voidRemoves the specified published item from the DB.voidremoveSubscription(NodeSubscription subscription) Removes the subscription of the user from the DB.voidCreates and stores the published item in the database.voidshutdown()Stops the provider.voidupdateAffiliation(Node node, NodeAffiliate affiliate) Updates an affiliation of the user in the node.voidupdateDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, DefaultNodeConfiguration config) Updates the default node configuration for the specified service.voidupdateNode(Node node) Schedules the node to be updated in the database.voidupdateSubscription(Node node, NodeSubscription subscription) Updates the subscription of the user to the node to the database.
-
Field Details
-
DELEGATE
The class definition used to instantiate the delegate, used by this instance to interact with persistent data storage. -
FLUSH_TIMER_DELAY
Flush timer delay is configurable, but not less than 20 seconds (default: 2 mins) -
MAX_ITEMS_FLUSH
Maximum number of published items allowed in the write cache before being flushed to the database.
-
-
Constructor Details
-
CachingPubsubPersistenceProvider
public CachingPubsubPersistenceProvider()
-
-
Method Details
-
initialize
public void initialize()Description copied from interface:PubSubPersistenceProviderStarts the provider. This method is invoked before the provider is used to interact with the backend datastore.- Specified by:
initializein interfacePubSubPersistenceProvider
-
shutdown
public void shutdown()Description copied from interface:PubSubPersistenceProviderStops the provider. This method is invoked when the system is to be shut down. The provider should not be used after this method is invoked.- Specified by:
shutdownin interfacePubSubPersistenceProvider
-
createNode
Description copied from interface:PubSubPersistenceProviderSchedules the node to be created in the database.- Specified by:
createNodein interfacePubSubPersistenceProvider- Parameters:
node- The newly created node.
-
updateNode
Description copied from interface:PubSubPersistenceProviderSchedules the node to be updated in the database.- Specified by:
updateNodein interfacePubSubPersistenceProvider- Parameters:
node- The updated node.
-
removeNode
Description copied from interface:PubSubPersistenceProviderSchedules the node to be removed in the database.- Specified by:
removeNodein interfacePubSubPersistenceProvider- Parameters:
node- The node that is being deleted.
-
loadNodes
Description copied from interface:PubSubPersistenceProviderLoads all nodes from the database and adds them to the PubSub service.- Specified by:
loadNodesin interfacePubSubPersistenceProvider- Parameters:
service- the pubsub service that is hosting the nodes.
-
loadNode
Description copied from interface:PubSubPersistenceProviderLoads all nodes from the database and adds them to the PubSub service.- Specified by:
loadNodein interfacePubSubPersistenceProvider- Parameters:
service- the pubsub service that is hosting the nodes.nodeIdentifier- the identifier of the node to load.
-
loadSubscription
Description copied from interface:PubSubPersistenceProviderLoads a subscription from the database, storing it in the provided node.- Specified by:
loadSubscriptionin interfacePubSubPersistenceProvider- Parameters:
node- The node for which a subscription is to be loaded from the database.subId- The identifier of the subscription that is to be loaded from the database.
-
findDirectlySubscribedNodes
@Nonnull public Set<Node.UniqueIdentifier> findDirectlySubscribedNodes(@Nonnull org.xmpp.packet.JID address) Description copied from interface:PubSubPersistenceProviderReturns identifiers for all pubsub nodes to which the provided address is a direct subscriber. Note that the results do not include nodes to which the provided address is a subscriber through inheritance! The result can include root nodes, (other) collection nodes as well as leaf nodes. When a node is subscribed to using a full JID, that node will be returned only if the address used as an argument in this method matches that full JID. If the node was subscribed to using a bare JID, it will be returned when the provided argument's bare JID representation matches the JID used for the subscription.- Specified by:
findDirectlySubscribedNodesin interfacePubSubPersistenceProvider- Parameters:
address- The address (bare of full JID) for which to return nodes.- Returns:
- A collection of node identifiers, possibly empty.
-
createAffiliation
Description copied from interface:PubSubPersistenceProviderCreates a new affiliation of the user in the node.- Specified by:
createAffiliationin interfacePubSubPersistenceProvider- Parameters:
node- The node where the affiliation of the user was updated.affiliate- The new affiliation of the user in the node.
-
updateAffiliation
Description copied from interface:PubSubPersistenceProviderUpdates an affiliation of the user in the node.- Specified by:
updateAffiliationin interfacePubSubPersistenceProvider- Parameters:
node- The node where the affiliation of the user was updated.affiliate- The new affiliation of the user in the node.
-
removeAffiliation
Description copied from interface:PubSubPersistenceProviderRemoves the affiliation and subscription state of the user from the DB.- Specified by:
removeAffiliationin interfacePubSubPersistenceProvider- Parameters:
node- The node where the affiliation of the user was updated.affiliate- The existing affiliation and subsription state of the user in the node.
-
createSubscription
Description copied from interface:PubSubPersistenceProviderAdds the new subscription of the user to the node to the database.- Specified by:
createSubscriptionin interfacePubSubPersistenceProvider- Parameters:
node- The node where the user has subscribed to.subscription- The new subscription of the user to the node.
-
updateSubscription
Description copied from interface:PubSubPersistenceProviderUpdates the subscription of the user to the node to the database.- Specified by:
updateSubscriptionin interfacePubSubPersistenceProvider- Parameters:
node- The node where the user has subscribed to.subscription- The new subscription of the user to the node.
-
removeSubscription
Description copied from interface:PubSubPersistenceProviderRemoves the subscription of the user from the DB.- Specified by:
removeSubscriptionin interfacePubSubPersistenceProvider- Parameters:
subscription- The existing subscription of the user to the node.
-
purgeNode
Description copied from interface:PubSubPersistenceProviderDeletes all published items of a node.- Specified by:
purgeNodein interfacePubSubPersistenceProvider- Parameters:
leafNode- the node for which to delete all published items.
-
savePublishedItem
Description copied from interface:PubSubPersistenceProviderCreates and stores the published item in the database. When an item with the same ID was previously saved, this item will be replaced by the new item.- Specified by:
savePublishedItemin interfacePubSubPersistenceProvider- Parameters:
item- The published item to save.
-
flushPendingChanges
-
flushPendingChanges
-
flushPendingChanges
public void flushPendingChanges(boolean sendToCluster) Persists any changes that have been applied to the caches by invoking the relevant methods of the delegate. A flush can be performed either local (typically used to periodically persist data) or cluster-wide (useful to ensure that a particular state is reached, cluster-wide).- Parameters:
sendToCluster- set to 'true' to trigger a flush on all cluster nodes. If false, a flush will occur only on the local node.
-
removePublishedItem
Description copied from interface:PubSubPersistenceProviderRemoves the specified published item from the DB.- Specified by:
removePublishedItemin interfacePubSubPersistenceProvider- Parameters:
item- The published item to delete.
-
loadPEPServiceFromDB
Description copied from interface:PubSubPersistenceProviderLoads a PEP service from the database, if it exists. Note that the returned service is not yet initialized!- Specified by:
loadPEPServiceFromDBin interfacePubSubPersistenceProvider- Parameters:
jid- the JID of the owner of the PEP service.- Returns:
- the loaded PEP service, or null if not found.
-
bulkPublishedItems
Description copied from interface:PubSubPersistenceProviderWrites large changesets, using batches and transactions when available. The 'delete' list takes precedence over the 'add' list: when an item exists on both lists, it is removed (and not re-added) from storage To prevent duplicates to exist, this method will attempt to remove all items to-be-added, before re-adding them.- Specified by:
bulkPublishedItemsin interfacePubSubPersistenceProvider- Parameters:
addList- A list of items to be added.delList- A list of items to be removed.
-
loadDefaultConfiguration
public DefaultNodeConfiguration loadDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, boolean isLeafType) Description copied from interface:PubSubPersistenceProviderLoads from the database the default node configuration for the specified node type and pubsub service.- Specified by:
loadDefaultConfigurationin interfacePubSubPersistenceProvider- Parameters:
serviceIdentifier- Identifier of the serviceisLeafType- true if loading default configuration for leaf nodes.- Returns:
- the loaded default node configuration for the specified node type and service or null if none was found.
-
createDefaultConfiguration
public void createDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, DefaultNodeConfiguration config) Description copied from interface:PubSubPersistenceProviderCreates a new default node configuration for the specified service.- Specified by:
createDefaultConfigurationin interfacePubSubPersistenceProvider- Parameters:
serviceIdentifier- Identifier of the serviceconfig- the default node configuration to create in the database.
-
updateDefaultConfiguration
public void updateDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, DefaultNodeConfiguration config) Description copied from interface:PubSubPersistenceProviderUpdates the default node configuration for the specified service.- Specified by:
updateDefaultConfigurationin interfacePubSubPersistenceProvider- Parameters:
serviceIdentifier- Identifier of the serviceconfig- the default node configuration to update in the database.
-
getPublishedItems
Description copied from interface:PubSubPersistenceProviderFetches all the results for the specified node, limited byLeafNode.getMaxPublishedItems(). Results are ordered by creation date.- Specified by:
getPublishedItemsin interfacePubSubPersistenceProvider- Parameters:
node- the leaf node to load its published items.
-
getPublishedItems
Description copied from interface:PubSubPersistenceProviderFetches all the results for the specified node, limited byLeafNode.getMaxPublishedItems(). Results are ordered by creation date.- Specified by:
getPublishedItemsin interfacePubSubPersistenceProvider- Parameters:
node- the leaf node to load its published items.
-
getLastPublishedItem
Description copied from interface:PubSubPersistenceProviderFetches the last published item (by creation date) for the specified node.- Specified by:
getLastPublishedItemin interfacePubSubPersistenceProvider- Parameters:
node- the leaf node to load its last published items.
-
getPublishedItem
Description copied from interface:PubSubPersistenceProviderFetches a published item (by ID) for a node.- Specified by:
getPublishedItemin interfacePubSubPersistenceProvider- Parameters:
node- The node for which to get a published item.itemIdentifier- The unique identifier of the item to fetch.- Returns:
- The item, or null if no item was found.
-