use of com.unboundid.ldap.sdk.FailoverServerSet in project zm-mailbox by Zimbra.
the class LdapServerPoolTest method testLDAPCreatePool.
@Test
public void testLDAPCreatePool() throws Exception {
LdapServerPool pool = new LdapServerPool(new MockLdapServerConfig(LdapServerType.MASTER));
FailoverServerSet set = (FailoverServerSet) pool.serverSet;
Assert.assertTrue(set.reOrderOnFailover());
}
use of com.unboundid.ldap.sdk.FailoverServerSet in project zm-mailbox by Zimbra.
the class LdapServerPool method createServerSet.
private ServerSet createServerSet(SocketFactory socketFactory) throws UnknownHostException {
if (urls.size() == 1) {
LDAPURL url = urls.get(0);
if (LdapConnType.isLDAPI(url.getScheme())) {
// dummy ldap host is used for LDAPI
return new SingleServerSet(url.getHost(), url.getPort(), socketFactory, connOpts);
}
InetAddress[] addrs = InetAddress.getAllByName(url.getHost());
if (addrs.length == 1) {
if (socketFactory == null) {
return new SingleServerSet(url.getHost(), url.getPort(), connOpts);
} else {
return new SingleServerSet(url.getHost(), url.getPort(), socketFactory, connOpts);
}
} else {
Set<String> uniqAddr = new HashSet<>();
for (int i = 0; i < addrs.length; i++) {
uniqAddr.add(addrs[i].getHostAddress());
}
if (uniqAddr.size() == 1) {
if (socketFactory == null) {
return new SingleServerSet(url.getHost(), url.getPort(), connOpts);
} else {
return new SingleServerSet(url.getHost(), url.getPort(), socketFactory, connOpts);
}
} else {
String[] hosts = new String[uniqAddr.size()];
int[] ports = new int[uniqAddr.size()];
int i = 0;
for (String addr : uniqAddr) {
hosts[i] = addr;
ports[i] = url.getPort();
i++;
}
if (socketFactory == null) {
return new FailoverServerSet(hosts, ports, connOpts);
} else {
return new FailoverServerSet(hosts, ports, socketFactory, connOpts);
}
}
}
} else {
Set<Pair<String, Integer>> hostsAndPorts = new LinkedHashSet<>();
for (LDAPURL url : urls) {
InetAddress[] addrs = InetAddress.getAllByName(url.getHost());
if (addrs.length == 1) {
hostsAndPorts.add(new Pair<String, Integer>(url.getHost(), url.getPort()));
} else {
for (int i = 0; i < addrs.length; i++) {
hostsAndPorts.add(new Pair<String, Integer>(addrs[i].getHostAddress(), url.getPort()));
}
}
}
String[] hostsStrs = new String[hostsAndPorts.size()];
int[] portsStrs = new int[hostsAndPorts.size()];
int i = 0;
for (Pair<String, Integer> pair : hostsAndPorts) {
hostsStrs[i] = pair.getFirst();
portsStrs[i] = pair.getSecond();
i++;
}
if (socketFactory == null) {
FailoverServerSet serverSet = new FailoverServerSet(hostsStrs, portsStrs, connOpts);
serverSet.setReOrderOnFailover(true);
return serverSet;
} else {
FailoverServerSet serverSet = new FailoverServerSet(hostsStrs, portsStrs, socketFactory, connOpts);
serverSet.setReOrderOnFailover(true);
return serverSet;
}
}
}
Aggregations