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 intstatic org.slf4j.Loggerprivate intprivate booleanprivate LDAPCacheprivate LDAPConnSetupMgrprivate static intInternal variablesprivate intprivate static intConnection IDs for ldap trace messagesprivate InputStreamprivate OutputStreamprivate Vector<LDAPConnection> private Hashtable<Integer, LDAPMessageQueue> private Objectprivate InputStreamprivate OutputStreamprivate Thread(package private) static SimpleDateFormatprivate Objectprivate static final intConstants -
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) voidabandon(int id, LDAPControl[] ctrls) Stop dispatching responses for a particular message ID and send the abandon request.private intAllocates a new LDAP message ID.private voidcacheSearchResult(LDAPSearchListener l, LDAPMessage msg, int size) Collect search results to be added to the LDAPCache.private void(package private) LDAPMessageQueuechangeListener(int id, LDAPMessageQueue toNotify) Change listener for a message ID.private voidSleep if there is a backlog of search resultsprivate voidcleanUp(LDAPException ex) Clean up after the thread shutdown.voidclose()(package private) voidconnect(LDAPConnection ldc) (package private) voidderegister(LDAPConnection conn) De-Register with this connection thread.(package private) int(package private) InputStream(package private) OutputStream(package private) int(package private) booleanisBound()(package private) boolean(package private) voidlayerSocket(LDAPTLSSocketFactory factory) Layer a SSL socket over the current non-SSL one(package private) voidprivate voidHandles network errors.private voidprocessResponse(LDAPMessage msg, int size) When a response arrives from the LDAP server, it is processed by this routine.voidregister(LDAPConnection conn) Register with this connection thread.(package private) voidThis is called when a search result has been retrieved from the incoming queue.voidrun()Reads from the LDAP server input stream for incoming LDAP messages.private voidsendAbandonRequest(int id, LDAPControl[] ctrls) (package private) voidsendRequest(LDAPConnection conn, JDAPProtocolOp request, LDAPMessageQueue toNotify, LDAPConstraints cons) Sends LDAP request via this connection thread.private booleansendRequest(LDAPMessage msg, boolean ignoreErrors) private voidsendUnbindRequest(LDAPControl[] ctrls) (package private) voidsetBound(boolean bound) (package private) voidSet the cache to use for searches.(package private) void(package private) void(package private) voidsetTraceOutput(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;nullfor 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.
-