Package netscape.ldap

Class LDAPConnThread

java.lang.Object
netscape.ldap.LDAPConnThread
All Implemented Interfaces:
Runnable

class LDAPConnThread extends Object implements 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 Details

    • logger

      public static org.slf4j.Logger logger
    • MAXMSGID

      private static final int MAXMSGID
      Constants
      See Also:
    • BACKLOG_CHKCNT

      private static final int BACKLOG_CHKCNT
      See Also:
    • m_highMsgId

      private static transient int m_highMsgId
      Internal variables
    • m_serverInput

      private transient InputStream m_serverInput
    • m_origServerInput

      private transient InputStream m_origServerInput
    • m_serverOutput

      private transient OutputStream m_serverOutput
    • m_origServerOutput

      private transient OutputStream m_origServerOutput
    • m_requests

      private transient Hashtable<Integer,LDAPMessageQueue> m_requests
    • m_messages

      private transient Hashtable<Integer,Vector<Object>> m_messages
    • m_registered

      private transient Vector<LDAPConnection> m_registered
    • m_cache

      private transient LDAPCache m_cache
    • m_thread

      private transient Thread m_thread
    • m_sendRequestLock

      private transient Object m_sendRequestLock
    • m_connMgr

      private transient LDAPConnSetupMgr m_connMgr
    • m_traceOutput

      private transient Object m_traceOutput
    • m_backlogCheckCounter

      private transient int m_backlogCheckCounter
    • m_bound

      private transient boolean m_bound
    • m_nextId

      private static transient int m_nextId
      Connection IDs for ldap trace messages
    • m_id

      private transient int m_id
    • m_timeFormat

      static SimpleDateFormat m_timeFormat
  • Constructor Details

    • LDAPConnThread

      public LDAPConnThread(LDAPConnSetupMgr connMgr, LDAPCache cache, Object traceOutput)
      Constructs a connection thread that maintains connection to the LDAP server.
      Parameters:
      connMgr - the connection setup manager
      cache - cache object or null
      traceOutput - trace object or null
  • Method Details

    • connect

      void connect(LDAPConnection ldc) throws LDAPException
      Throws:
      LDAPException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • layerSocket

      void layerSocket(LDAPTLSSocketFactory factory) throws Exception
      Layer a SSL socket over the current non-SSL one
      Throws:
      Exception
    • setBound

      void setBound(boolean bound)
    • isBound

      boolean isBound()
    • getInputStream

      InputStream getInputStream()
    • setInputStream

      void setInputStream(InputStream is)
    • getOutputStream

      OutputStream getOutputStream()
    • setOutputStream

      void setOutputStream(OutputStream os)
    • getRequestCount

      int getRequestCount()
    • setTraceOutput

      void setTraceOutput(Object traceOutput)
    • logTraceMessage

      void logTraceMessage(StringBuffer msg)
    • setCache

      void setCache(LDAPCache cache)
      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 send
      toNotify - response listener to invoke when the response is ready
      Throws:
      LDAPException
    • sendRequest

      private boolean sendRequest(LDAPMessage msg, boolean ignoreErrors)
    • sendUnbindRequest

      private void sendUnbindRequest(LDAPControl[] ctrls)
    • sendAbandonRequest

      private void sendAbandonRequest(int id, LDAPControl[] ctrls)
    • register

      public void register(LDAPConnection conn)
      Register with this connection thread.
      Parameters:
      conn - LDAP connection
    • getClientCount

      int getClientCount()
    • isConnected

      boolean isConnected()
    • deregister

      void deregister(LDAPConnection conn)
      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

      private void cleanUp(LDAPException ex)
      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

      private void checkBacklog() throws InterruptedException
      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.
      Specified by:
      run in interface Runnable
    • processResponse

      private void processResponse(LDAPMessage msg, int size)
      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

      private void cacheSearchResult(LDAPSearchListener l, LDAPMessage msg, int size)
      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

      void abandon(int id, LDAPControl[] ctrls)
      Stop dispatching responses for a particular message ID and send the abandon request.
      Parameters:
      id - Message ID for which to discard responses.
    • changeListener

      LDAPMessageQueue changeListener(int id, LDAPMessageQueue toNotify)
      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

      private void networkError(Exception e)
      Handles network errors. Basically shuts down the whole connection.
      Parameters:
      e - The exception which was caught while trying to read from input stream.