Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3C21FD3F1 for ; Thu, 29 Nov 2012 10:09:27 +0000 (UTC) Received: (qmail 73038 invoked by uid 500); 29 Nov 2012 10:09:26 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 72938 invoked by uid 500); 29 Nov 2012 10:09:24 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 72888 invoked by uid 99); 29 Nov 2012 10:09:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Nov 2012 10:09:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Nov 2012 10:09:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0E11A23888E7; Thu, 29 Nov 2012 10:08:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1415111 - /directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/SearchRequestHandler.java Date: Thu, 29 Nov 2012 10:08:57 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121129100858.0E11A23888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Thu Nov 29 10:08:56 2012 New Revision: 1415111 URL: http://svn.apache.org/viewvc?rev=1415111&view=rev Log: o Created a specific method to handle replication o renamed the readResults method to writeResults : this is what this method do, anyway... Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/SearchRequestHandler.java Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/SearchRequestHandler.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/SearchRequestHandler.java?rev=1415111&r1=1415110&r2=1415111&view=diff ============================================================================== --- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/SearchRequestHandler.java (original) +++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/SearchRequestHandler.java Thu Nov 29 10:08:56 2012 @@ -162,7 +162,7 @@ public class SearchRequestHandler extend } // now we process entries forever as they change - PersistentSearchListener handler = new PersistentSearchListener( session, req ); + PersistentSearchListener persistentSearchListener = new PersistentSearchListener( session, req ); // compose notification criteria and add the listener to the event // service using that notification criteria to determine which events @@ -173,8 +173,8 @@ public class SearchRequestHandler extend criteria.setFilter( req.getFilter() ); criteria.setScope( req.getScope() ); criteria.setEventMask( EventType.getEventTypes( psearch.getChangeTypes() ) ); - getLdapServer().getDirectoryService().getEventService().addListener( handler, criteria ); - req.addAbandonListener( new SearchAbandonListener( ldapServer, handler ) ); + getLdapServer().getDirectoryService().getEventService().addListener( persistentSearchListener, criteria ); + req.addAbandonListener( new SearchAbandonListener( ldapServer, persistentSearchListener ) ); } @@ -191,22 +191,7 @@ public class SearchRequestHandler extend // check first for the syncrepl search request decorator if ( req.getControls().containsKey( SyncRequestValue.OID ) ) { - if ( replicationReqHandler != null ) - { - replicationReqHandler.handleSyncRequest( session, req ); - } - else - { - LOG.warn( "This server does not allow replication" ); - // Replication is not allowed on this server. generate a error message - LdapResult result = req.getResultResponse().getLdapResult(); - - result.setDiagnosticMessage( "Replication is not allowed on this server" ); - result.setResultCode( ResultCodeEnum.OTHER ); - session.getIoSession().write( req.getResultResponse() ); - - return; - } + handleReplication( session, req ); } // if we have the ManageDSAIt decorator, go directly // to the handling without pre-processing the request @@ -237,6 +222,30 @@ public class SearchRequestHandler extend } } } + + + /** + * Handle the replication request. + */ + private void handleReplication( LdapSession session, SearchRequest searchRequest ) throws LdapException + { + if ( replicationReqHandler != null ) + { + replicationReqHandler.handleSyncRequest( session, searchRequest ); + } + else + { + // Replication is not allowed on this server. generate a error message + LOG.warn( "This server does not allow replication" ); + LdapResult result = searchRequest.getResultResponse().getLdapResult(); + + result.setDiagnosticMessage( "Replication is not allowed on this server" ); + result.setResultCode( ResultCodeEnum.OTHER ); + session.getIoSession().write( searchRequest.getResultResponse() ); + + return; + } + } /** @@ -374,7 +383,7 @@ public class SearchRequestHandler extend } - private void readResults( LdapSession session, SearchRequest req, LdapResult ldapResult, + private void writeResults( LdapSession session, SearchRequest req, LdapResult ldapResult, EntryFilteringCursor cursor, long sizeLimit ) throws Exception { long count = 0; @@ -636,6 +645,12 @@ public class SearchRequestHandler extend if ( Strings.isEmpty( cookie ) ) { + // No cursor : do a search. + cursor = session.getCoreSession().search( req ); + + // Position the cursor at the beginning + cursor.beforeFirst(); + // This is a new search. We have a special case when the paged size // is above the server size limit : in this case, we default to a // standard search @@ -644,14 +659,8 @@ public class SearchRequestHandler extend // Normal search : create the cursor, and set pagedControl to false try { - // No cursor : do a search. - cursor = session.getCoreSession().search( req ); - - // Position the cursor at the beginning - cursor.beforeFirst(); - - // And read the entries - readResults( session, req, ldapResult, cursor, sizeLimit ); + // And write the entries + writeResults( session, req, ldapResult, cursor, sizeLimit ); } finally { @@ -667,6 +676,7 @@ public class SearchRequestHandler extend // If we had a cookie in the session, remove it removeContext( session, pagedContext ); + return req.getResultResponse(); } else @@ -682,12 +692,6 @@ public class SearchRequestHandler extend pagedResultsControl.setSize( 0 ); pagedResultsControl.setCritical( true ); - // No cursor : do a search. - cursor = session.getCoreSession().search( req ); - - // Position the cursor at the beginning - cursor.beforeFirst(); - // And stores the cursor into the session pagedContext.setCursor( cursor ); } @@ -745,7 +749,6 @@ public class SearchRequestHandler extend pagedResultsControl.setCookie( cookie ); pagedResultsControl.setSize( 0 ); pagedResultsControl.setCritical( true ); - } } @@ -835,7 +838,7 @@ public class SearchRequestHandler extend long sizeLimit = min( requestLimit, serverLimit ); - readResults( session, req, ldapResult, cursor, sizeLimit ); + writeResults( session, req, ldapResult, cursor, sizeLimit ); } finally {