You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/04/12 22:05:09 UTC

svn commit: r933391 - in /directory/apacheds/trunk/syncrepl: ./ src/main/java/org/apache/directory/server/syncrepl/

Author: kayyagari
Date: Mon Apr 12 20:05:08 2010
New Revision: 933391

URL: http://svn.apache.org/viewvc?rev=933391&view=rev
Log:
o updated client-api dependency version
o fixed the errors introduced cuase of the refactoring done in shared and client-api

Modified:
    directory/apacheds/trunk/syncrepl/pom.xml
    directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java
    directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java
    directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java
    directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java

Modified: directory/apacheds/trunk/syncrepl/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/syncrepl/pom.xml?rev=933391&r1=933390&r2=933391&view=diff
==============================================================================
--- directory/apacheds/trunk/syncrepl/pom.xml (original)
+++ directory/apacheds/trunk/syncrepl/pom.xml Mon Apr 12 20:05:08 2010
@@ -49,7 +49,7 @@
     <dependency>
       <groupId>org.apache.directory.client.ldap</groupId>
       <artifactId>ldap-client-api</artifactId>
-      <version>0.1-SNAPSHOT</version>
+      <version>0.2-SNAPSHOT</version>
     </dependency>
 
     <dependency>

Modified: directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java?rev=933391&r1=933390&r2=933391&view=diff
==============================================================================
--- directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java (original)
+++ directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java Mon Apr 12 20:05:08 2010
@@ -31,12 +31,13 @@ import javax.swing.JTextField;
 import javax.swing.border.TitledBorder;
 
 import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.ldap.client.api.message.SearchResponse;
 import org.apache.directory.ldap.client.api.message.SearchResultEntry;
 import org.apache.directory.shared.ldap.cursor.Cursor;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
 import org.apache.directory.shared.ldap.filter.SearchScope;
