System.out.println("Accounts created successfully: " + created);
}
public void populateRosters(String userPrefix, int from, int total, int usersPerRoster) {
XMPPServer server = XMPPServer.getInstance();
RosterManager rosterManager = server.getRosterManager();
int batchTotal = total / usersPerRoster;
System.out.println("Total batches of users: " + batchTotal);
for (int batchNumber = 0; batchNumber < batchTotal; batchNumber++) {
System.out.println("Current batch: " + batchNumber + ". Users: " + batchNumber*usersPerRoster + " - " + ((batchNumber*usersPerRoster)+usersPerRoster));
// Add rosters items between connected users
for (int i = (batchNumber * usersPerRoster) + from;
i < (batchNumber * usersPerRoster) + usersPerRoster + from; i++) {
String username = userPrefix + i;
Roster roster;
try {
roster = rosterManager.getRoster(username);
} catch (UserNotFoundException e) {
continue;
}
if (roster.getRosterItems().size() >= usersPerRoster) {
// Roster already populated. Skip it.
continue;
}
for (int j = (batchNumber * usersPerRoster) + from;
j < (batchNumber * usersPerRoster) + usersPerRoster + from; j++) {
if (i == j) {
continue;
}
try {
Roster recipientRoster = rosterManager.getRoster(userPrefix + j);
manageSub(server.createJID(userPrefix + j, null), true, Presence.Type.subscribe, roster);
manageSub(server.createJID(username, null), false, Presence.Type.subscribe, recipientRoster);
manageSub(server.createJID(userPrefix + j, null), true, Presence.Type.subscribed, roster);