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 classNettyConnection.AutoReadEventHandlerInitiates a channel read when an LDAP message has been processed and auto read is false.classNettyConnection.BindOperationHandleBind specific operation handle that locks other operations until the bind completes.protected static classNettyConnection.MessageDecoderDecodes byte buffer into a concrete LDAP response message.protected static classNettyConnection.MessageStatusEnum that describes the state of an LDAP message in the pipeline.protected static classNettyConnection.RequestEncoderEncodes 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 voidclose(RequestControl... controls)Closes this connection.protected voidcomplete(DefaultOperationHandle handle)Report that the supplied handle has completed.LdapURLgetLdapURL()Returns the URL that was selected for this connection.booleanisOpen()Returns whether the underlying Netty channel is open.protected voidnotifyOperationHandlesOfClose()Sends an exception notification to all pending responses that the connection has been closed.protected voidopen(LdapURL url)Attempt to open a connection to the supplied LDAP URL.voidoperation(AbandonRequest request)Executes an abandon operation.DefaultOperationHandle<AddRequest,AddResponse>operation(AddRequest request)Creates a handle for an add operation.NettyConnection.BindOperationHandleoperation(BindRequest request)Creates a handle for a bind operation.DefaultCompareOperationHandleoperation(CompareRequest request)Creates a handle for a compare operation.DefaultOperationHandle<DeleteRequest,DeleteResponse>operation(DeleteRequest request)Creates a handle for an delete operation.DefaultExtendedOperationHandleoperation(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.BindResponseoperation(DefaultSaslClientRequest request)Performs a SASL client bind operation.BindResponseoperation(SaslClientRequest request)Performs a SASL bind operation that uses a custom client.DefaultSearchOperationHandleoperation(SearchRequest request)Creates a handle for a search operation.protected voidoperation(UnbindRequest request)Executes an unbind operation.protected voidreconnect()Attempts to reestablish the channel for this connection.protected booleantest(LdapURL url)Determine whether the supplied URL is acceptable for use.java.lang.StringtoString()protected voidwrite(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:TransportConnectionDetermine whether the supplied URL is acceptable for use.- Specified by:
testin 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:TransportConnectionAttempt to open a connection to the supplied LDAP URL.- Specified by:
openin classTransportConnection- Parameters:
url- LDAP URL to connect to- Throws:
LdapException- if opening the connection fails
-
getLdapURL
public LdapURL getLdapURL()
Description copied from interface:ConnectionReturns 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:TransportConnectionExecutes an unbind operation. Clients should close connections usingConnection.close().- Specified by:
operationin 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:ConnectionExecutes 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:ConnectionCreates a handle for an add operation.- Parameters:
request- add request- Returns:
- operation handle
-
operation
public NettyConnection.BindOperationHandle operation(BindRequest request)
Description copied from interface:ConnectionCreates 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:ConnectionCreates 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:ConnectionCreates a handle for an delete operation.- Parameters:
request- delete request- Returns:
- operation handle
-
operation
public DefaultExtendedOperationHandle operation(ExtendedRequest request)
Description copied from interface:ConnectionCreates 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:ConnectionCreates 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:ConnectionCreates 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:ConnectionCreates a handle for a search operation.- Parameters:
request- search request- Returns:
- search operation handle
-
write
protected void write(DefaultOperationHandle handle)
Description copied from class:TransportConnectionWrite the request in the supplied handle to the LDAP server. This method does not throw, it should report exceptions to the handle.- Specified by:
writein classTransportConnection- Parameters:
handle- for the operation write
-
complete
protected void complete(DefaultOperationHandle handle)
Description copied from class:TransportConnectionReport that the supplied handle has completed. Allows the connection to cleanup any resources associated with the handle.- Specified by:
completein 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 themessageWorkerGroupif 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:
toStringin classjava.lang.Object
-
-