Package org.ldaptive.transport
Class TransportConnection
- java.lang.Object
-
- org.ldaptive.transport.TransportConnection
-
- All Implemented Interfaces:
AutoCloseable
,Connection
- Direct Known Subclasses:
NettyConnection
public abstract class TransportConnection extends Object implements Connection
Base class for connection implementations.
-
-
Field Summary
Fields Modifier and Type Field Description protected ReentrantLock
closeLock
Only one invocation of close can occur at a time.protected ConnectionConfig
connectionConfig
Provides host connection configuration.private ConnectionStrategy
connectionStrategy
Connection strategy for this connection.protected Instant
lastSuccessfulOpen
Time of the last successful open for this connection.private static Logger
LOGGER
Logger for this class.protected ReentrantLock
openLock
Only one invocation of open can occur at a time.
-
Constructor Summary
Constructors Constructor Description TransportConnection(ConnectionConfig config)
Creates a new transport connection.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
complete(DefaultOperationHandle handle)
Report that the supplied handle has completed.void
open()
Opens the connection.protected abstract void
open(LdapURL url)
Attempt to open a connection to the supplied LDAP URL.protected abstract void
operation(UnbindRequest request)
Executes an unbind operation.protected void
reopen(RetryMetadata metadata)
Method to support reopening a connection that was previously established.protected void
strategyOpen(RetryMetadata metadata)
Retrieves URLs from the connection strategy and attempts each one, in order, until a connection is made or the list is exhausted.protected abstract boolean
test(LdapURL url)
Determine whether the supplied URL is acceptable for use.protected abstract void
write(DefaultOperationHandle handle)
Write the request in the supplied handle to the LDAP server.
-
-
-
Field Detail
-
LOGGER
private static final Logger LOGGER
Logger for this class.
-
openLock
protected final ReentrantLock openLock
Only one invocation of open can occur at a time.
-
closeLock
protected final ReentrantLock closeLock
Only one invocation of close can occur at a time.
-
connectionConfig
protected final ConnectionConfig connectionConfig
Provides host connection configuration.
-
lastSuccessfulOpen
protected Instant lastSuccessfulOpen
Time of the last successful open for this connection.
-
connectionStrategy
private final ConnectionStrategy connectionStrategy
Connection strategy for this connection. Default value isActivePassiveConnectionStrategy
.
-
-
Constructor Detail
-
TransportConnection
public TransportConnection(ConnectionConfig config)
Creates a new transport connection.- Parameters:
config
- connection configuration
-
-
Method Detail
-
open
public void open() throws LdapException
Description copied from interface:Connection
Opens the connection.- Specified by:
open
in interfaceConnection
- Throws:
LdapException
- if an error occurs opening the connection
-
reopen
protected void reopen(RetryMetadata metadata) throws LdapException
Method to support reopening a connection that was previously established. This method differs fromopen()
in that the autoReconnectCondition is tested before the open is attempted.- Parameters:
metadata
- associated with this reopen- Throws:
LdapException
- if the open fails
-
strategyOpen
protected void strategyOpen(RetryMetadata metadata) throws LdapException
Retrieves URLs from the connection strategy and attempts each one, in order, until a connection is made or the list is exhausted.- Parameters:
metadata
- to track URL success and failure- Throws:
LdapException
- if a connection cannot be established
-
test
protected abstract boolean test(LdapURL url)
Determine whether the supplied URL is acceptable for use.- Parameters:
url
- LDAP URL to test- Returns:
- whether URL can be become active
-
open
protected abstract void open(LdapURL url) throws LdapException
Attempt to open a connection to the supplied LDAP URL.- Parameters:
url
- LDAP URL to connect to- Throws:
LdapException
- if opening the connection fails
-
operation
protected abstract void operation(UnbindRequest request)
Executes an unbind operation. Clients should close connections usingConnection.close()
.- Parameters:
request
- unbind request
-
write
protected abstract void write(DefaultOperationHandle handle)
Write the request in the supplied handle to the LDAP server. This method does not throw, it should report exceptions to the handle.- Parameters:
handle
- for the operation write
-
complete
protected abstract void complete(DefaultOperationHandle handle)
Report that the supplied handle has completed. Allows the connection to clean up any resources associated with the handle.- Parameters:
handle
- that has completed
-
-