LDAPSearchListener.java revision c9b9c9d7d9ab568bd89af593dd6ac6ba933f23be
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* Portions Copyrighted 2012-2015 ForgeRock AS.
*/
/**
* Manages search results, references and responses returned on one or
* more search requests
* @deprecated As of ForgeRock OpenAM 10.
*/
public class LDAPSearchListener extends LDAPMessageQueue {
static final long serialVersionUID = -7163312406176592277L;
class ExtendedRequestEntry extends RequestEntry {
boolean gotFirstMessage;
boolean completed;
gotFirstMessage = false;
completed = false;
}
}
// this instance variable is only for cache purpose
private LDAPSearchConstraints m_constraints;
protected boolean notified;
protected boolean hasListener;
private ExtendedRequestEntry currentWaitRequest;
/**
* Constructs a LDAP search listener.
* @param asynchOp a boolean flag indicating whether the object is used
* for asynchronous LDAP operations
* @param cons LDAP search constraints
* @see com.sun.identity.shared.ldap.LDAPAsynchronousConnection
*/
super ( asynchOp );
m_messageQueue = new Vector();
if (asynchOp) {
m_requestList = new Hashtable();
}
this.notified = false;
this.hasListener = false;
}
synchronized (this) {
if (m_asynchOp) {
if (hasListener) {
notified = true;
notify();
}
}
} else {
reset();
}
}
}
synchronized (this) {
if (m_asynchOp) {
synchronized (m_requestList) {
request.gotFirstMessage = true;
if (msg.getMessageType() ==
}
if (hasListener) {
notified = true;
notify();
}
}
}
} else {
if ((currentWaitRequest != null) &&
currentWaitRequest.gotFirstMessage = true;
if (msg.getMessageType() ==
currentWaitRequest.completed = true;
}
if (hasListener) {
notified = true;
notify();
}
}
}
}
}
if (m_asynchOp) {
synchronized (m_requestList) {
}
}
}
} else {
synchronized (this) {
if (currentWaitRequest != null) {
}
}
}
}
protected boolean removeRequest(int msgId) {
synchronized (this) {
if (m_asynchOp) {
!= null) {
}
}
if (currentWaitRequest == entry) {
if (hasListener) {
notified = true;
notify();
}
}
return true;
}
} else {
msgId)){
reset();
return true;
}
}
}
return false;
}
int removeCount=0;
boolean needToNotify = false;
synchronized (this) {
if (m_asynchOp) {
synchronized (m_requestList) {
removeCount++;
if (currentWaitRequest == entry) {
needToNotify = true;
}
}
}
}
}
}
if (needToNotify) {
if (hasListener) {
notified = true;
notify();
}
}
} else {
if ((currentWaitRequest != null) &&
reset();
}
}
}
return removeCount;
}
public int getMessageCount() {
synchronized (this) {
return m_messageQueue.size();
}
}
synchronized (this) {
if (!hasListener) {
hasListener = true;
if (m_asynchOp) {
(m_exception == null)) {
}
} else {
while ((currentWaitRequest != null) &&
(m_exception == null)) {
}
}
hasListener = false;
// Network exception occurred ?
if (m_exception != null) {
m_exception = null;
throw ex;
}
} else {
throw new LDAPException(
"Time to complete operation exceeded",
}
}
}
try {
if (timeToWait > 0) {
if (notified) {
notified = false;
// Spurious wakeup before timeout
return;
} else {
}
} else {
}
} else {
wait();
notified = false;
}
} catch (InterruptedException e) {
} catch (Exception e) {
}
}
/**
* Block until all results are in. Used for synchronous search with
* batch size of zero.
* @return search response message.
* @exception Network exception error
*/
synchronized (this) {
if (!m_asynchOp) {
if (!hasListener) {
hasListener = true;
&& (!currentWaitRequest.completed)) {
}
// Network exception occurred ?
if (m_exception != null) {
m_exception = null;
hasListener = false;
throw ex;
}
if (currentWaitRequest == null) {
hasListener = false;
throw new LDAPException("Invalid response",
}
hasListener = false;
return tempMessages;
} else {
throw new LDAPException(
"Time to complete operation exceeded",
}
} else {
throw new LDAPException(
"Time to complete operation exceeded",
}
}
}
synchronized (this) {
if (!hasListener) {
hasListener = true;
if (m_asynchOp) {
&& m_messageQueue.isEmpty()) {
if (currentWaitRequest == null) {
synchronized (m_requestList) {
if ((currentWaitRequest == null) ||
}
}
}
}
}
} else {
&& m_messageQueue.isEmpty()) {
}
}
hasListener = false;
if (m_exception != null) {
m_exception = null;
throw ex;
}
if (m_asynchOp) {
if (m_requestList.isEmpty()) {
throw new LDAPException("Invalid response",
}
} else {
if (currentWaitRequest == null) {
throw new LDAPException("Invalid response",
}
}
if (tempResponse.getMessageType() ==
}
} else {
throw new LDAPException(
"Time to complete operation exceeded",
}
}
return tempResponse;
}
public int getType() {
return LDAPMessageQueue.LDAP_SEARCH_LISTENER;
}
/**
* Returns message IDs for all outstanding requests
* @return message ID array.
*/
public int[] getMessageIDs() {
if (m_asynchOp) {
synchronized (m_requestList) {
int i = 0;
i++;
}
}
} else {
synchronized (this) {
if (currentWaitRequest != null) {
ids = new int[1];
}
}
}
return ids;
}
// Yield just in case the LDAPConnThread is in the process of
// dispatching a message
synchronized (LDAPSearchListener.class) {
synchronized(this) {
synchronized (mq2) {
}
}
synchronized (mq2.m_requestList) {
}
}
}
if (hasListener) {
notified = true;
notify();
}
}
}
} else {
throw new LDAPException();
}
}
/**
* Return the search constraints used to create this object.
* @return the search constraints used to create this object.
*/
return m_constraints;
}
/**
* Set new search constraints object.
* @param cons LDAP search constraints
*/
}
/**
* Resets the state of this object, so it can be recycled.
* Used by LDAPConnection synchronous operations.
*/
protected void reset() {
synchronized (this) {
m_exception = null;
if (m_asynchOp) {
}
if (hasListener) {
notified = true;
notify();
}
}
}
/**
* Set the key of the cache entry. The listener needs to know this value
* when the results get processed in the queue. After the results have been
* saved in the vector, then the key and a vector of results are put in
* the cache.
* @param key the key of the cache entry
*/
}
/**
* Get the key of the cache entry.
* @return the key of the cache entry.
*/
return m_key;
}
}