Package org.ldaptive
Class SingleConnectionFactory
java.lang.Object
org.ldaptive.AbstractFreezable
org.ldaptive.DefaultConnectionFactory
org.ldaptive.SingleConnectionFactory
- All Implemented Interfaces:
ConnectionFactory,Freezable
Creates a single connection which is proxied for LDAP operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprotected static classContains the connection used by this factory.classInvokesdestroyConnectionProxy()followed byinitializeConnectionProxy(). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ExecutorServiceExecutor for scheduling factory tasks.private booleanWhetherinitialize()should throw if the connection cannot be opened.private booleanWhetherinitialize()has been successfully invoked.private booleanWhetherinitialize()should occur on a separate thread.private Predicate<Connection>To run when a connection is closed.private Predicate<Connection>To run when a connection is opened.The proxy used by this factory.private ConnectionValidatorFor validating the connection.Fields inherited from class org.ldaptive.DefaultConnectionFactory
logger -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.SingleConnectionFactory(String ldapUrl) Creates a new single connection factory.SingleConnectionFactory(String ldapUrl, Transport t) Creates a new single connection factory.Creates a new single connection factory.Creates a new single connection factory.Creates a new single connection factory. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a builder for this class.Creates a builder for this class.voidclose()Free any resources associated with this factory.private voidCloses the connection and sets the proxy to null.voidfreeze()Freezes this object, making it immutable.Creates a new connection.booleanReturns whetherinitialize()should throw if the connection cannot be opened.booleanReturns whetherinitialize()should execute on a separate thread.Returns the function to run when the connection is closed.Returns the function to run when the connection is opened.Returns the connection validator for this factory.voidPrepares this factory for use.private voidOpens the connection and creates the connection proxy.private voidAttempts to open the connection and establish the proxy.booleanReturns whether this factory has been initialized.voidsetFailFastInitialize(boolean b) Sets whetherinitialize()should throw if the connection cannot be opened.voidsetNonBlockingInitialize(boolean b) Sets whetherinitialize()should execute on a separate thread.voidsetOnClose(Predicate<Connection> function) Sets the function to run when the connection is closed.voidsetOnOpen(Predicate<Connection> function) Sets the function to run when the connection is opened.voidSets the connection validator for this factory.toString()Methods inherited from class org.ldaptive.DefaultConnectionFactory
getConnectionConfig, getTransport, setConnectionConfigMethods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, isFrozen
-
Field Details
-
proxy
The proxy used by this factory. -
initialized
private boolean initializedWhetherinitialize()has been successfully invoked. -
failFastInitialize
private boolean failFastInitializeWhetherinitialize()should throw if the connection cannot be opened. -
nonBlockingInitialize
private boolean nonBlockingInitializeWhetherinitialize()should occur on a separate thread. -
onOpen
To run when a connection is opened. -
onClose
To run when a connection is closed. -
validator
For validating the connection. -
factoryExecutor
Executor for scheduling factory tasks.
-
-
Constructor Details
-
SingleConnectionFactory
public SingleConnectionFactory()Default constructor. -
SingleConnectionFactory
Creates a new single connection factory.- Parameters:
t- transport
-
SingleConnectionFactory
Creates a new single connection factory.- Parameters:
ldapUrl- to connect to
-
SingleConnectionFactory
Creates a new single connection factory.- Parameters:
ldapUrl- to connect tot- transport
-
SingleConnectionFactory
Creates a new single connection factory.- Parameters:
cc- connection configuration
-
SingleConnectionFactory
Creates a new single connection factory.- Parameters:
cc- connection configurationt- transport
-
-
Method Details
-
freeze
public void freeze()Description copied from interface:FreezableFreezes this object, making it immutable.- Specified by:
freezein interfaceFreezable- Overrides:
freezein 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
Returns the function to run when the connection is opened.- Returns:
- on open function
-
setOnOpen
Sets the function to run when the connection is opened.- Parameters:
function- to run on connection open
-
getOnClose
Returns the function to run when the connection is closed.- Returns:
- on close function
-
setOnClose
Sets the function to run when the connection is closed.- Parameters:
function- to run on connection close
-
getValidator
Returns the connection validator for this factory.- Returns:
- connection validator
-
setValidator
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
Prepares this factory for use.- Throws:
LdapException- if the connection cannot be opened
-
initializeInternal
Attempts to open the connection and establish the proxy.- Throws:
LdapException- ifConnection.open()fails andfailFastInitializeis true
-
initializeConnectionProxy
Opens the connection and creates the connection proxy. InvokesonOpenand 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. InvokesonCloseprior to closing the connection. -
getConnection
Description copied from class:DefaultConnectionFactoryCreates a new connection. Connections returned from this method must be opened before they can perform ldap operations.- Specified by:
getConnectionin interfaceConnectionFactory- Overrides:
getConnectionin classDefaultConnectionFactory- Returns:
- connection
-
close
public void close()Description copied from interface:ConnectionFactoryFree any resources associated with this factory.- Specified by:
closein interfaceConnectionFactory- Overrides:
closein classDefaultConnectionFactory
-
toString
- Overrides:
toStringin classDefaultConnectionFactory
-
builder
Creates a builder for this class.- Returns:
- new builder
-
builder
Creates a builder for this class.- Parameters:
t- transport- Returns:
- new builder
-