You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2008/06/10 03:47:49 UTC

svn commit: r665949 - in /harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap: LdapClient.java LdapContextImpl.java LdapSearchResult.java SearchOp.java

Author: qiuxx
Date: Mon Jun  9 18:47:49 2008
New Revision: 665949

URL: http://svn.apache.org/viewvc?rev=665949&view=rev
Log:
Apply patch for HARMONY-5865, ([classlib][jndi][ldap] - add support for batch reading search results from server)

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java?rev=665949&r1=665948&r2=665949&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java Mon Jun  9 18:47:49 2008
@@ -77,6 +77,8 @@
      */
     private Hashtable<Integer, Element> requests = new Hashtable<Integer, Element>();
 
+    private Hashtable<Integer, Element> batchedSearchRequests = new Hashtable<Integer, Element>();
+
     /**
      * the max time to wait server response in milli-second
      */
@@ -182,6 +184,11 @@
                             // get response operation according messageId
                             Element element = requests.get(Integer
                                     .valueOf(messageId));
+                            if (element == null) {
+                                element = batchedSearchRequests.get(Integer
+                                        .valueOf(messageId));
+                            }
+
                             if (element != null) {
                                 return element.response.getResponseOp();
                             }
@@ -229,20 +236,41 @@
 
             Element element = requests.get(Integer.valueOf(response
                     .getMessageId()));
+            if (element == null
+                    && batchedSearchRequests.contains(Integer.valueOf(response
+                            .getMessageId()))) {
+                element = batchedSearchRequests.get(Integer.valueOf(response
+                        .getMessageId()));
+                // error occurs when read response
+                if (ex != null) {
+                    ((SearchOp) response.getResponseOp()).getSearchResult()
+                            .setException(ex);
+                    batchedSearchRequests.remove(Integer.valueOf(response
+                            .getMessageId()));
+                    return;
+                }
+
+                // wait time out
+                if (element.response.getMessageId() != response.getMessageId()) {
+                    // ldap.31=Read LDAP response message time out
+                    ((SearchOp) response.getResponseOp()).getSearchResult()
+                            .setException(
+                                    new IOException(Messages
+                                            .getString("ldap.31"))); //$NON-NLS-1$);
+                    batchedSearchRequests.remove(Integer.valueOf(response
+                            .getMessageId()));
+                    return;
+                }
 
+            }
             if (element != null) {
                 element.response = response;
                 element.ex = ex;
-                // persistent search response
+                // persistent search response || search response
                 if (element.lock == null) {
-
                     notifyPersistenSearchListener(element);
 
                 } else {
-                    /*
-                     * notify the thread which send request and wait for
-                     * response
-                     */
                     if (element.response.getOperationIndex() == LdapASN1Constant.OP_EXTENDED_RESPONSE
                             && ((ExtendedOp) element.response.getResponseOp())
                                     .getExtendedRequest().getID().equals(
@@ -254,6 +282,10 @@
                         isStopped = true;
                     }
 
+                    /*
+                     * notify the thread which send request and wait for
+                     * response
+                     */
                     synchronized (element.lock) {
                         element.lock.notify();
                     }
@@ -366,7 +398,7 @@
                 }
             }
         }
-        
+
         element = requests.get(messageID);
 
         // wait time out
