Class LdapServer
- java.lang.Object
-
- org.forgerock.opendj.ldap.LdapServer
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public final class LdapServer extends Object implements Closeable
An LDAP server connection listener which waits for LDAP connection requests to come in over the network and binds them to a server connection created using the provided server connection factory.When processing requests, server connection implementations are passed an integer as the first parameter. This integer represents the
requestID
associated with the client request and corresponds to therequestID
passed as a parameter to abandon and cancel extended requests. The request ID may also be useful for logging purposes.An
LdapServer
does not require server connection implementations to return a result when processing requests. More specifically, anLdapServer
does not maintain any internal state information associated with each request which must be released. This is useful when implementing LDAP abandon operations which may prevent results being sent for abandoned operations.The following code illustrates how to create a simple LDAP server:
/** Server connection. */ class MyClientConnection implements BiFunction<Integer, Request, Flowable<Response>> { private final LDAPClientContext clientContext; private MyClientConnection(LDAPClientContext clientContext) { this.clientContext = clientContext; } public Flowable<Response> apply(Integer requestID, Request request) throws Exception { // ... } } /** Server connection factory. */ class MyServer implements Function<LdapSession, BiFunction<Integer, Request, Flowable<Response>>> { public BiFunction<Integer, Request, Flowable<Response>> accept(LDAPClientContext context) { System.out.println("Connection from: " + context.getPeerAddress()); return new MyClientConnection(context); } } public static void main(String[] args) throws Exception { try (LdapServer server = new LdapServer(1389, new MyServer())) { // ... } }
-
-
Field Summary
Fields Modifier and Type Field Description static Option<Boolean>
BLOCKING_WRITE
Specify whether the response should be written synchronously.static Option<Integer>
BUFFER_SIZE
Size of the buffer used when reading/writing data from/to the network.static Option<Integer>
CONNECT_MAX_BACKLOG
Specifies the maximum queue length for incoming connections requests.static Option<DecodeOptions>
DECODE_OPTIONS
Sets the decoding options which will be used to control how requests and responses are decoded.static Option<Integer>
MAX_CONCURRENT_REQUESTS
Specifies the maximum number of concurrent requests per connection.static Option<IntConsumer>
PROBE_BYTES_READ
Callback invoked each time this server read bytes from the network.static Option<IntConsumer>
PROBE_BYTES_WRITTEN
Callback invoked each time this server write bytes to the network.static Option<Integer>
REQUEST_MAX_SIZE_IN_BYTES
Specifies the maximum request size in bytes for incoming LDAP requests.static Option<Integer>
SELECTOR_THREAD_COUNT
Specifies the number of threads which will be used to handle incoming network events.static Option<String>
SELECTOR_THREAD_NAME
Specifies the thread name used for selector threads.static Option<Boolean>
SO_KEEPALIVE
Specifies the value of theSO_KEEPALIVE
socket option for new connections.static Option<Integer>
SO_LINGER_IN_SECONDS
Specifies the value of theSO_LINGER
socket option for new connections.static Option<Boolean>
SO_REUSE_ADDRESS
Specifies the value of theSO_REUSEADDR
socket option for new connections.static Option<SslOptions>
SSL_OPTIONS
Specifies the options to use for the SSL support ornull
if SSL is disabled.static Option<Boolean>
TCP_NO_DELAY
Specifies the value of theTCP_NODELAY
socket option for new connections.static Option<String>
TRANSPORT_PROVIDER
Specifies the name of the provider to use for transport.static Option<ClassLoader>
TRANSPORT_PROVIDER_CLASS_LOADER
Specifies the class loader which will be used to load theTransportProvider
.static Option<Long>
WRITE_TIMEOUT_MS
Maximum time allowed for write operations to complete.
-
Constructor Summary
Constructors Constructor Description LdapServer(int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory)
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.LdapServer(int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory, Options options)
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.LdapServer(String host, int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory)
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.LdapServer(String host, int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory, Options options)
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.LdapServer(Set<InetSocketAddress> addresses, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory)
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.LdapServer(Set<InetSocketAddress> addresses, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory, Options options)
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this LDAP connection listener.InetSocketAddress
firstSocketAddress()
Returns the first address that his LDAP listener is listening on.Options
getOptions()
Returns a copy of the options currently used by this LDAP listener.String
getProviderName()
Returns the name of the transport provider, which provides the implementation of this factory.Set<InetSocketAddress>
getSocketAddresses()
Returns the addresses that this LDAP listener is listening on.boolean
setOptions(Options options)
Updates the options of this LDAP listener.String
toString()
-
-
-
Field Detail
-
CONNECT_MAX_BACKLOG
public static final Option<Integer> CONNECT_MAX_BACKLOG
Specifies the maximum queue length for incoming connections requests. If a connection request arrives when the queue is full, the connection is refused.
-
BLOCKING_WRITE
public static final Option<Boolean> BLOCKING_WRITE
Specify whether the response should be written synchronously.
-
BUFFER_SIZE
public static final Option<Integer> BUFFER_SIZE
Size of the buffer used when reading/writing data from/to the network.
-
WRITE_TIMEOUT_MS
public static final Option<Long> WRITE_TIMEOUT_MS
Maximum time allowed for write operations to complete.
-
SELECTOR_THREAD_COUNT
public static final Option<Integer> SELECTOR_THREAD_COUNT
Specifies the number of threads which will be used to handle incoming network events.
-
SELECTOR_THREAD_NAME
public static final Option<String> SELECTOR_THREAD_NAME
Specifies the thread name used for selector threads.
-
REQUEST_MAX_SIZE_IN_BYTES
public static final Option<Integer> REQUEST_MAX_SIZE_IN_BYTES
Specifies the maximum request size in bytes for incoming LDAP requests. If an incoming request exceeds the limit then the connection will be aborted by the listener. Default value is 5MiB.
-
MAX_CONCURRENT_REQUESTS
public static final Option<Integer> MAX_CONCURRENT_REQUESTS
Specifies the maximum number of concurrent requests per connection. Once this number is reached, back-pressure mechanism will stop reading requests from the connection.
-
TRANSPORT_PROVIDER_CLASS_LOADER
public static final Option<ClassLoader> TRANSPORT_PROVIDER_CLASS_LOADER
Specifies the class loader which will be used to load theTransportProvider
.By default the default class loader will be used.
The transport provider is loaded using
java.util.ServiceLoader
, the JDK service-provider loading facility. The provider must be accessible from the same class loader that was initially queried to locate the configuration file; note that this is not necessarily the class loader from which the file was actually loaded. This method allows to provide a class loader to be used for loading the provider.
-
TRANSPORT_PROVIDER
public static final Option<String> TRANSPORT_PROVIDER
Specifies the name of the provider to use for transport.Transport providers implement
TransportProvider
interface.The name should correspond to the name of an existing provider, as returned by
TransportProvider#getName()
method.
-
TCP_NO_DELAY
public static final Option<Boolean> TCP_NO_DELAY
Specifies the value of theTCP_NODELAY
socket option for new connections.The default setting is
true
and may be configured using theorg.forgerock.opendj.transport.tcpNoDelay
property.
-
SO_REUSE_ADDRESS
public static final Option<Boolean> SO_REUSE_ADDRESS
Specifies the value of theSO_REUSEADDR
socket option for new connections.The default setting is
true
and may be configured using theorg.forgerock.opendj.transport.reuseAddress
property.
-
SO_LINGER_IN_SECONDS
public static final Option<Integer> SO_LINGER_IN_SECONDS
Specifies the value of theSO_LINGER
socket option for new connections.The default setting is
-1
(disabled) and may be configured using theorg.forgerock.opendj.transport.linger
property.
-
SO_KEEPALIVE
public static final Option<Boolean> SO_KEEPALIVE
Specifies the value of theSO_KEEPALIVE
socket option for new connections.The default setting is
true
and may be configured using theorg.forgerock.opendj.transport.keepAlive
property.
-
DECODE_OPTIONS
public static final Option<DecodeOptions> DECODE_OPTIONS
Sets the decoding options which will be used to control how requests and responses are decoded.
-
SSL_OPTIONS
public static final Option<SslOptions> SSL_OPTIONS
Specifies the options to use for the SSL support ornull
if SSL is disabled.
-
PROBE_BYTES_READ
public static final Option<IntConsumer> PROBE_BYTES_READ
Callback invoked each time this server read bytes from the network. Must be thread-safe.
-
PROBE_BYTES_WRITTEN
public static final Option<IntConsumer> PROBE_BYTES_WRITTEN
Callback invoked each time this server write bytes to the network. Must be thread-safe.
-
-
Constructor Detail
-
LdapServer
public LdapServer(int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory) throws IOException
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
port
- The port to listen on.factory
- The handler factory which will be used to create handlers.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- If {code factory} wasnull
.
-
LdapServer
public LdapServer(int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory, Options options) throws IOException
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
port
- The port to listen on.factory
- The handler factory which will be used to create handlers.options
- The LDAP listener options.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- If {code factory} oroptions
wasnull
.
-
LdapServer
public LdapServer(Set<InetSocketAddress> addresses, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory) throws IOException
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
addresses
- The addresses to listen on.factory
- The handler factory which will be used to create handlers.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- Ifaddress
or {code factory} wasnull
.
-
LdapServer
public LdapServer(Set<InetSocketAddress> addresses, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory, Options options) throws IOException
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
addresses
- The addresses to listen on.factory
- The handler factory which will be used to create handlers.options
- The LDAP listener options.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- Ifaddress
, {code factory}, oroptions
wasnull
.
-
LdapServer
public LdapServer(String host, int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory) throws IOException
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
host
- The address to listen on.port
- The port to listen on.factory
- The handler factory which will be used to create handlers.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- Ifhost
or {code factory} wasnull
.
-
LdapServer
public LdapServer(String host, int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory, Options options) throws IOException
Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
host
- The address to listen on.port
- The port to listen on.factory
- The handler factory which will be used to create handlers.options
- The LDAP listener options.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- Ifhost
, {code factory}, oroptions
wasnull
.
-
-
Method Detail
-
setOptions
public boolean setOptions(Options options)
Updates the options of this LDAP listener. Most of the options will be applied only for next client connection, current connections will not impacted by this operation. Some options are not modifiable and will be ignored by this operation.- Parameters:
options
- The LDAP listener options.- Returns:
true
if some or all options have been applied,false
if options cannot be changed.
-
getOptions
public Options getOptions()
Returns a copy of the options currently used by this LDAP listener. Modifying the returned Options will have not impact until applied withsetOptions(Options)
.- Returns:
- The LDAP listener options.
-
close
public void close()
Closes this LDAP connection listener.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getSocketAddresses
public Set<InetSocketAddress> getSocketAddresses()
Returns the addresses that this LDAP listener is listening on.- Returns:
- The addresses that this LDAP listener is listening on.
-
firstSocketAddress
public InetSocketAddress firstSocketAddress()
Returns the first address that his LDAP listener is listening on.- Returns:
- The addresses that this LDAP listener is listening on.
-
getProviderName
public String getProviderName()
Returns the name of the transport provider, which provides the implementation of this factory.- Returns:
- The name of actual transport provider.
-
-