directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r752445 - /directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java
Date Wed, 11 Mar 2009 13:47:29 GMT
Author: kayyagari
Date: Wed Mar 11 13:47:28 2009
New Revision: 752445

URL: http://svn.apache.org/viewvc?rev=752445&view=rev
Log:
o implemented various handler callback methods

Modified:
    directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java

Modified: directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java?rev=752445&r1=752444&r2=752445&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java
(original)
+++ directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java
Wed Mar 11 13:47:28 2009
@@ -50,6 +50,7 @@
 import org.apache.directory.shared.ldap.codec.search.SearchRequest;
 import org.apache.directory.shared.ldap.codec.search.SearchResultDone;
 import org.apache.directory.shared.ldap.codec.search.SearchResultEntry;
+import org.apache.directory.shared.ldap.codec.search.SearchResultReference;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
@@ -78,7 +79,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class SyncreplConsumer implements ConsumerCalllback
+public class SyncreplConsumer implements ConsumerCallback
 {
 
     /** the syncrepl configuration */
@@ -301,143 +302,136 @@
     }
 
 
-    /**
-     * {@inheritDoc}
-     * atm does nothinng except examinig and printing the content of syncinfovalue control
-     */
-    public void handleSyncInfo( IntermediateResponse response )
+    public void handleSearchDone( SearchResultDone searchDone )
     {
-        if ( response == null )
+        LOG.debug( "///////////////// handleSearchDone //////////////////" );
+        Control ctrl = searchDone.getCurrentControl();
+        SyncDoneValueControlCodec syncDoneCtrl = ( SyncDoneValueControlCodec ) ctrl.getControlValue();
+
+        if ( !config.isRefreshPersist() )
         {
-            return;
+            config.setRefreshPersist( true );
         }
 
-        try
+        if ( syncDoneCtrl.getCookie() != null )
+        {
+            syncCookie = syncDoneCtrl.getCookie();
+            LOG.debug( "assigning cookie from sync done value control: " + StringTools.utf8ToString(
syncCookie ) );
+        }
+        else
         {
-            LOG.debug( "============ inside handleSyncInfo ======================" );
-            String name = response.getResponseName();
-            byte[] value = response.getResponseValue();
+            LOG.info( "cookie in syncdone message is null" );
+        }
 
-            SyncInfoValueControlCodec syncInfoValue = ( SyncInfoValueControlCodec ) decoder.decode(
value );
+        LOG.debug( "//////////////// END handleSearchDone//////////////////////" );
+    }
 
-            byte[] cookie = syncInfoValue.getCookie();
 
