Browse Source

Parallel add and delete

main
Christian Pape 3 days ago
committed by Dustin Frisch
parent
commit
a87e8c6384
No known key found for this signature in database GPG Key ID: B4C3BF012D9B26BE
  1. 18
      src/main/java/de/hsfulda/informatik/AccountSource.java

18
src/main/java/de/hsfulda/informatik/AccountSource.java

@ -12,11 +12,14 @@ import com.unboundid.ldap.sdk.SearchScope;
import com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest;
import com.unboundid.util.ssl.SSLUtil;
import com.unboundid.util.ssl.TrustAllTrustManager;
import sun.nio.ch.ThreadPool;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
public class AccountSource {
@ -24,6 +27,7 @@ public class AccountSource {
final List<SearchResultEntry> searchResultEntryList;
final Set<String> users;
final String baseDN;
final ExecutorService executorService = Executors.newFixedThreadPool(24);
AccountSource(final String baseDN, final List<SearchResultEntry> searchResultEntryList) {
this.baseDN = baseDN;
@ -65,10 +69,12 @@ public class AccountSource {
public void add(final List<Entry> usersToBeAdded) {
for (final Entry entry : usersToBeAdded) {
System.out.print("-> Füge Benutzer " + entry.getDN() + "...");
executorService.submit(new Runnable() {
@Override
public void run() {
final LDAPResult ldapResult;
try {
ldapResult = connection.add(entry);
if (ldapResult.getResultCode().intValue() == 0) {
System.out.print("Ok\n");
} else {
@ -78,15 +84,19 @@ public class AccountSource {
System.out.print("Fehler (" + e.getMessage() + ")\n");
}
}
});
}
}
public void del(final Set<String> usersToBeDeleted) {
for (final String user : usersToBeDeleted) {
System.out.print("-> Lösche Benutzer cn=" + user + "," + this.baseDN + "...");
executorService.submit(new Runnable() {
@Override
public void run() {
final LDAPResult ldapResult;
try {
ldapResult = connection.delete("cn=" + user + "," + this.baseDN);
ldapResult = connection.delete("cn=" + user + "," + AccountSource.this.baseDN);
if (ldapResult.getResultCode().intValue() == 0) {
System.out.print("Ok\n");
@ -97,5 +107,7 @@ public class AccountSource {
System.out.print("Fehler (" + e.getMessage() + ")\n");
}
}
});
}
}
}
Loading…
Cancel
Save