@Nonnull
    public Set<Node> findSubscribedNodes(@Nonnull final JID entity, @Nonnull final String nodeId)
    {
        final Set<Node> result = new HashSet<>();

        // Find all nodes that the entity has a direct subscription to. Most of these will be root nodes (representing a service)
        // for which subscriptions apply to all child nodes. The resulting nodes could also be intermediate collection nodes
        // (that might similarly have subscriptions bubbling up), or specific leaf nodes.
        final Set<Node.UniqueIdentifier> directlySubscribedNodes = XMPPServer.getInstance().getPubSubModule().getPersistenceProvider().findDirectlySubscribedNodes(entity);

        // For all of the services and collection nodes, see if any of their children match the nodeIdFilter. The implementation here
        // checks if the corresponding service has a node with a matching nodeID at all. If it does, it explicitly checks if the
        // entity has a subscription to that node (which recursively looks at its parents).
        final Set<PubSubService.UniqueIdentifier> relatedServiceUIDs = directlySubscribedNodes.stream().map(Node.UniqueIdentifier::getServiceIdentifier).collect(Collectors.toSet());
        for( final PubSubService.UniqueIdentifier relatedServiceUID : relatedServiceUIDs ) {
            // Here, we're only interested in PEP services, not generic Pubsub services.
            final PEPService service = getPEPService( relatedServiceUID, false );
            if ( service != null ) {
                final Node node = service.getNode( nodeId );
                if (node != null) {
                    // TODO should we consider other nodes than LeafNode?
                    if ( node instanceof LeafNode && ((LeafNode) node).getAffiliatesToNotify().stream().anyMatch(
                        nodeAffiliate -> nodeAffiliate.getJID().equals(entity) || nodeAffiliate.getJID().equals(entity.asBareJID())) )
                    {
                        result.add( node );
                    }
                }
            }
        }

        Log.trace( "Entity '{}' is subscribed to {} nodes that have NodeID {}", entity, result.size(), nodeId);
        return result;
    }
Returns all PEP nodes with a specific ID that the provided entity is a subscriber to. This would typically
return a similar node for many different services (eg: the 'user-tune' node of the PEP services of all of
entity's contacts.

@param entity The entity address.
@param nodeId The NodeID of the nodes to return
@return A collection of nodes (possibly empty).
xmppserver/src/main/java/org/jivesoftware/openfire/pep/PEPServiceManager.java