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

org.ldaptive.ConnectionStrategy Maven / Gradle / Ivy

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

import java.util.function.Predicate;

/**
 * Interface to describe various connection strategies. Each strategy returns an ordered list of LDAP URLs to attempt
 * when opening a connection.
 *
 * @author  Middleware Services
 */
public interface ConnectionStrategy extends Iterable
{


  /**
   * Populates a {@link LdapURLSet} from the URL string provided at configuration time.
   *
   * @param  urls  Space-delimited string of URLs describing the LDAP hosts to connect to. The URLs in the string
   *               are commonly {@code ldap://} or {@code ldaps://} URLs that directly describe the hosts to connect to,
   *               but may also describe a resource from which to obtain LDAP connection URLs as is the case for
   *               {@link DnsSrvConnectionStrategy} that use URLs with the scheme {@code dns:}.
   * @param  urlSet  LDAP URL set to populate.
   */
  void populate(String urls, LdapURLSet urlSet);


  /**
   * Prepare this strategy for use.
   *
   * @param  urls  LDAP URLs for this strategy
   * @param  activateCondition  predicate to determine whether a connection is active
   */
  void initialize(String urls, Predicate activateCondition);


  /**
   * Whether this strategy is ready for use.
   *
   * @return  whether this strategy is ready for use
   */
  boolean isInitialized();


  /**
   * Returns the condition used to activate connections.
   *
   * @return  activate condition
   */
  Predicate getActivateCondition();


  /**
   * Returns the condition used to determine whether to attempt to activate a connection.
   *
   * @return  retry condition
   */
  Predicate getRetryCondition();


  /**
   * Indicates the supplied URL was successfully connected to.
   *
   * @param  url  which was successfully connected to
   */
  void success(LdapURL url);


  /**
   * Indicates the supplied URL could not be connected to.
   *
   * @param  url  which was could not be connected to
   */
  void failure(LdapURL url);


  /**
   * Create a deep copy of this strategy.
   *
   * @return  new instance of this connection strategy
   */
  ConnectionStrategy newInstance();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy