public final class LdapServer extends Object implements Closeable
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 the requestID
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, an LdapServer
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())) { // ... } }
Modifier and Type | Field and 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 the
SO_KEEPALIVE socket option for new connections. |
static Option<Integer> |
SO_LINGER_IN_SECONDS
Specifies the value of the
SO_LINGER socket option for new connections. |
static Option<Boolean> |
SO_REUSE_ADDRESS
Specifies the value of the
SO_REUSEADDR socket option for new connections. |
static Option<SslOptions> |
SSL_OPTIONS
Specifies the options to use for the SSL support or
null if SSL is disabled. |
static Option<Boolean> |
TCP_NO_DELAY
Specifies the value of the
TCP_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 the
TransportProvider . |
static Option<Long> |
WRITE_TIMEOUT_MS
Maximum time allowed for write operations to complete.
|
Constructor and 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(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.
|
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.
|
Modifier and Type | Method and 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() |
public static final Option<Integer> CONNECT_MAX_BACKLOG
public static final Option<Boolean> BLOCKING_WRITE
public static final Option<Integer> BUFFER_SIZE
public static final Option<Long> WRITE_TIMEOUT_MS
public static final Option<Integer> SELECTOR_THREAD_COUNT
public static final Option<String> SELECTOR_THREAD_NAME
public static final Option<Integer> REQUEST_MAX_SIZE_IN_BYTES
public static final Option<Integer> MAX_CONCURRENT_REQUESTS
public static final Option<ClassLoader> TRANSPORT_PROVIDER_CLASS_LOADER
TransportProvider
.
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.
public static final Option<String> TRANSPORT_PROVIDER
Transport providers implement TransportProvider
interface.
The name should correspond to the name of an existing provider, as
returned by TransportProvider#getName()
method.
public static final Option<Boolean> TCP_NO_DELAY
TCP_NODELAY
socket option for new connections.
The default setting is true
and may be configured using the
org.forgerock.opendj.transport.tcpNoDelay
property.
public static final Option<Boolean> SO_REUSE_ADDRESS
SO_REUSEADDR
socket option for new connections.
The default setting is true
and may be configured using the
org.forgerock.opendj.transport.reuseAddress
property.
public static final Option<Integer> SO_LINGER_IN_SECONDS
SO_LINGER
socket option for new connections.
The default setting is -1
(disabled) and may be configured using
the org.forgerock.opendj.transport.linger
property.
public static final Option<Boolean> SO_KEEPALIVE
SO_KEEPALIVE
socket option for new connections.
The default setting is true
and may be configured using the
org.forgerock.opendj.transport.keepAlive
property.
public static final Option<DecodeOptions> DECODE_OPTIONS
public static final Option<SslOptions> SSL_OPTIONS
null
if SSL is disabled.public static final Option<IntConsumer> PROBE_BYTES_READ
public static final Option<IntConsumer> PROBE_BYTES_WRITTEN
public LdapServer(int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory) throws IOException
port
- The port to listen on.factory
- The handler factory which will be used to create handlers.IOException
- If an error occurred while trying to listen on the provided
address.NullPointerException
- If {code factory} was null
.public LdapServer(int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory, Options options) throws IOException
port
- The port to listen on.factory
- The handler factory which will be used to create handlers.options
- The LDAP listener options.IOException
- If an error occurred while trying to listen on the provided
address.NullPointerException
- If {code factory} or options
was null
.public LdapServer(Set<InetSocketAddress> addresses, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory) throws IOException
addresses
- The addresses to listen on.factory
- The handler factory which will be used to create handlers.IOException
- If an error occurred while trying to listen on the provided
address.NullPointerException
- If address
or {code factory} was null
.public LdapServer(Set<InetSocketAddress> addresses, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory, Options options) throws IOException
addresses
- The addresses to listen on.factory
- The handler factory which will be used to create handlers.options
- The LDAP listener options.IOException
- If an error occurred while trying to listen on the provided
address.NullPointerException
- If address
, {code factory}, or options
was
null
.public LdapServer(String host, int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory) throws IOException
host
- The address to listen on.port
- The port to listen on.factory
- The handler factory which will be used to create handlers.IOException
- If an error occurred while trying to listen on the provided
address.NullPointerException
- If host
or {code factory} was null
.public LdapServer(String host, int port, Function<LdapSession,BiFunction<Integer,Request,Flowable<Response>>> factory, Options options) throws IOException
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.IOException
- If an error occurred while trying to listen on the provided
address.NullPointerException
- If host
, {code factory}, or options
was
null
.public boolean setOptions(Options options)
options
- The LDAP listener options.true
if some or all options have been applied, false
if options cannot be changed.public Options getOptions()
setOptions(Options)
.public void close()
close
in interface Closeable
close
in interface AutoCloseable
public Set<InetSocketAddress> getSocketAddresses()
public InetSocketAddress firstSocketAddress()
public String getProviderName()
Copyright 2010-2022 ForgeRock AS.