protected void dispatch( @Nonnull JID entity, @Nonnull EntityCapabilities updatedEntityCapabilities, @Nullable EntityCapabilities previousEntityCapabilities ) {
        Log.trace( "Dispatching entity capabilities changed listeners for '{}'", entity );

        // Calculate diffs
        final Set<String> featuresInUpdate = updatedEntityCapabilities.getFeatures();
        final Set<String> featuresExisting = previousEntityCapabilities == null ? Collections.emptySet() : previousEntityCapabilities.getFeatures();
        final Set<String> identitiesInUpdate = updatedEntityCapabilities.getIdentities();
        final Set<String> identitiesExisting = previousEntityCapabilities == null ? Collections.emptySet() :previousEntityCapabilities.getIdentities();

        final Set<String> featuresAdded = new HashSet<>(featuresInUpdate);
        featuresAdded.removeAll( featuresExisting );

        final Set<String> featuresRemoved = new HashSet<>(featuresExisting);
        featuresRemoved.removeAll( featuresInUpdate );

        final Set<String> identitiesAdded = new HashSet<>(identitiesInUpdate);
        identitiesAdded.removeAll( identitiesExisting );

        final Set<String> identitiesRemoved = new HashSet<>(identitiesExisting);
        identitiesRemoved.removeAll( identitiesInUpdate );

        // Invoke event listeners.
        for ( final EntityCapabilitiesListener listener : allUserCapabilitiesListeners ) {
            try {
                listener.entityCapabilitiesChanged( entity, updatedEntityCapabilities, featuresAdded, featuresRemoved, identitiesAdded, identitiesRemoved );
            } catch ( Exception e ) {
                Log.warn( "An exception occurred while dispatching entity capabilities changed event for entity '{}' to listener '{}'.", entity, listener, e );
            }
        }
        final Set<EntityCapabilitiesListener> userSpecificListeners = userSpecificCapabilitiesListener.get(entity);
        for (final EntityCapabilitiesListener listener : userSpecificListeners) {
            try {
                listener.entityCapabilitiesChanged(entity, updatedEntityCapabilities, featuresAdded, featuresRemoved, identitiesAdded, identitiesRemoved);
            } catch (Exception e) {
                Log.warn("An exception occurred while dispatching entity capabilities changed event for entity '{}' to listener '{}'.", entity, listener, e);
            }
        }
    }
Invokes the entityCapabilitiesChanged method of all currently registered event listeners.

It is assumed that this method is used to notify listeners of a change in capabilities for a particular entity.

@param entity The entity for which an event is to be dispatched
@param updatedEntityCapabilities The most up-to-date capabilities.
@param previousEntityCapabilities The capabilities, if any, prior to the update.
xmppserver/src/main/java/org/jivesoftware/openfire/entitycaps/EntityCapabilitiesManager.java