All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ldaptive.provider.RandomConnectionStrategy Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
/* See LICENSE for licensing and NOTICE for copyright. */
package org.ldaptive.provider;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Connection strategy that randomizes the list of configured URLs. A random URL ordering will be created for each
 * connection attempt.
 *
 * @author  Middleware Services
 */
public class RandomConnectionStrategy implements ConnectionStrategy
{


  /**
   * Return a list of URLs in random order.
   *
   * @param  metadata  which can be used to produce the URL list
   *
   * @return  list of URLs to attempt connections to
   */
  @Override
  public String[] getLdapUrls(final ConnectionFactoryMetadata metadata)
  {
    if (metadata == null || metadata.getLdapUrl() == null) {
      return null;
    }

    final List l = Arrays.asList(metadata.getLdapUrl().split(" "));
    Collections.shuffle(l);
    return l.toArray(new String[l.size()]);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy