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 classSingleConnectionFactory.Builderprotected static classSingleConnectionFactory.ConnectionProxyContains the connection used by this factory.classSingleConnectionFactory.ReinitializeConnectionConsumerInvokesdestroyConnectionProxy()followed byinitializeConnectionProxy().
-
Field Summary
Fields Modifier and Type Field Description private ExecutorServicefactoryExecutorExecutor for scheduling factory tasks.private booleanfailFastInitializeWhetherinitialize()should throw if the connection cannot be opened.private booleaninitializedWhetherinitialize()has been successfully invoked.private booleannonBlockingInitializeWhetherinitialize()should occur on a separate thread.private Predicate<Connection>onCloseTo run when a connection is closed.private Predicate<Connection>onOpenTo run when a connection is opened.private SingleConnectionFactory.ConnectionProxyproxyThe proxy used by this factory.private ConnectionValidatorvalidatorFor 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.Builderbuilder()Creates a builder for this class.static SingleConnectionFactory.Builderbuilder(Transport t)Creates a builder for this class.voidclose()Free any resources associated with this factory.private voiddestroyConnectionProxy()Closes the connection and sets the proxy to null.voidfreeze()Freezes this object, making it immutable.ConnectiongetConnection()Creates a new connection.booleangetFailFastInitialize()Returns whetherinitialize()should throw if the connection cannot be opened.booleangetNonBlockingInitialize()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.ConnectionValidatorgetValidator()Returns the connection validator for this factory.voidinitialize()Prepares this factory for use.private voidinitializeConnectionProxy()Opens the connection and creates the connection proxy.private voidinitializeInternal()Attempts to open the connection and establish the proxy.booleanisInitialized()Returns 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.voidsetValidator(ConnectionValidator cv)Sets the connection validator for this factory.StringtoString()-
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: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
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 LdapExceptionPrepares this factory for use.- Throws:
LdapException- if the connection cannot be opened
-
initializeInternal
private void initializeInternal() throws LdapExceptionAttempts to open the connection and establish the proxy.- Throws:
LdapException- ifConnection.open()fails andfailFastInitializeis true
-
initializeConnectionProxy
private void initializeConnectionProxy() throws LdapExceptionOpens 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
public 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
public String toString()
- Overrides:
toStringin 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
-
-