-import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.DN;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -67,7 +68,7 @@ public class EntryInjector extends JPane
 
     public EntryInjector( String host, int port, String bindDn, String pwd ) throws Exception
     {
-        connection = new LdapConnection( host, port );
+        connection = new LdapNetworkConnection( host, port );
         connection.bind( bindDn, pwd );
 
         addcomponents();
@@ -80,7 +81,7 @@ public class EntryInjector extends JPane
         try
         {
             String cn = "entry-" + System.currentTimeMillis();
-            LdapDN dn = new LdapDN( "cn=" + cn + "," + config.getBaseDn() );
+            DN dn = new DN( "cn=" + cn + "," + config.getBaseDn() );
             DefaultClientEntry entry = new DefaultClientEntry();
             entry.add( "objectclass", "inetOrgPerson", "organizationalPerson", "person" );
             entry.add( "cn", cn );

Modified: directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java?rev=933391&r1=933390&r2=933391&view=diff
==============================================================================
--- directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java (original)
+++ directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java Mon Apr 12 20:05:08 2010
@@ -28,22 +28,23 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.directory.ldap.client.api.LdapAsyncConnection;
 import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.ldap.client.api.exception.LdapException;
-import org.apache.directory.ldap.client.api.listener.IntermediateResponseListener;
-import org.apache.directory.ldap.client.api.listener.SearchListener;
+import org.apache.directory.ldap.client.api.future.SearchFuture;
 import org.apache.directory.ldap.client.api.message.BindResponse;
 import org.apache.directory.ldap.client.api.message.IntermediateResponse;
 import org.apache.directory.ldap.client.api.message.LdapResult;
+import org.apache.directory.ldap.client.api.message.SearchIntermediateResponse;
 import org.apache.directory.ldap.client.api.message.SearchRequest;
+import org.apache.directory.ldap.client.api.message.SearchResponse;
 import org.apache.directory.ldap.client.api.message.SearchResultDone;
 import org.apache.directory.ldap.client.api.message.SearchResultEntry;
 import org.apache.directory.ldap.client.api.message.SearchResultReference;
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
-import org.apache.directory.server.core.entry.DefaultServerEntry;
-import org.apache.directory.server.core.entry.ServerModification;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControl;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlDecoder;
@@ -53,11 +54,12 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.controls.replication.syncStateValue.SyncStateValueControl;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncStateValue.SyncStateValueControlDecoder;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.DefaultServerEntry;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.entry.ServerModification;
 import org.apache.directory.shared.ldap.filter.EqualityNode;
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.OrNode;
@@ -67,7 +69,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.message.control.replication.SyncStateTypeEnum;
 import org.apache.directory.shared.ldap.message.control.replication.SynchronizationModeEnum;
-import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -76,14 +78,14 @@ import org.slf4j.LoggerFactory;
 
 /**
  * 
- * An agent capable of communicate with some LDAP servers.
+ * Implementation of syncrepl slave a.k.a consumer.
  * 
  * TODO write test cases
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class SyncReplConsumer implements SearchListener, IntermediateResponseListener
+public class SyncReplConsumer
 {
 
     /** the syncrepl configuration */
@@ -96,7 +98,7 @@ public class SyncReplConsumer implements
     private static final Logger LOG = LoggerFactory.getLogger( SyncReplConsumer.class.getSimpleName() );
 
     /** conection to the syncrepl provider */
-    private LdapConnection connection;
+    private LdapAsyncConnection connection;
 
     /** the search request with control */
     private SearchRequest searchRequest;
@@ -128,7 +130,7 @@ public class SyncReplConsumer implements
 
     /** attributes on which modification should be ignored */
     private static final String[] MOD_IGNORE_AT = new String[]
-        { "entryUUID", "entryCSN" }; //{ "1.3.6.1.1.16.4", "1.3.6.1.4.1.4203.666.1.7" };
+        { SchemaConstants.ENTRY_UUID_AT, SchemaConstants.ENTRY_CSN_AT }; //{ "1.3.6.1.1.16.4", "1.3.6.1.4.1.4203.666.1.7" };
 
     /** flag to indicate whether the current phase is for deleting entries */
     private boolean refreshDeletes;
@@ -182,7 +184,7 @@ public class SyncReplConsumer implements
             // Create a connection
             if ( connection == null )
             {
-                connection = new LdapConnection( providerHost, port );
+                connection = new LdapNetworkConnection( providerHost, port );
             }
 
             // Do a bind
@@ -322,7 +324,8 @@ public class SyncReplConsumer implements
 
             try
             {
-                syncStateCtrl = ( SyncStateValueControl ) syncStateControlDecoder.decode( ctrl.getValue(), syncStateCtrl );
+                syncStateCtrl = ( SyncStateValueControl ) syncStateControlDecoder.decode( ctrl.getValue(),
+                    syncStateCtrl );
             }
             catch ( Exception e )
             {
@@ -356,7 +359,7 @@ public class SyncReplConsumer implements
                         session.add( new DefaultServerEntry( schemaManager, remoteEntry ) );
                     }
                     // in refreshOnly mode the modified entry will be sent with state ADD
-                    else if( !config.isRefreshPersist() )
+                    else if ( !config.isRefreshPersist() )
                     {
                         LOG.debug( "updating entry in refreshOnly mode {}", remoteEntry.getDn().getName() );
                         modify( remoteEntry );
@@ -518,7 +521,27 @@ public class SyncReplConsumer implements
         searchRequest.add( syncReq );
 
         // Do the search
-        connection.search( searchRequest, this );
+        SearchFuture sf = connection.searchAsync( searchRequest );
+
+        SearchResponse resp = sf.get();
+
+        while ( !( resp instanceof SearchResultDone ) || !sf.isCancelled() )
+        {
+            if ( resp instanceof SearchResultEntry )
+            {
+                handleSearchResult( ( SearchResultEntry ) resp );
+            }
+            else if ( resp instanceof SearchResultReference )
+            {
+                handleSearchReference( ( SearchResultReference ) resp );
+            }
+            else if ( resp instanceof SearchIntermediateResponse )
+            {
+                handleSyncInfo( ( ( SearchIntermediateResponse ) resp ).getResponseValue() );
+            }
+        }
+        
+        handleSearchDone( ( SearchResultDone ) resp );
     }
 
 
@@ -540,10 +563,10 @@ public class SyncReplConsumer implements
             LOG.info( "Connection closed for the server {}", config.getProviderHost() );
 
             connection = null;
-            
+
             // persist the cookie
             storeCookie();
-            
+
             // reset the cookie
             syncCookie = null;
         }
@@ -699,22 +722,22 @@ public class SyncReplConsumer implements
         int i = 0;
         for ( ; i < count; i++ )
         {
-            startIndex = i* NODE_LIMIT;
+            startIndex = i * NODE_LIMIT;
             _deleteEntries_( uuidList.subList( startIndex, startIndex + NODE_LIMIT ) );
         }
 
-        if( ( uuidList.size() % NODE_LIMIT ) != 0 )
+        if ( ( uuidList.size() % NODE_LIMIT ) != 0 )
         {
             // remove the remaining entries
-            if( count > 0 )
+            if ( count > 0 )
             {
-                startIndex = i* NODE_LIMIT;
+                startIndex = i * NODE_LIMIT;
             }
             _deleteEntries_( uuidList.subList( startIndex, uuidList.size() ) );
         }
     }
