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 912774F8E for ; Wed, 11 May 2011 13:41:07 +0000 (UTC) Received: (qmail 28365 invoked by uid 500); 11 May 2011 13:41:07 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 28326 invoked by uid 500); 11 May 2011 13:41:07 -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 28319 invoked by uid 99); 11 May 2011 13:41:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 May 2011 13:41:07 +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; Wed, 11 May 2011 13:41:05 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B93ED2388A29; Wed, 11 May 2011 13:40:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1101873 [2/2] - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/ apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authz/ apacheds/trunk/core-integ/src/test/java/org/apache/direc... Date: Wed, 11 May 2011 13:40:45 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110511134045.B93ED2388A29@eris.apache.org> Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/EntryCursorImpl.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/EntryCursorImpl.java?rev=1101873&r1=1101872&r2=1101873&view=diff ============================================================================== --- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/EntryCursorImpl.java (original) +++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/EntryCursorImpl.java Wed May 11 13:40:44 2011 @@ -21,20 +21,16 @@ package org.apache.directory.ldap.client.api; -import java.util.concurrent.TimeUnit; - -import org.apache.directory.ldap.client.api.future.SearchFuture; import org.apache.directory.shared.i18n.I18n; import org.apache.directory.shared.ldap.model.cursor.AbstractCursor; import org.apache.directory.shared.ldap.model.cursor.EntryCursor; import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException; +import org.apache.directory.shared.ldap.model.cursor.SearchCursor; import org.apache.directory.shared.ldap.model.entry.Entry; import org.apache.directory.shared.ldap.model.exception.LdapException; -import org.apache.directory.shared.ldap.model.exception.LdapReferralException; import org.apache.directory.shared.ldap.model.message.Response; import org.apache.directory.shared.ldap.model.message.SearchResultDone; import org.apache.directory.shared.ldap.model.message.SearchResultEntry; -import org.apache.directory.shared.ldap.model.message.SearchResultReference; /** @@ -46,94 +42,70 @@ import org.apache.directory.shared.ldap. */ public class EntryCursorImpl extends AbstractCursor implements EntryCursor { - /** the search future */ - private SearchFuture future; - - /** wait time while polling for a SearchResponse */ - private long timeout; - - /** time units of timeout value */ - private TimeUnit timeUnit; - /** a reference to hold the retrieved SearchResponse object from SearchFuture */ private Response response; - /** the done flag */ - private boolean done; - - /** a reference to hold the SearchResultDone response */ - private SearchResultDone searchDoneResp; + /** The encapsulated search cursor */ + private SearchCursor searchCursor; + /** The underlying messageId */ + private int messageId; /** - * Instantiates a new search cursor. + * Instantiates a new search cursor, embedding a SearchCursor. * - * @param future the future - * @param timeout the timeout - * @param timeUnit the time unit - */ - public EntryCursorImpl( SearchFuture future, long timeout, TimeUnit timeUnit ) - { - this.future = future; - this.timeout = timeout; - this.timeUnit = timeUnit; + * @param searchCursor the embedded SearchResponse cursor + */ + public EntryCursorImpl( SearchCursor searchCursor ) + { + this.searchCursor = searchCursor; + messageId = -1; } - + /** * {@inheritDoc} */ public boolean next() throws Exception { - if ( done ) + if ( !searchCursor.next() ) { return false; } try { - if ( future.isCancelled() ) + + do { - response = null; - done = true; - return false; - } + response = searchCursor.get(); - response = future.get( timeout, timeUnit ); + if ( response == null ) + { + throw new LdapException( LdapNetworkConnection.TIME_OUT_ERROR ); + } + + messageId = response.getMessageId(); + + if ( response instanceof SearchResultEntry ) + { + return true; + } + } + while ( !( response instanceof SearchResultDone ) ); + + return false; } catch ( Exception e ) { LdapException ldapException = new LdapException( LdapNetworkConnection.NO_RESPONSE_ERROR ); ldapException.initCause( e ); - // Send an abandon request - if ( !future.isCancelled() ) - { - future.cancel( true ); - } - // close the cursor close( ldapException ); throw ldapException; } - - if ( response == null ) - { - future.cancel( true ); - - throw new LdapException( LdapNetworkConnection.TIME_OUT_ERROR ); - } - - done = ( response instanceof SearchResultDone ); - - if ( done ) - { - searchDoneResp = ( SearchResultDone ) response; - response = null; - } - - return !done; } @@ -142,18 +114,21 @@ public class EntryCursorImpl extends Abs */ public Entry get() throws Exception { - if ( !available() ) + if ( !searchCursor.available() ) { throw new InvalidCursorPositionException(); } - if ( response instanceof SearchResultEntry ) + do { - return ((SearchResultEntry)response).getEntry(); + if ( response instanceof SearchResultEntry ) + { + return ((SearchResultEntry)response).getEntry(); + } } + while ( next() && !( response instanceof SearchResultDone ) ); - SearchResultReference referral = ((SearchResultReference)response); - throw new LdapReferralException( referral.getReferral().getLdapUrls() ); + return null; } @@ -162,7 +137,7 @@ public class EntryCursorImpl extends Abs */ public SearchResultDone getSearchResultDone() { - return searchDoneResp; + return searchCursor.getSearchResultDone(); } @@ -180,7 +155,7 @@ public class EntryCursorImpl extends Abs */ public boolean available() { - return response != null; + return searchCursor.available(); } @@ -190,7 +165,7 @@ public class EntryCursorImpl extends Abs @Override public void close() throws Exception { - close( null ); + searchCursor.close(); } @@ -200,25 +175,7 @@ public class EntryCursorImpl extends Abs @Override public void close( Exception cause ) throws Exception { - if ( done ) - { - super.close(); - return; - } - - if ( !future.isCancelled() ) - { - future.cancel( true ); - } - - if ( cause != null ) - { - super.close( cause ); - } - else - { - super.close(); - } + searchCursor.close( cause ); } @@ -299,4 +256,13 @@ public class EntryCursorImpl extends Abs throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName() .concat( "." ).concat( "previous()" ) ) ); } + + + /** + * {@inheritDoc} + */ + public int getMessageId() + { + return messageId; + } } Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=1101873&r1=1101872&r2=1101873&view=diff ============================================================================== --- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java (original) +++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Wed May 11 13:40:44 2011 @@ -25,6 +25,7 @@ import java.util.List; import org.apache.directory.shared.asn1.util.Oid; import org.apache.directory.shared.ldap.codec.api.LdapCodecService; +import org.apache.directory.shared.ldap.model.cursor.EntryCursor; import org.apache.directory.shared.ldap.model.cursor.SearchCursor; import org.apache.directory.shared.ldap.model.entry.Entry; import org.apache.directory.shared.ldap.model.entry.Modification; @@ -232,7 +233,7 @@ public interface LdapConnection * @return A search cursor on the result. * @throws LdapException if some error occurred */ - SearchCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes ) + EntryCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException; @@ -255,7 +256,7 @@ public interface LdapConnection * @return A search cursor on the result. * @throws LdapException if some error occurred */ - SearchCursor search( String baseDn, String filter, SearchScope scope, String... attributes ) + EntryCursor search( String baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException; @@ -782,10 +783,4 @@ public interface LdapConnection * @return true if there is a non-null future exists, false otherwise */ boolean doesFutureExistFor( int messageId ); - - - /** - * Shutdowns the internal OSGi container if any. - */ - void shutdown(); } \ No newline at end of file Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1101873&r1=1101872&r2=1101873&view=diff ============================================================================== --- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original) +++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Wed May 11 13:40:44 2011 @@ -69,6 +69,7 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.codec.api.MessageEncoderException; import org.apache.directory.shared.ldap.model.constants.SchemaConstants; import org.apache.directory.shared.ldap.model.cursor.Cursor; +import org.apache.directory.shared.ldap.model.cursor.EntryCursor; import org.apache.directory.shared.ldap.model.cursor.SearchCursor; import org.apache.directory.shared.ldap.model.entry.Attribute; import org.apache.directory.shared.ldap.model.entry.DefaultEntry; @@ -1558,7 +1559,7 @@ public class LdapNetworkConnection exten /** * {@inheritDoc} */ - public SearchCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes ) + public EntryCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException { if ( baseDn == null ) @@ -1577,14 +1578,14 @@ public class LdapNetworkConnection exten searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS ); // Process the request in blocking mode - return search( searchRequest ); + return new EntryCursorImpl( search( searchRequest ) ); } /** * {@inheritDoc} */ - public SearchCursor search( String baseDn, String filter, SearchScope scope, String... attributes ) + public EntryCursor search( String baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException { return search( new Dn( baseDn ), filter, scope, attributes ); @@ -3505,14 +3506,13 @@ public class LdapNetworkConnection exten */ private void fetchRootDSE() throws LdapException { - Cursor cursor = null; + EntryCursor cursor = null; + try { cursor = search( "", "(objectClass=*)", SearchScope.OBJECT, "*", "+" ); cursor.next(); - SearchResultEntry searchRes = ( SearchResultEntry ) cursor.get(); - - rootDSE = searchRes.getEntry(); + rootDSE = cursor.get(); } catch ( Exception e ) { @@ -4003,17 +4003,4 @@ public class LdapNetworkConnection exten return krb5ConfPath; } - - - - /** - * {@inheritDoc} - */ - public void shutdown() - { - if ( codec != null ) - { - codec.shutdown(); - } - } } Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/NetworkSchemaLoader.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/NetworkSchemaLoader.java?rev=1101873&r1=1101872&r2=1101873&view=diff ============================================================================== --- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/NetworkSchemaLoader.java (original) +++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/NetworkSchemaLoader.java Wed May 11 13:40:44 2011 @@ -25,15 +25,13 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.apache.directory.shared.ldap.model.cursor.Cursor; +import org.apache.directory.shared.ldap.model.cursor.EntryCursor; import org.apache.directory.shared.ldap.model.entry.Entry; import org.apache.directory.shared.ldap.model.exception.LdapException; -import org.apache.directory.shared.ldap.model.message.Response; -import org.apache.directory.shared.ldap.model.message.SearchResultEntry; import org.apache.directory.shared.ldap.model.message.SearchScope; import org.apache.directory.shared.ldap.model.name.Dn; -import org.apache.directory.shared.ldap.model.schema.registries.Schema; import org.apache.directory.shared.ldap.model.schema.registries.AbstractSchemaLoader; +import org.apache.directory.shared.ldap.model.schema.registries.Schema; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -112,11 +110,11 @@ public class NetworkSchemaLoader extends filter = FILTER; } - Cursor cursor = connection.search( new Dn( baseDn ), filter, SearchScope.ONELEVEL, "*", "+" ); + EntryCursor cursor = connection.search( new Dn( baseDn ), filter, SearchScope.ONELEVEL, "*", "+" ); while ( cursor.next() ) { - Entry entry = ( ( SearchResultEntry ) cursor.get() ).getEntry(); + Entry entry = cursor.get(); entries.add( entry ); } Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/EntryCursor.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/EntryCursor.java?rev=1101873&r1=1101872&r2=1101873&view=diff ============================================================================== --- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/EntryCursor.java (original) +++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/EntryCursor.java Wed May 11 13:40:44 2011 @@ -38,4 +38,10 @@ public interface EntryCursor extends Cur * @return the SearchResultDone message, null if the search operation fails for any reason */ public SearchResultDone getSearchResultDone(); + + + /** + * @return the underlying message ID + */ + public int getMessageId(); }