@@ -394,7 +426,10 @@
     }
 
     private LdapMessage doSearchOperation(ASN1Encodable request,
-            ASN1Decodable response, Control[] controls) throws IOException {
+            ASN1Decodable response, Control[] controls)
+            throws IOException {
+        int batchSize = ((SearchOp) request).getBatchSize();
+
         LdapMessage requestMsg = new LdapMessage(
                 LdapASN1Constant.OP_SEARCH_REQUEST, request, controls);
 
@@ -407,9 +442,15 @@
             out.write(requestMsg.encode());
             out.flush();
             LdapMessage responseMsg = waitResponse(messageID, lock);
-
+            int size = 1;
             while (responseMsg.getOperationIndex() != LdapASN1Constant.OP_SEARCH_RESULT_DONE) {
+                if (size == batchSize) {
+                    batchedSearchRequests.put(messageID, requests
+                            .get(messageID));
+                    break;
+                }
                 responseMsg = waitResponse(messageID, lock);
+                ++size;
             }
 
             return responseMsg;

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java?rev=665949&r1=665948&r2=665949&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java Mon Jun  9 18:47:49 2008
@@ -807,7 +807,7 @@
             searchControls.setReturningAttributes(new String[] {
                     "namingContexts", "subschemaSubentry", "altServer", });
             search = new SearchOp(name.toString(), searchControls, filter);
-
+            search.setBatchSize(0);
             try {
                 client.doOperation(search, requestControls);
             } catch (IOException e) {
@@ -858,7 +858,7 @@
             throw ex;
         }
         search = new SearchOp(subschemasubentry, searchControls, filter);
-
+        search.setBatchSize(0);
         try {
             client.doOperation(search, requestControls);
         } catch (IOException e) {
@@ -1155,7 +1155,6 @@
         if (result.isEmpty() && result.getException() != null) {
             throw result.getException();
         }
-        
         return result.toSearchResultEnumeration(targetDN);
     }
 
@@ -1358,6 +1357,13 @@
     LdapSearchResult doSearch(String dn, Filter filter, SearchControls controls)
             throws NamingException {
         SearchOp op = new SearchOp(dn, controls, filter);
+        String stringValue = (String) env.get(Context.BATCHSIZE);
+        if (stringValue == null) {
+            op.setBatchSize(0);
+        } else {
+            op.setBatchSize(Integer.valueOf(stringValue).intValue());
+        }
+
         return doSearch(op);
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java?rev=665949&r1=665948&r2=665949&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java Mon Jun  9 18:47:49 2008
@@ -92,6 +92,12 @@
      */
     private boolean isFinished;
 
+    private static int ENUMERATION_NAME_CLASS_PAIR = 1;
+
+    private static int ENUMERATION_BINDING = 2;
+
+    private static int ENUMERATION_SEARCH_RESULT = 3;
+
     public int getBatchSize() {
         return batchSize;
     }
@@ -218,7 +224,7 @@
 
     public NamingEnumeration<NameClassPair> toNameClassPairEnumeration(
             String baseDN) {
-        enumerationType = 1;
+        enumerationType = ENUMERATION_NAME_CLASS_PAIR;
         enumeration = new LdapNamingEnumeration<Object>(null, null);
         this.baseDN = baseDN;
         addToEnumeration();
@@ -227,7 +233,7 @@
 
     public NamingEnumeration<Binding> toBindingEnumeration(
             LdapContextImpl context, Name name) throws NamingException {
-        enumerationType = 2;
+        enumerationType = ENUMERATION_BINDING;
         enumeration = new LdapNamingEnumeration<Object>(null, null);
         this.context = context;
         this.name = name;
@@ -243,7 +249,7 @@
 
     public NamingEnumeration<SearchResult> toSearchResultEnumeration(
             String baseDN) {
-        enumerationType = 3;
+        enumerationType = ENUMERATION_SEARCH_RESULT;
         enumeration = new LdapNamingEnumeration<Object>(null, null);
         this.baseDN = baseDN;
 

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java?rev=665949&r1=665948&r2=665949&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java Mon Jun  9 18:47:49 2008
@@ -43,6 +43,8 @@
 
     private LdapSearchResult result;
 
+    private int batchSize = 0;
+
     public LdapSearchResult getSearchResult() {
         if (result == null) {
             result = new LdapSearchResult();
@@ -149,4 +151,12 @@
         this.filter = filter;
     }
 
+    public int getBatchSize() {
+        return batchSize;
+    }
+
+    public void setBatchSize(int batchSize) {
+        this.batchSize = batchSize;
+    }
+
 }