-            if ( cookie != null )
+    public void handleSearchReference( SearchResultReference searchRef )
+    {
+        LOG.error( "!!!!!!!!!!!!!!!!! TODO handle SearchReference messages !!!!!!!!!!!!!!!!"
);
+    }
+
+
+    public void handleSearchResult( SearchResultEntry syncResult )
+    {
+
+        LOG.debug( "------------- starting handleSearchResult ------------" );
+
+        try
+        {
+            Entry clientEntry = syncResult.getEntry();
+
+            Control ctrl = syncResult.getCurrentControl();
+            SyncStateValueControlCodec syncStateCtrl = ( SyncStateValueControlCodec ) ctrl.getControlValue();
+
+            if ( syncStateCtrl.getCookie() != null )
             {
-                LOG.debug( "setting the cookie from the sync info: " + StringTools.utf8ToString(
value ) );
-                syncCookie = cookie;
+                syncCookie = syncStateCtrl.getCookie();
+                LOG.debug( "assigning the cookie from sync state value control: "
+                    + StringTools.utf8ToString( syncCookie ) );
             }
 
-            SearchResultEntry searchResult = response.getSearchResultEntry();
+            SyncStateTypeEnum state = syncStateCtrl.getSyncStateType();
 
-            LOG.debug( "searchResult: " + searchResult );
+            LOG.debug( "state name {}" + state.name() );
+            LOG.debug( "entryUUID = " + StringTools.utf8ToString( syncStateCtrl.getEntryUUID()
) );
+            CoreSession session = directoryService.getAdminSession();
 
-            List<byte[]> uuidList = syncInfoValue.getSyncUUIDs();
+            if ( state == SyncStateTypeEnum.ADD )
+            {
 
-            LOG.info( "The uuid list " + uuidList );// receives a list of UUIDs of the entries
what to do with them???
-            LOG.info( "refreshDeletes: " + syncInfoValue.isRefreshDeletes() );
-            LOG.info( "refreshDone: " + syncInfoValue.isRefreshDone() );
+                if ( !session.exists( clientEntry.getDn() ) )
+                {
+                    LOG.debug( "adding entry with dn {}", clientEntry.getDn().getUpName()
);
+                    LOG.debug( clientEntry.toString() );
+                    session.add( new DefaultServerEntry( directoryService.getRegistries(),
clientEntry ) );
+                }
+            }
+            else if ( state == SyncStateTypeEnum.MODIFY )
+            {
+                // WARN FIXME inefficient delta calculation
+                // FIXME won't work for deleted attributes
+                LOG.debug( "modifying entry with dn {}", clientEntry.getDn().getUpName()
);
+
+                List<Modification> mods = new ArrayList<Modification>();
+                Iterator<EntryAttribute> itr = clientEntry.iterator();
+                while ( itr.hasNext() )
+                {
+                    Modification mod = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE,
itr.next() );
+                    mods.add( mod );
+                }
+
+                session.modify( clientEntry.getDn(), mods );
+            }
+            else if ( state == SyncStateTypeEnum.DELETE )
+            {
+                LOG.debug( "deleting entry with dn {}", clientEntry.getDn().getUpName() );
+                directoryService.getAdminSession().delete( clientEntry.getDn() );
+            }
         }
-        catch ( DecoderException de )
+        catch ( Exception e )
         {
-            LOG.error( "Failed to handle syncinfo message" );
-            de.printStackTrace();
+            LOG.error( e.getMessage(), e );
         }
 
-        LOG.debug( "============ END handleSyncInfo ======================" );
-
+        LOG.debug( "------------- starting handleSearchResult ------------" );
     }
 
 
     /**
      * {@inheritDoc}
+     * atm does nothinng except examinig and printing the content of syncinfovalue control
      */
