Package netscape.ldap

Class LDAPMessageQueue

java.lang.Object
netscape.ldap.LDAPMessageQueue
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
LDAPResponseListener, LDAPSearchListener

class LDAPMessageQueue extends Object implements Serializable
A queue of response messsages from the server. Multiple requests can be multiplexed on the same queue. For synchronous LDAPConnection requests, there will be only one request per queue. For asynchronous LDAPConnection requests, the user can add multiple request to the same queue. Superclass for LDAResponseListener and LDAPSearchListener
  • Field Details

  • Constructor Details

    • LDAPMessageQueue

      LDAPMessageQueue(boolean asynchOp)
      Constructor
      Parameters:
      asynchOp - a boolean flag that is true if the object is used for asynchronous LDAP operations
      See Also:
  • Method Details

    • isAsynchOp

      boolean isAsynchOp()
      Returns a flag whether the listener is used for asynchronous LDAP operations
      Returns:
      asynchronous operation flag.
      See Also:
    • waitFirstMessage

      void waitFirstMessage() throws LDAPException
      Blocks until a response is available. Used by LDAPConnection.sendRequest (synch ops) to test if the server is really available after a request had been sent.
      Throws:
      LDAPException - Network error exception
      LDAPInterruptedException - The invoking thread was interrupted
    • nextMessage

      LDAPMessage nextMessage() throws LDAPException
      Blocks until a response is available or until all operations associated with the object have completed or been canceled.
      Returns:
      LDAP message or null if there are no more outstanding requests.
      Throws:
      LDAPException - Network error exception
      LDAPInterruptedException - The invoking thread was interrupted
    • completeRequest

      LDAPResponse completeRequest() throws LDAPException
      Wait for request to complete. This method blocks until a message of type LDAPResponse has been received. Used by synchronous search with batch size of zero (block until all results are received)
      Returns:
      LDAPResponse message or null if there are no more outstanding requests.
      Throws:
      LDAPException - Network error exception
      LDAPInterruptedException - The invoking thread was interrupted
    • waitForMessage

      private void waitForMessage() throws LDAPException
      Wait for a response message. Process interrupts and honor time limit if set for any request
      Throws:
      LDAPException
    • merge

      void merge(LDAPMessageQueue mq2)
      Merge two message queues. Move/append the content from another message queue to this one. To be used for synchronization of asynchronous LDAP operations where requests are sent by one thread but processed by another one A client may be implemented in such a way that one thread makes LDAP requests and calls l.getMessageIDs(), while another thread is responsible for processing of responses (call l.getResponse()). Both threads are using the same listener objects. In such a case, a race condition may occur, where a LDAP response message is retrieved and the request terminated (request ID removed) before the first thread has a chance to execute l.getMessageIDs(). The proper way to handle this scenario is to create a separate listener for each new request, and after l.getMessageIDs() has been invoked, merge the new request with the existing one.
      Parameters:
      mq2 - message queue to merge with this one
    • getAllMessages

      Vector<LDAPMessage> getAllMessages()
      Retrieves all messages currently in the queue without blocking
      Returns:
      vector of messages.
    • addMessage

      void addMessage(LDAPMessage msg)
      Queues the LDAP server's response. This causes anyone waiting in nextMessage() to unblock.
      Parameters:
      msg - response message
    • setException

      void setException(LDAPConnThread connThread, LDAPException e)
      Signals that a network exception occured while servicing the request. This exception will be throw to any thread waiting in nextMessage()
      Parameters:
      connThread - LDAPConnThread on which the exception occurred
      e - exception
    • isMessageReceived

      boolean isMessageReceived()
      Checks if response message is received.
      Returns:
      true or false.
    • getMessageCount

      public int getMessageCount()
      Returns the count of queued messages
      Returns:
      message count.
    • removeAllMessages

      private int removeAllMessages(int id)
      Remove all queued messages associated with the request ID Called when a LDAP operation is abandoned Not synchronized as its private and can be called only by abandon() and removeAllRequests()
      Returns:
      count of removed messages.
    • reset

      void reset()
      Resets the state of this object, so it can be recycled. Used by LDAPConnection synchronous operations.
      See Also:
    • getConnection

      LDAPConnection getConnection(int id)
      Returns the connection associated with the specified request id
      Parameters:
      id - request id
      Returns:
      connection.
    • getConnThread

      LDAPConnThread getConnThread(int id)
      Returns the connection thread associated with the specified request id
      Parameters:
      id - request id.
      Returns:
      connection thread.
    • getMessageID

      int getMessageID()
      Returns message ID of the last request
      Returns:
      message ID.
    • getMessageIDs

      int[] getMessageIDs()
      Returns a list of message IDs for all outstanding requests
      Returns:
      message ID array.
    • addRequest

      void addRequest(int id, LDAPConnection connection, LDAPConnThread connThread, int timeLimit)
      Registers a LDAP request
      Parameters:
      id - LDAP request message ID
      connection - LDAP Connection for the message ID
      connThread - a physical connection to the server
      timeLimit - the maximum number of milliseconds to wait for the request to complete
    • getRequestCount

      public int getRequestCount()
      Returns the number of outstanding requests.
      Returns:
      outstanding request count.
    • removeRequest

      boolean removeRequest(int id)
      Remove request with the specified ID Called when a LDAP operation is abandoned (called from LDAPConnThread), or terminated (called by nextMessage() when LDAPResponse message is received)
      Returns:
      flag indicating whether the request was removed.
    • removeAllRequests

      int removeAllRequests(LDAPConnThread connThread)
      Remove all requests associated with the specified connThread Called when a connThread has a network error
      Returns:
      number of removed requests.
    • toString

      public String toString()
      String representation of the object
      Overrides:
      toString in class Object