public Collection<Group> getGroups() {
        HashSet<String> groupNames = getGroupNamesFromCache();
        if (groupNames == null) {
            synchronized(GROUP_NAMES_LOCK) {
                groupNames = getGroupNamesFromCache();
                if (groupNames == null) {
                    groupNames = new HashSet<>(provider.getGroupNames());
                    saveGroupNamesInCache(groupNames);
                }
            }
        }
        return new GroupCollection(groupNames);
    }
Returns an unmodifiable Collection of all groups in the system.

NOTE: Iterating through the resulting collection has the effect of loading
every group into memory. This may be an issue for large deployments. You
may call the size() method on the resulting collection to determine the best
approach to take before iterating over (and thus instantiating) the groups.

@return an unmodifiable Collection of all groups.
xmppserver/src/main/java/org/jivesoftware/openfire/group/GroupManager.java