Package netscape.ldap
Class LDAPMessageQueue
java.lang.Object
netscape.ldap.LDAPMessageQueue
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
LDAPResponseListener
,LDAPSearchListener
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Request entry encapsulates request parameters -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private LDAPException
private Vector
<LDAPMessage> Internal variablesprivate Vector
<LDAPMessageQueue.RequestEntry> private boolean
(package private) static final long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
addMessage
(LDAPMessage msg) Queues the LDAP server's response.(package private) void
addRequest
(int id, LDAPConnection connection, LDAPConnThread connThread, int timeLimit) Registers a LDAP request(package private) LDAPResponse
Wait for request to complete.(package private) Vector
<LDAPMessage> Retrieves all messages currently in the queue without blocking(package private) LDAPConnection
getConnection
(int id) Returns the connection associated with the specified request id(package private) LDAPConnThread
getConnThread
(int id) Returns the connection thread associated with the specified request idint
Returns the count of queued messages(package private) int
Returns message ID of the last request(package private) int[]
Returns a list of message IDs for all outstanding requestsint
Returns the number of outstanding requests.(package private) boolean
Returns a flag whether the listener is used for asynchronous LDAP operations(package private) boolean
Checks if response message is received.(package private) void
merge
(LDAPMessageQueue mq2) Merge two message queues.(package private) LDAPMessage
Blocks until a response is available or until all operations associated with the object have completed or been canceled.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()(package private) int
removeAllRequests
(LDAPConnThread connThread) Remove all requests associated with the specified connThread Called when a connThread has a network error(package private) 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)(package private) void
reset()
Resets the state of this object, so it can be recycled.(package private) void
setException
(LDAPConnThread connThread, LDAPException e) Signals that a network exception occured while servicing the request.toString()
String representation of the object(package private) void
Blocks until a response is available.private void
Wait for a response message.
-
Field Details
-
serialVersionUID
static final long serialVersionUID- See Also:
-
m_messageQueue
Internal variables -
m_requestList
-
m_exception
-
m_asynchOp
private boolean m_asynchOp -
m_timeConstrained
private boolean m_timeConstrained
-
-
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
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 exceptionLDAPInterruptedException
- The invoking thread was interrupted
-
nextMessage
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 exceptionLDAPInterruptedException
- The invoking thread was interrupted
-
completeRequest
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 exceptionLDAPInterruptedException
- The invoking thread was interrupted
-
waitForMessage
Wait for a response message. Process interrupts and honor time limit if set for any request- Throws:
LDAPException
-
merge
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
Queues the LDAP server's response. This causes anyone waiting in nextMessage() to unblock.- Parameters:
msg
- response message
-
setException
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 occurrede
- 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
Returns the connection associated with the specified request id- Parameters:
id
- request id- Returns:
- connection.
-
getConnThread
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
Registers a LDAP request- Parameters:
id
- LDAP request message IDconnection
- LDAP Connection for the message IDconnThread
- a physical connection to the servertimeLimit
- 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
Remove all requests associated with the specified connThread Called when a connThread has a network error- Returns:
- number of removed requests.
-
toString
String representation of the object
-