@Override
    public void execute(@Nonnull final SessionData data, Element command) {
        final Locale preferredLocale = SessionManager.getInstance().getLocaleForSession(data.getOwner());

        DataForm form = new DataForm(DataForm.Type.result);

        FormField field = form.addField();
        field.setType(FormField.Type.hidden);
        field.setVariable("FORM_TYPE");
        field.addValue("http://jabber.org/protocol/admin");

        field = form.addField();
        field.setType(FormField.Type.text_single);
        field.setLabel(LocaleUtils.getLocalizedString("commands.admin.getnumberonlineusers.form.field.onlineusersnum.label", preferredLocale));
        field.setVariable("onlineusersnum");

        // Make sure that we are only counting based on bareJIDs and not fullJIDs
        Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
        Set<String> users = new HashSet<>(sessions.size());
        for (ClientSession session : sessions) {
            users.add(session.getAddress().toBareJID());
        }
        field.addValue(users.size());

        command.add(form.getElement());
    }
Command that allows to retrieve the number of registered users who are online at
any one moment. By "online user" is meant any user or account that currently has
an IM session that may or may not be available.

@author Gaston Dombiak
@see <a href="https://xmpp.org/extensions/xep-0133.html#get-online-users-num">XEP-0133 Service Administration: Get Number of Online Users</a>
xmppserver/src/main/java/org/jivesoftware/openfire/commands/admin/GetNumberOnlineUsers.java