Package netscape.ldap
Class LDAPConnThread
java.lang.Object
netscape.ldap.LDAPConnThread
- All Implemented Interfaces:
Runnable
Multiple LDAPConnection clones can share a single physical connection,
which is maintained by a thread.
+----------------+
| LDAPConnection | --------+
+----------------+ |
|
+----------------+ | +----------------+
| LDAPConnection | --------+------- | LDAPConnThread |
+----------------+ | +----------------+
|
+----------------+ |
| LDAPConnection | --------+
+----------------+
All LDAPConnections send requests and get responses from
LDAPConnThread (a thread).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
static org.slf4j.Logger
private int
private boolean
private LDAPCache
private LDAPConnSetupMgr
private static int
Internal variablesprivate int
private static int
Connection IDs for ldap trace messagesprivate InputStream
private OutputStream
private Vector<LDAPConnection>
private Hashtable<Integer,
LDAPMessageQueue> private Object
private InputStream
private OutputStream
private Thread
(package private) static SimpleDateFormat
private Object
private static final int
Constants -
Constructor Summary
ConstructorsConstructorDescriptionLDAPConnThread
(LDAPConnSetupMgr connMgr, LDAPCache cache, Object traceOutput) Constructs a connection thread that maintains connection to the LDAP server. -
Method Summary
Modifier and TypeMethodDescription(package private) void
abandon
(int id, LDAPControl[] ctrls) Stop dispatching responses for a particular message ID and send the abandon request.private int
Allocates a new LDAP message ID.private void
cacheSearchResult
(LDAPSearchListener l, LDAPMessage msg, int size) Collect search results to be added to the LDAPCache.private void
(package private) LDAPMessageQueue
changeListener
(int id, LDAPMessageQueue toNotify) Change listener for a message ID.private void
Sleep if there is a backlog of search resultsprivate void
cleanUp
(LDAPException ex) Clean up after the thread shutdown.void
close()
(package private) void
connect
(LDAPConnection ldc) (package private) void
deregister
(LDAPConnection conn) De-Register with this connection thread.(package private) int
(package private) InputStream
(package private) OutputStream
(package private) int
(package private) boolean
isBound()
(package private) boolean
(package private) void
layerSocket
(LDAPTLSSocketFactory factory) Layer a SSL socket over the current non-SSL one(package private) void
private void
Handles network errors.private void
processResponse
(LDAPMessage msg, int size) When a response arrives from the LDAP server, it is processed by this routine.void
register
(LDAPConnection conn) Register with this connection thread.(package private) void
This is called when a search result has been retrieved from the incoming queue.void
run()
Reads from the LDAP server input stream for incoming LDAP messages.private void
sendAbandonRequest
(int id, LDAPControl[] ctrls) (package private) void
sendRequest
(LDAPConnection conn, JDAPProtocolOp request, LDAPMessageQueue toNotify, LDAPConstraints cons) Sends LDAP request via this connection thread.private boolean
sendRequest
(LDAPMessage msg, boolean ignoreErrors) private void
sendUnbindRequest
(LDAPControl[] ctrls) (package private) void
setBound
(boolean bound) (package private) void
Set the cache to use for searches.(package private) void
(package private) void
(package private) void
setTraceOutput
(Object traceOutput) toString()
-
Field Details
-
logger
public static org.slf4j.Logger logger -
MAXMSGID
private static final int MAXMSGIDConstants- See Also:
-
BACKLOG_CHKCNT
private static final int BACKLOG_CHKCNT- See Also:
-
m_highMsgId
private static transient int m_highMsgIdInternal variables -
m_serverInput
-
m_origServerInput
-
m_serverOutput
-
m_origServerOutput
-
m_requests
-
m_messages
-
m_registered
-
m_cache
-
m_thread
-
m_sendRequestLock
-
m_connMgr
-
m_traceOutput
-
m_backlogCheckCounter
private transient int m_backlogCheckCounter -
m_bound
private transient boolean m_bound -
m_nextId
private static transient int m_nextIdConnection IDs for ldap trace messages -
m_id
private transient int m_id -
m_timeFormat
-
-
Constructor Details
-
LDAPConnThread
Constructs a connection thread that maintains connection to the LDAP server.- Parameters:
connMgr
- the connection setup managercache
- cache object or nulltraceOutput
- trace object or null
-
-
Method Details
-
connect
- Throws:
LDAPException
-
toString
-
layerSocket
Layer a SSL socket over the current non-SSL one- Throws:
Exception
-
setBound
void setBound(boolean bound) -
isBound
boolean isBound() -
getInputStream
InputStream getInputStream() -
setInputStream
-
getOutputStream
OutputStream getOutputStream() -
setOutputStream
-
getRequestCount
int getRequestCount() -
setTraceOutput
-
logTraceMessage
-
setCache
Set the cache to use for searches.- Parameters:
cache
- The cache to use for searches;null
for no cache
-
allocateId
private int allocateId()Allocates a new LDAP message ID. These are arbitrary numbers used to correlate client requests with server responses.- Returns:
- new unique msgId
-
sendRequest
void sendRequest(LDAPConnection conn, JDAPProtocolOp request, LDAPMessageQueue toNotify, LDAPConstraints cons) throws LDAPException Sends LDAP request via this connection thread.- Parameters:
request
- request to sendtoNotify
- response listener to invoke when the response is ready- Throws:
LDAPException
-
sendRequest
-
sendUnbindRequest
-
sendAbandonRequest
-
register
Register with this connection thread.- Parameters:
conn
- LDAP connection
-
getClientCount
int getClientCount() -
isConnected
boolean isConnected() -
deregister
De-Register with this connection thread. If all the connection is deregistered. Then, this thread should be killed.- Parameters:
conn
- LDAP connection
-
close
public void close() -
cleanUp
Clean up after the thread shutdown. The list of registered clients m_registered is left in the current state to enable the clients to recover the connection. -
checkBacklog
Sleep if there is a backlog of search results- Throws:
InterruptedException
-
resultRetrieved
void resultRetrieved()This is called when a search result has been retrieved from the incoming queue. We use the notification to unblock the listener thread, if it is waiting for the backlog to lighten. -
run
public void run()Reads from the LDAP server input stream for incoming LDAP messages. -
processResponse
When a response arrives from the LDAP server, it is processed by this routine. It will pass the message on to the listening object associated with the LDAP msgId.- Parameters:
msg
- New message from LDAP server
-
changeIOStreams
private void changeIOStreams() -
cacheSearchResult
Collect search results to be added to the LDAPCache. Search results are packaged in a vector and temporary stored into a hashtable m_messages using the message id as the key. The vector first element (at index 0) is a Long integer representing the total size of all LDAPEntries entries. It is followed by the actual LDAPEntries. If the total size of entries exceeds the LDAPCache max size, or a referral has been received, caching of search results is disabled and the entry is not added to the LDAPCache. A disabled search request is denoted by setting the entry size to -1. -
abandon
Stop dispatching responses for a particular message ID and send the abandon request.- Parameters:
id
- Message ID for which to discard responses.
-
changeListener
Change listener for a message ID. Required when LDAPMessageQueue.merge() is invoked.- Parameters:
id
- Message ID for which to chanage the listener.- Returns:
- Previous listener.
-
networkError
Handles network errors. Basically shuts down the whole connection.- Parameters:
e
- The exception which was caught while trying to read from input stream.
-