ldapsdk
ldapsdk copied to clipboard
LDAPConnection should have an asyncBind method
It would be good if there could be an asynchronous bind method to go along with the rest of the async methods.
This is an intentional omission because bind operations cannot be processed asynchronously. LDAP explicitly forbids processing any operation on a connection while a bind is in progress on that connection.
It is true that an asynchronous API could be used in a manner that guarantees only one operation in progress on a connection, but it is expected that it will primarily used for processing multiple operations concurrently on a single connection, which would cause trouble for bind operations (and potentially in a way that is difficult to troubleshoot). It's also the case that it isn't particularly difficult to use existing Java features to process an operation in the background if you're confident that it won't conflict with another operation on the same connection.
One important thing to note is that each LDAPConnection
has it's own LDAPConnectionReader
which extends Thread
; the actual socket level IO is always blocking. If the underlying reads used a Selector
on the SocketChannel
(such that multiple connections could be multiplexed onto a single Thread
), or AsynchronousSocketChannel
(such that multiple connections could be multiplexed onto a single AsynchronousChannelGroup
), then there would be a reason to have an asyncBind
method to avoid blocking.
As is, the async methods don't actually avoid blocking IO, they simply allow for multiple concurrent operations on the same connection, and since the bind operation cannot be processed concurrently with other operations on the connection, there is no current reason for an asyncBind
.