-    
-    
+
+
     /**
      * do not call this method directly, instead call deleteEntries()
      *
@@ -724,37 +747,39 @@ public class SyncReplConsumer implements
     {
         ExprNode filter = null;
         int size = limitedUuidList.size();
-        if( size == 1 )
+        if ( size == 1 )
         {
             String uuid = StringTools.uuidToString( limitedUuidList.get( 0 ) );
-            filter = new EqualityNode<String>( SchemaConstants.ENTRY_UUID_AT, new ClientStringValue( uuid ) );
+            filter = new EqualityNode<String>( SchemaConstants.ENTRY_UUID_AT,
+                new org.apache.directory.shared.ldap.entry.StringValue( uuid ) );
         }
         else
         {
             filter = new OrNode();
-            for ( int i=0; i < size; i++ )
+            for ( int i = 0; i < size; i++ )
             {
                 String uuid = StringTools.uuidToString( limitedUuidList.get( i ) );
-                EqualityNode<String> uuidEqNode = new EqualityNode<String>( SchemaConstants.ENTRY_UUID_AT, new ClientStringValue( uuid ) );
+                EqualityNode<String> uuidEqNode = new EqualityNode<String>( SchemaConstants.ENTRY_UUID_AT,
+                    new org.apache.directory.shared.ldap.entry.StringValue( uuid ) );
                 ( ( OrNode ) filter ).addNode( uuidEqNode );
             }
         }
 
-        LdapDN dn = new LdapDN( config.getBaseDn() );
+        DN dn = new DN( config.getBaseDn() );
         dn.normalize( schemaManager.getNormalizerMapping() );
 
-        EntryFilteringCursor cursor = session.search( dn, SearchScope.SUBTREE, filter, AliasDerefMode.NEVER_DEREF_ALIASES, new HashSet() );
-    
-        while( cursor.next() )
+        EntryFilteringCursor cursor = session.search( dn, SearchScope.SUBTREE, filter,
+            AliasDerefMode.NEVER_DEREF_ALIASES, new HashSet() );
+
+        while ( cursor.next() )
         {
             ClonedServerEntry entry = cursor.get();
             session.delete( entry.getDn(), true );
         }
-        
+
         cursor.close();
     }
-    
-    
+
     /**
      * A Thread implementation for synchronizing the DIT in refreshOnly mode
      */
@@ -804,43 +829,4 @@ public class SyncReplConsumer implements
         }
     }
 
-
-    //====================== SearchListener methods ====================================
-
-    /* (non-Javadoc)
-     * @see org.apache.directory.shared.ldap.client.api.listeners.SearchListener#entryFound(org.apache.directory.shared.ldap.client.api.LdapConnection, org.apache.directory.shared.ldap.client.api.messages.SearchResultEntry)
-     */
-    public void entryFound( LdapConnection connection, SearchResultEntry searchResultEntry ) throws LdapException
-    {
-        handleSearchResult( searchResultEntry );
-    }
-
-
-    /* (non-Javadoc)
-     * @see org.apache.directory.shared.ldap.client.api.listeners.SearchListener#referralFound(org.apache.directory.shared.ldap.client.api.LdapConnection, org.apache.directory.shared.ldap.client.api.messages.SearchResultReference)
-     */
-    public void referralFound( LdapConnection connection, SearchResultReference searchResultReference )
-        throws LdapException
-    {
-        handleSearchReference( searchResultReference );
-    }
-
-
-    /* (non-Javadoc)
-     * @see org.apache.directory.shared.ldap.client.api.listeners.SearchListener#searchDone(org.apache.directory.shared.ldap.client.api.LdapConnection, org.apache.directory.shared.ldap.client.api.messages.SearchResultDone)
-     */
-    public void searchDone( LdapConnection connection, SearchResultDone searchResultDone ) throws LdapException
-    {
-        handleSearchDone( searchResultDone );
-    }
-
-
-    /* (non-Javadoc)
-     * @see org.apache.directory.shared.ldap.client.api.listeners.IntermediateResponseListener#responseReceived(org.apache.directory.shared.ldap.client.api.LdapConnection, org.apache.directory.shared.ldap.client.api.messages.IntermediateResponse)
-     */
-    public void responseReceived( LdapConnection connection, IntermediateResponse intermediateResponse )
-    {
-        handleSyncInfo( intermediateResponse.getResponseValue() );
-    }
-
 }

