public void removedExpiredPresences() {
        Map<String, Collection<DirectedPresence>> copy =
                new HashMap<>(localDirectedPresences);
        for (Map.Entry<String, Collection<DirectedPresence>> entry : copy.entrySet()) {
            for (DirectedPresence directedPresence : entry.getValue()) {
                if (!routingTable.hasClientRoute(directedPresence.getHandler()) &&
                        !routingTable.hasComponentRoute(directedPresence.getHandler())) {
                    Collection<DirectedPresence> presences = localDirectedPresences.get(entry.getKey());
                    presences.remove(directedPresence);
                    if (presences.isEmpty()) {
                        localDirectedPresences.remove(entry.getKey());
                    }
                }
            }
        }
    }
Removes directed presences sent to entities that are no longer available.
xmppserver/src/main/java/org/jivesoftware/openfire/handler/PresenceUpdateHandler.java