com.sun.slamd.example
Class SLAMDLDAPSocketFactory

java.lang.Object
  extended by com.sun.slamd.example.SLAMDLDAPSocketFactory
All Implemented Interfaces:
netscape.ldap.LDAPSocketFactory

public class SLAMDLDAPSocketFactory
extends java.lang.Object
implements netscape.ldap.LDAPSocketFactory

This class provides a simple LDAP socket factory that creates plain sockets that are well-suited for LDAP performance and benchmarking. In particular, it sets the TCP_NODELAY option to ensure that requests packets are sent as quickly as possible, and it uses the SO_LINGER and SO_REUSEADDR options to be well-suited for lots of short-lived connections.

Author:
Neil A. Wilson

Constructor Summary
SLAMDLDAPSocketFactory()
          Creates a new instance of this LDAP socket factory with the default settings.
SLAMDLDAPSocketFactory(boolean setKeepAlive, boolean setLinger, boolean setReuseAddress, boolean setTCPNoDelay)
          Creates a new instance of this LDAP socket factory with the provided settings.
 
Method Summary
 int getConnectTimeout()
          Retrieves the maximum length of time in milliseconds to wait while attempting to connect before giving up.
 boolean getKeepAlive()
          Indicates whether the SO_KEEPALIVE socket option should be used for new connections.
 boolean getLinger()
          Indicates whether the SO_LINGER socket option should be used for new connections.
 boolean getReuseAddress()
          Indicates whether the SO_REUSEADDR socket option should be used for new connections.
 boolean getTCPNoDelay()
          Indicates whether the TCP_NODELAY socket option should be used for new connections.
 java.net.Socket makeSocket(java.lang.String host, int port)
          Establishes a socket to the provided host and port with the specified settings that can be used by the LDAP SDK for Java.
 void setConnectTimeout(int connectTimeout)
          Specifies the maximum length of time in milliseconds to wait while attempting to connect before giving up.
 void setKeepAlive(boolean setKeepAlive)
          Specifies whether to use the SO_KEEPALIVE socket option.
 void setLinger(boolean setLinger)
          Specifies whether to use the SO_LINGER socket option.
 void setReuseAddress(boolean setReuseAddress)
          Specifies whether to use the SO_REUSEADDR socket option.
 void setTCPNoDelay(boolean setTCPNoDelay)
          Specifies whether to use the TCP_NODELAY socket option.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SLAMDLDAPSocketFactory

public SLAMDLDAPSocketFactory()
Creates a new instance of this LDAP socket factory with the default settings. The keepalive, linger, reuse address, and TCP nodelay socket options will all be enabled.


SLAMDLDAPSocketFactory

public SLAMDLDAPSocketFactory(boolean setKeepAlive,
                              boolean setLinger,
                              boolean setReuseAddress,
                              boolean setTCPNoDelay)
Creates a new instance of this LDAP socket factory with the provided settings.

Parameters:
setKeepAlive - Inkdicates whether to use the SO_KEEPALIVE socket option.
setLinger - Indicates whether to use the SO_LINGER socket option.
setReuseAddress - Indicates whether to use the SO_REUSEADDR socket option.
setTCPNoDelay - Indicates whether to use the TCP_NODELAY socket option.
Method Detail

getKeepAlive

public boolean getKeepAlive()
Indicates whether the SO_KEEPALIVE socket option should be used for new connections.

Returns:
true if the SO_KEEPALIVE socket option should be used, or false if not.

setKeepAlive

public void setKeepAlive(boolean setKeepAlive)
Specifies whether to use the SO_KEEPALIVE socket option.

Parameters:
setKeepAlive - Specifies whether to use the SO_KEEPALIVE socket option.

getLinger

public boolean getLinger()
Indicates whether the SO_LINGER socket option should be used for new connections.

Returns:
true if the SO_LINGER socket option should be used, or false if not.

setLinger

public void setLinger(boolean setLinger)
Specifies whether to use the SO_LINGER socket option.

Parameters:
setLinger - Specifies whether to use the SO_LINGER socket option.

getReuseAddress

public boolean getReuseAddress()
Indicates whether the SO_REUSEADDR socket option should be used for new connections.

Returns:
true if the SO_REUSEADDR socket option should be used, or false if not.

setReuseAddress

public void setReuseAddress(boolean setReuseAddress)
Specifies whether to use the SO_REUSEADDR socket option.

Parameters:
setReuseAddress - Specifies whether to use the SO_REUSEADDR socket option.

getTCPNoDelay

public boolean getTCPNoDelay()
Indicates whether the TCP_NODELAY socket option should be used for new connections.

Returns:
true if the TCP_NODELAY socket option should be used, or false if not.

setTCPNoDelay

public void setTCPNoDelay(boolean setTCPNoDelay)
Specifies whether to use the TCP_NODELAY socket option.

Parameters:
setTCPNoDelay - Specifies whether to use the TCP_NODELAY socket option.

getConnectTimeout

public int getConnectTimeout()
Retrieves the maximum length of time in milliseconds to wait while attempting to connect before giving up.

Returns:
The maximum length of time in milliseconds to wait while attempting to connect before giving up.

setConnectTimeout

public void setConnectTimeout(int connectTimeout)
Specifies the maximum length of time in milliseconds to wait while attempting to connect before giving up.

Parameters:
connectTimeout - The maximum length of time in milliseconds to wait while attempting to connect before giving up.

makeSocket

public java.net.Socket makeSocket(java.lang.String host,
                                  int port)
                           throws netscape.ldap.LDAPException
Establishes a socket to the provided host and port with the specified settings that can be used by the LDAP SDK for Java.

Specified by:
makeSocket in interface netscape.ldap.LDAPSocketFactory
Parameters:
host - The address of the server to which the connection is to be established.
port - The port number of the server to which the connection is to be established.
Returns:
The socket that may be used for communicating with the directory server.
Throws:
netscape.ldap.LDAPException - If a problem occurs while trying to establish the connection.