Package org.ldaptive.transport.netty
Class NettyConnection
- java.lang.Object
-
- org.ldaptive.transport.TransportConnection
-
- org.ldaptive.transport.netty.NettyConnection
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,Connection
public final class NettyConnection extends TransportConnection
Netty based connection implementation.- Author:
- Middleware Services
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
NettyConnection.AutoReadEventHandler
Initiates a channel read when an LDAP message has been processed and auto read is false.class
NettyConnection.BindOperationHandle
Bind specific operation handle that locks other operations until the bind completes.protected static class
NettyConnection.MessageDecoder
Decodes byte buffer into a concrete LDAP response message.protected static class
NettyConnection.MessageStatus
Enum that describes the state of an LDAP message in the pipeline.protected static class
NettyConnection.RequestEncoder
Encodes an LDAP request into it's DER bytes.
-
Field Summary
-
Fields inherited from class org.ldaptive.transport.TransportConnection
closeLock, connectionConfig, lastSuccessfulOpen, openLock
-
-
Constructor Summary
Constructors Constructor Description NettyConnection(ConnectionConfig config, java.lang.Class<? extends io.netty.channel.Channel> type, io.netty.channel.EventLoopGroup ioGroup, io.netty.channel.EventLoopGroup messageGroup, boolean shutdownGroups)
Creates a new connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close(RequestControl... controls)
Closes this connection.protected void
complete(DefaultOperationHandle handle)
Report that the supplied handle has completed.LdapURL
getLdapURL()
Returns the URL that was selected for this connection.boolean
isOpen()
Returns whether the underlying Netty channel is open.protected void
notifyOperationHandlesOfClose()
Sends an exception notification to all pending responses that the connection has been closed.protected void
open(LdapURL url)
Attempt to open a connection to the supplied LDAP URL.void
operation(AbandonRequest request)
Executes an abandon operation.DefaultOperationHandle<AddRequest,AddResponse>
operation(AddRequest request)
Creates a handle for an add operation.NettyConnection.BindOperationHandle
operation(BindRequest request)
Creates a handle for a bind operation.DefaultCompareOperationHandle
operation(CompareRequest request)
Creates a handle for a compare operation.DefaultOperationHandle<DeleteRequest,DeleteResponse>
operation(DeleteRequest request)
Creates a handle for an delete operation.DefaultExtendedOperationHandle
operation(ExtendedRequest request)
Creates a handle for an extended operation.DefaultOperationHandle<ModifyDnRequest,ModifyDnResponse>
operation(ModifyDnRequest request)
Creates a handle for a modify dn operation.DefaultOperationHandle<ModifyRequest,ModifyResponse>
operation(ModifyRequest request)
Creates a handle for a modify operation.BindResponse
operation(DefaultSaslClientRequest request)
Performs a SASL client bind operation.BindResponse
operation(SaslClientRequest request)
Performs a SASL bind operation that uses a custom client.DefaultSearchOperationHandle
operation(SearchRequest request)
Creates a handle for a search operation.protected void
operation(UnbindRequest request)
Executes an unbind operation.protected void
reconnect()
Attempts to reestablish the channel for this connection.protected boolean
test(LdapURL url)
Determine whether the supplied URL is acceptable for use.java.lang.String
toString()
protected void
write(DefaultOperationHandle handle)
Write the request in the supplied handle to the LDAP server.-
Methods inherited from class org.ldaptive.transport.TransportConnection
open, reopen, strategyOpen
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.ldaptive.Connection
close
-
-
-
-
Constructor Detail
-
NettyConnection
public NettyConnection(ConnectionConfig config, java.lang.Class<? extends io.netty.channel.Channel> type, io.netty.channel.EventLoopGroup ioGroup, io.netty.channel.EventLoopGroup messageGroup, boolean shutdownGroups)
Creates a new connection. Netty supports various transport implementations including NIO, EPOLL, KQueue, etc. The class type and event loop group are tightly coupled in this regard.- Parameters:
config
- connection configurationtype
- type of channelioGroup
- event loop group that handles I/O and supports the channel type, cannot be nullmessageGroup
- event loop group that handles inbound messages, can be nullshutdownGroups
- whether to shutdown the event loop groups when the connection is closed
-
-
Method Detail
-
test
protected boolean test(LdapURL url)
Description copied from class:TransportConnection
Determine whether the supplied URL is acceptable for use.- Specified by:
test
in classTransportConnection
- Parameters:
url
- LDAP URL to test- Returns:
- whether URL can be become active
-
open
protected void open(LdapURL url) throws LdapException
Description copied from class:TransportConnection
Attempt to open a connection to the supplied LDAP URL.- Specified by:
open
in classTransportConnection
- Parameters:
url
- LDAP URL to connect to- Throws:
LdapException
- if opening the connection fails
-
getLdapURL
public LdapURL getLdapURL()
Description copied from interface:Connection
Returns the URL that was selected for this connection. The existence of this value does not indicate a current established connection.- Returns:
- LDAP URL
-
operation
protected void operation(UnbindRequest request)
Description copied from class:TransportConnection
Executes an unbind operation. Clients should close connections usingConnection.close()
.- Specified by:
operation
in classTransportConnection
- Parameters:
request
- unbind request
-
operation
public BindResponse operation(SaslClientRequest request) throws LdapException
Performs a SASL bind operation that uses a custom client.- Parameters:
request
- to send- Returns:
- result of the GSS-API bind operation
- Throws:
LdapException
- if the operation fails or another bind is in progress
-
operation
public BindResponse operation(DefaultSaslClientRequest request) throws LdapException
Performs a SASL client bind operation.- Parameters:
request
- to send- Returns:
- result of the SASL client bind operation
- Throws:
LdapException
- if the operation fails or another bind is in progress
-
operation
public void operation(AbandonRequest request)
Description copied from interface:Connection
Executes an abandon operation. Clients should execute abandons usingOperationHandle.abandon()
.- Parameters:
request
- abandon request
-
operation
public DefaultOperationHandle<AddRequest,AddResponse> operation(AddRequest request)
Description copied from interface:Connection
Creates a handle for an add operation.- Parameters:
request
- add request- Returns:
- operation handle
-
operation
public NettyConnection.BindOperationHandle operation(BindRequest request)
Description copied from interface:Connection
Creates a handle for a bind operation. Since clients must not send requests while a bind is in progress, some methods may not be supported on the the operation handle.- Parameters:
request
- bind request- Returns:
- operation handle
-
operation
public DefaultCompareOperationHandle operation(CompareRequest request)
Description copied from interface:Connection
Creates a handle for a compare operation.- Parameters:
request
- compare request- Returns:
- compare operation handle
-
operation
public DefaultOperationHandle<DeleteRequest,DeleteResponse> operation(DeleteRequest request)
Description copied from interface:Connection
Creates a handle for an delete operation.- Parameters:
request
- delete request- Returns:
- operation handle
-
operation
public DefaultExtendedOperationHandle operation(ExtendedRequest request)
Description copied from interface:Connection
Creates a handle for an extended operation.- Parameters:
request
- extended request- Returns:
- extended operation handle
-
operation
public DefaultOperationHandle<ModifyRequest,ModifyResponse> operation(ModifyRequest request)
Description copied from interface:Connection
Creates a handle for a modify operation.- Parameters:
request
- modify request- Returns:
- operation handle
-
operation
public DefaultOperationHandle<ModifyDnRequest,ModifyDnResponse> operation(ModifyDnRequest request)
Description copied from interface:Connection
Creates a handle for a modify dn operation.- Parameters:
request
- modify dn request- Returns:
- operation handle
-
operation
public DefaultSearchOperationHandle operation(SearchRequest request)
Description copied from interface:Connection
Creates a handle for a search operation.- Parameters:
request
- search request- Returns:
- search operation handle
-
write
protected void write(DefaultOperationHandle handle)
Description copied from class:TransportConnection
Write the request in the supplied handle to the LDAP server. This method does not throw, it should report exceptions to the handle.- Specified by:
write
in classTransportConnection
- Parameters:
handle
- for the operation write
-
complete
protected void complete(DefaultOperationHandle handle)
Description copied from class:TransportConnection
Report that the supplied handle has completed. Allows the connection to cleanup any resources associated with the handle.- Specified by:
complete
in classTransportConnection
- Parameters:
handle
- that has completed
-
close
public void close(RequestControl... controls)
Closes this connection. Abandons all pending responses and sends an unbind to the LDAP server if the connection is open when this method is invoked.- Parameters:
controls
- to send with the unbind request when closing the connection
-
notifyOperationHandlesOfClose
protected void notifyOperationHandlesOfClose()
Sends an exception notification to all pending responses that the connection has been closed. Since this invokes any configured exception handlers, notifications will use themessageWorkerGroup
if it is configured.
-
reconnect
protected void reconnect()
Attempts to reestablish the channel for this connection.- Throws:
java.lang.IllegalStateException
- if the connection is open
-
isOpen
public boolean isOpen()
Returns whether the underlying Netty channel is open. SeeChannel.isOpen()
.- Returns:
- whether the Netty channel is open
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-