Modified: directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java?rev=933391&r1=933390&r2=933391&view=diff
==============================================================================
--- directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java (original)
+++ directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java Mon Apr 12 20:05:08 2010
@@ -73,7 +73,7 @@ public class SyncreplConfiguration
     private int searchTimeout = 0;
 
     /** the search scope */
-    private int searchScope = SearchScope.ONELEVEL.getJndiScope();
+    private int searchScope = SearchScope.ONELEVEL.getScope();
 
     /** the replica's id */
     private int replicaId;

Modified: directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java?rev=933391&r1=933390&r2=933391&view=diff
==============================================================================
--- directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java (original)
+++ directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java Mon Apr 12 20:05:08 2010
@@ -41,7 +41,6 @@ import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.DefaultDirectoryService;
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.partition.Partition;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
@@ -53,8 +52,9 @@ import org.apache.directory.server.ldap.
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.directory.server.xdbm.Index;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.ServerEntry;
 import org.apache.directory.shared.ldap.filter.SearchScope;
-import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
@@ -117,7 +117,7 @@ public class SyncreplRunnerUI implements
         config.setBaseDn( "dc=my-domain,dc=com" );
         config.setFilter( "(objectclass=*)" );
         config.setAttributes( "*,entryUUID,entryCSN" );
-        config.setSearchScope( SearchScope.SUBTREE.getJndiScope() );
+        config.setSearchScope( SearchScope.SUBTREE.getScope() );
         config.setReplicaId( 1 );
         config.setRefreshPersist( false );
         config.setConsumerInterval( 60 * 1000 );
@@ -217,7 +217,7 @@ public class SyncreplRunnerUI implements
             ldapServer.setTransports( new TcpTransport( consumerPort ) );
             ldapServer.setDirectoryService( dirService );
 
-            LdapDN suffix = new LdapDN( config.getBaseDn() );
+            DN suffix = new DN( config.getBaseDn() );
             JdbmPartition partition = new JdbmPartition();
             partition.setSuffix( suffix.getName() );
             partition.setId( "syncrepl" );
@@ -226,7 +226,7 @@ public class SyncreplRunnerUI implements
             partition.setSchemaManager( dirService.getSchemaManager() );
             
             // Add objectClass attribute for the system partition
-            Set<Index<?, ServerEntry>> indexedAttrs = new HashSet<Index<?, ServerEntry>>();
+            Set<Index<?, ServerEntry, Long>> indexedAttrs = new HashSet<Index<?, ServerEntry, Long>>();
             indexedAttrs.add( new JdbmIndex<Object, ServerEntry>( SchemaConstants.ENTRY_UUID_AT ) );
             ( ( JdbmPartition ) partition ).setIndexedAttributes( indexedAttrs );
 
@@ -394,7 +394,7 @@ public class SyncreplRunnerUI implements
         ( ( JdbmPartition ) systemPartition ).setPartitionDir( new File( dirService.getWorkingDirectory(), "system" ) );
 
         // Add objectClass attribute for the system partition
-        Set<Index<?, ServerEntry>> indexedAttrs = new HashSet<Index<?, ServerEntry>>();
+        Set<Index<?, ServerEntry, Long>> indexedAttrs = new HashSet<Index<?, ServerEntry, Long>>();
         indexedAttrs.add( new JdbmIndex<Object, ServerEntry>( SchemaConstants.OBJECT_CLASS_AT ) );
         ( ( JdbmPartition ) systemPartition ).setIndexedAttributes( indexedAttrs );