-    public void handleSearchResult( List<SearchResultEntry> syncResList, SearchResultDone
searchDone,
-        IntermediateResponse intermResponse )
+    public void handleSyncInfo( byte[] syncinfo )
     {
-
-        handleSyncInfo( intermResponse );
-
-        LOG.debug( "================ starting handleSearchResult ==============" );
         try
         {
-            SyncDoneValueControlCodec syncDoneCtrl = ( SyncDoneValueControlCodec ) searchDone.getCurrentControl()
-                .getControlValue();
+            LOG.debug( "............... inside handleSyncInfo ..............." );
 
-            if ( syncDoneCtrl.getCookie() != null )
-            {
-                syncCookie = syncDoneCtrl.getCookie();
-                LOG.debug( "assigning cookie from sync done value control: " + StringTools.utf8ToString(
syncCookie ) );
-            }
-            {
-                LOG.info( "cookie in syncdone message is null" );
-            }
+            SyncInfoValueControlCodec syncInfoValue = ( SyncInfoValueControlCodec ) decoder.decode(
syncinfo );
 
-            LOG.info( "synccookie {}", StringTools.utf8ToString( syncCookie ) );
+            byte[] cookie = syncInfoValue.getCookie();
 
-            if ( syncResList != null )
+            if ( cookie != null )
             {
-                LOG.debug( "sync state results..." + syncResList.size() );
-                for ( SearchResultEntry entry : syncResList )
-                {
-                    Entry clientEntry = entry.getEntry();
-                    SyncStateValueControlCodec syncStateCtrl = ( SyncStateValueControlCodec
) entry.getCurrentControl()
-                        .getControlValue();
-
-                    if ( syncStateCtrl.getCookie() != null )
-                    {
-                        syncCookie = syncStateCtrl.getCookie();
-                        LOG.debug( "assigning the cookie from sync state value control: "
-                            + StringTools.utf8ToString( syncCookie ) );
-                    }
-
-                    SyncStateTypeEnum state = syncStateCtrl.getSyncStateType();
-
-                    LOG.debug( "state name {}" + state.name() );
-                    LOG.debug( "entryUUID = " + clientEntry.get( "entryUUID" ) );
-                    CoreSession session = directoryService.getAdminSession();
-
-                    if ( state == SyncStateTypeEnum.ADD )
-                    {
-
-                        if ( !session.exists( clientEntry.getDn() ) )
-                        {
-                            LOG.debug( "adding entry with dn {}", clientEntry.getDn().getUpName()
);
-                            LOG.debug( clientEntry.toString() );
-                            session.add( new DefaultServerEntry( directoryService.getRegistries(),
clientEntry ) );
-                        }
-                        else
-                        {
-                            // WARN FIXME inefficient delta calculation
-                            // FIXME won't work for deleted attributes
-                            LOG.debug( "modifying entry with dn {}", clientEntry.getDn().getUpName()
);
-
-                            List<Modification> mods = new ArrayList<Modification>();
-                            Iterator<EntryAttribute> itr = clientEntry.iterator();
-                            while ( itr.hasNext() )
-                            {
-                                Modification mod = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE,
itr
-                                    .next() );
-                                mods.add( mod );
-                            }
-
-                            session.modify( clientEntry.getDn(), mods );
-                        }
-                    }
-                    else if ( state == SyncStateTypeEnum.DELETE )
-                    {
-                        LOG.debug( "deleting entry with dn {}" + clientEntry.getDn().getUpName()
);
-                        directoryService.getAdminSession().delete( clientEntry.getDn() );
-                    }
-                }
+                LOG.debug( "setting the cookie from the sync info: " + StringTools.utf8ToString(
cookie ) );
+                syncCookie = cookie;
             }
+
+            List<byte[]> uuidList = syncInfoValue.getSyncUUIDs();
+
+            LOG.info( "The uuid list " + uuidList );// receives a list of UUIDs of the entries
what to do with them???
+            LOG.info( "refreshDeletes: " + syncInfoValue.isRefreshDeletes() );
+            LOG.info( "refreshDone: " + syncInfoValue.isRefreshDone() );
         }
-        catch ( Exception e )
+        catch ( DecoderException de )
         {
-            LOG.error( e.getMessage(), e );
+            LOG.error( "Failed to handle syncinfo message" );
+            de.printStackTrace();
         }
 
-        LOG.debug( "================ END starting handleSearchResult ==============" );
+        LOG.debug( ".................... END handleSyncInfo ..............." );
     }
 
 
@@ -459,15 +453,21 @@
 
             int pass = 1;
 
-            while ( true )
+            do
             {
 
+                if( config.isRefreshPersist() )
+                {
+                    syncReq.setMode( SynchronizationModeEnum.REFRESH_AND_PERSIST );
+                }
+
                 if ( syncCookie != null )
                 {
                     syncReq.setCookie( syncCookie );
-                    searchRequest.getCurrentControl().setControlValue( syncReq.getEncodedValue()
);
                 }
-
+                
+                searchRequest.getCurrentControl().setControlValue( syncReq.getEncodedValue()
);
+                
                 try
                 {
                     LOG.debug( "========================================================
Pass #" + pass + "==========" );
@@ -485,7 +485,10 @@
                 {
                     LOG.error( "Failed to sync", e );
                 }
-            }// end of while loop
+            }
+            while( syncReq.getMode() != SynchronizationModeEnum.REFRESH_AND_PERSIST );//
end of while loop
+            
+            LOG.debug( "**************** exiting the while loop ***************" );
         }
         catch ( Exception e )
         {



Mime
View raw message