Package org.ldaptive

Class SingleConnectionFactory

All Implemented Interfaces:
ConnectionFactory, Freezable

public final class SingleConnectionFactory extends DefaultConnectionFactory
Creates a single connection which is proxied for LDAP operations.
  • Field Details

    • proxy

      The proxy used by this factory.
    • initialized

      private boolean initialized
      Whether initialize() has been successfully invoked.
    • failFastInitialize

      private boolean failFastInitialize
      Whether initialize() should throw if the connection cannot be opened.
    • nonBlockingInitialize

      private boolean nonBlockingInitialize
      Whether initialize() should occur on a separate thread.
    • onOpen

      private Predicate<Connection> onOpen
      To run when a connection is opened.
    • onClose

      private Predicate<Connection> onClose
      To run when a connection is closed.
    • validator

      private ConnectionValidator validator
      For validating the connection.
    • factoryExecutor

      private ExecutorService factoryExecutor
      Executor for scheduling factory tasks.
  • Constructor Details

    • SingleConnectionFactory

      public SingleConnectionFactory()
      Default constructor.
    • SingleConnectionFactory

      public SingleConnectionFactory(Transport t)
      Creates a new single connection factory.
      Parameters:
      t - transport
    • SingleConnectionFactory

      public SingleConnectionFactory(String ldapUrl)
      Creates a new single connection factory.
      Parameters:
      ldapUrl - to connect to
    • SingleConnectionFactory

      public SingleConnectionFactory(String ldapUrl, Transport t)
      Creates a new single connection factory.
      Parameters:
      ldapUrl - to connect to
      t - transport
    • SingleConnectionFactory

      public SingleConnectionFactory(ConnectionConfig cc)
      Creates a new single connection factory.
      Parameters:
      cc - connection configuration
    • SingleConnectionFactory

      public SingleConnectionFactory(ConnectionConfig cc, Transport t)
      Creates a new single connection factory.
      Parameters:
      cc - connection configuration
      t - transport
  • Method Details

    • freeze

      public void freeze()
      Description copied from interface: Freezable
      Freezes this object, making it immutable.
      Specified by:
      freeze in interface Freezable
      Overrides:
      freeze in class DefaultConnectionFactory
    • getFailFastInitialize

      public boolean getFailFastInitialize()
      Returns whether initialize() should throw if the connection cannot be opened.
      Returns:
      whether initialize() should throw
    • setFailFastInitialize

      public void setFailFastInitialize(boolean b)
      Sets whether initialize() should throw if the connection cannot be opened.
      Parameters:
      b - whether initialize() should throw
    • getNonBlockingInitialize

      public boolean getNonBlockingInitialize()
      Returns whether initialize() should execute on a separate thread.
      Returns:
      whether initialize() should block
    • setNonBlockingInitialize

      public void setNonBlockingInitialize(boolean b)
      Sets whether initialize() should execute on a separate thread.
      Parameters:
      b - whether initialize() should block
    • getOnOpen

      public Predicate<Connection> getOnOpen()
      Returns the function to run when the connection is opened.
      Returns:
      on open function
    • setOnOpen

      public void setOnOpen(Predicate<Connection> function)
      Sets the function to run when the connection is opened.
      Parameters:
      function - to run on connection open
    • getOnClose

      public Predicate<Connection> getOnClose()
      Returns the function to run when the connection is closed.
      Returns:
      on close function
    • setOnClose

      public void setOnClose(Predicate<Connection> function)
      Sets the function to run when the connection is closed.
      Parameters:
      function - to run on connection close
    • getValidator

      public ConnectionValidator getValidator()
      Returns the connection validator for this factory.
      Returns:
      connection validator
    • setValidator

      public void setValidator(ConnectionValidator cv)
      Sets the connection validator for this factory.
      Parameters:
      cv - connection validator
    • isInitialized

      public boolean isInitialized()
      Returns whether this factory has been initialized.
      Returns:
      whether this factory has been initialized
    • initialize

      public void initialize() throws LdapException
      Prepares this factory for use.
      Throws:
      LdapException - if the connection cannot be opened
    • initializeInternal

      private void initializeInternal() throws LdapException
      Attempts to open the connection and establish the proxy.
      Throws:
      LdapException - if Connection.open() fails and failFastInitialize is true
    • initializeConnectionProxy

      private void initializeConnectionProxy() throws LdapException
      Opens the connection and creates the connection proxy. Invokes onOpen and will tear down the connection if that function returns false.
      Throws:
      LdapException - if connection open fails
    • destroyConnectionProxy

      private void destroyConnectionProxy()
      Closes the connection and sets the proxy to null. Invokes onClose prior to closing the connection.
    • getConnection

      public Connection getConnection()
      Description copied from class: DefaultConnectionFactory
      Creates a new connection. Connections returned from this method must be opened before they can perform ldap operations.
      Specified by:
      getConnection in interface ConnectionFactory
      Overrides:
      getConnection in class DefaultConnectionFactory
      Returns:
      connection
    • close

      public void close()
      Description copied from interface: ConnectionFactory
      Free any resources associated with this factory.
      Specified by:
      close in interface ConnectionFactory
      Overrides:
      close in class DefaultConnectionFactory
    • toString

      public String toString()
      Overrides:
      toString in class DefaultConnectionFactory
    • builder

      public static SingleConnectionFactory.Builder builder()
      Creates a builder for this class.
      Returns:
      new builder
    • builder

      public static SingleConnectionFactory.Builder builder(Transport t)
      Creates a builder for this class.
      Parameters:
      t - transport
      Returns:
      new builder