Package org.ldaptive
Class SingleConnectionFactory
- java.lang.Object
-
- org.ldaptive.AbstractFreezable
-
- org.ldaptive.DefaultConnectionFactory
-
- org.ldaptive.SingleConnectionFactory
-
- All Implemented Interfaces:
ConnectionFactory
,Freezable
public final class SingleConnectionFactory extends DefaultConnectionFactory
Creates a single connection which is proxied for LDAP operations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SingleConnectionFactory.Builder
protected static class
SingleConnectionFactory.ConnectionProxy
Contains the connection used by this factory.class
SingleConnectionFactory.ReinitializeConnectionConsumer
InvokesdestroyConnectionProxy()
followed byinitializeConnectionProxy()
.
-
Field Summary
Fields Modifier and Type Field Description private ExecutorService
factoryExecutor
Executor for scheduling factory tasks.private boolean
failFastInitialize
Whetherinitialize()
should throw if the connection cannot be opened.private boolean
initialized
Whetherinitialize()
has been successfully invoked.private boolean
nonBlockingInitialize
Whetherinitialize()
should occur on a separate thread.private Predicate<Connection>
onClose
To run when a connection is closed.private Predicate<Connection>
onOpen
To run when a connection is opened.private SingleConnectionFactory.ConnectionProxy
proxy
The proxy used by this factory.private ConnectionValidator
validator
For validating the connection.-
Fields inherited from class org.ldaptive.DefaultConnectionFactory
logger
-
-
Constructor Summary
Constructors Constructor Description SingleConnectionFactory()
Default constructor.SingleConnectionFactory(String ldapUrl)
Creates a new single connection factory.SingleConnectionFactory(String ldapUrl, Transport t)
Creates a new single connection factory.SingleConnectionFactory(ConnectionConfig cc)
Creates a new single connection factory.SingleConnectionFactory(ConnectionConfig cc, Transport t)
Creates a new single connection factory.SingleConnectionFactory(Transport t)
Creates a new single connection factory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SingleConnectionFactory.Builder
builder()
Creates a builder for this class.static SingleConnectionFactory.Builder
builder(Transport t)
Creates a builder for this class.void
close()
Free any resources associated with this factory.private void
destroyConnectionProxy()
Closes the connection and sets the proxy to null.void
freeze()
Freezes this object, making it immutable.Connection
getConnection()
Creates a new connection.boolean
getFailFastInitialize()
Returns whetherinitialize()
should throw if the connection cannot be opened.boolean
getNonBlockingInitialize()
Returns whetherinitialize()
should execute on a separate thread.Predicate<Connection>
getOnClose()
Returns the function to run when the connection is closed.Predicate<Connection>
getOnOpen()
Returns the function to run when the connection is opened.ConnectionValidator
getValidator()
Returns the connection validator for this factory.void
initialize()
Prepares this factory for use.private void
initializeConnectionProxy()
Opens the connection and creates the connection proxy.private void
initializeInternal()
Attempts to open the connection and establish the proxy.boolean
isInitialized()
Returns whether this factory has been initialized.void
setFailFastInitialize(boolean b)
Sets whetherinitialize()
should throw if the connection cannot be opened.void
setNonBlockingInitialize(boolean b)
Sets whetherinitialize()
should execute on a separate thread.void
setOnClose(Predicate<Connection> function)
Sets the function to run when the connection is closed.void
setOnOpen(Predicate<Connection> function)
Sets the function to run when the connection is opened.void
setValidator(ConnectionValidator cv)
Sets the connection validator for this factory.String
toString()
-
Methods inherited from class org.ldaptive.DefaultConnectionFactory
getConnectionConfig, getTransport, setConnectionConfig
-
Methods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, isFrozen
-
-
-
-
Field Detail
-
proxy
private SingleConnectionFactory.ConnectionProxy proxy
The proxy used by this factory.
-
initialized
private boolean initialized
Whetherinitialize()
has been successfully invoked.
-
failFastInitialize
private boolean failFastInitialize
Whetherinitialize()
should throw if the connection cannot be opened.
-
nonBlockingInitialize
private boolean nonBlockingInitialize
Whetherinitialize()
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 Detail
-
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 tot
- 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 configurationt
- transport
-
-
Method Detail
-
freeze
public void freeze()
Description copied from interface:Freezable
Freezes this object, making it immutable.- Specified by:
freeze
in interfaceFreezable
- Overrides:
freeze
in classDefaultConnectionFactory
-
getFailFastInitialize
public boolean getFailFastInitialize()
Returns whetherinitialize()
should throw if the connection cannot be opened.- Returns:
- whether
initialize()
should throw
-
setFailFastInitialize
public void setFailFastInitialize(boolean b)
Sets whetherinitialize()
should throw if the connection cannot be opened.- Parameters:
b
- whetherinitialize()
should throw
-
getNonBlockingInitialize
public boolean getNonBlockingInitialize()
Returns whetherinitialize()
should execute on a separate thread.- Returns:
- whether
initialize()
should block
-
setNonBlockingInitialize
public void setNonBlockingInitialize(boolean b)
Sets whetherinitialize()
should execute on a separate thread.- Parameters:
b
- whetherinitialize()
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
- ifConnection.open()
fails andfailFastInitialize
is true
-
initializeConnectionProxy
private void initializeConnectionProxy() throws LdapException
Opens the connection and creates the connection proxy. InvokesonOpen
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. InvokesonClose
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 interfaceConnectionFactory
- Overrides:
getConnection
in classDefaultConnectionFactory
- Returns:
- connection
-
close
public void close()
Description copied from interface:ConnectionFactory
Free any resources associated with this factory.- Specified by:
close
in interfaceConnectionFactory
- Overrides:
close
in classDefaultConnectionFactory
-
toString
public String toString()
- Overrides:
toString
in classDefaultConnectionFactory
-
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
-
-