Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 97102 invoked from network); 21 Mar 2009 04:22:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Mar 2009 04:22:45 -0000 Received: (qmail 87920 invoked by uid 500); 21 Mar 2009 04:22:44 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 87890 invoked by uid 500); 21 Mar 2009 04:22:44 -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 87881 invoked by uid 99); 21 Mar 2009 04:22:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Mar 2009 21:22:44 -0700 X-ASF-Spam-Status: No, hits=-1998.8 required=10.0 tests=ALL_TRUSTED,FS_REPLICA 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; Sat, 21 Mar 2009 04:22:36 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 85DCF23888EB; Sat, 21 Mar 2009 04:22:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r756874 - /directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/SyncreplConsumer.java Date: Sat, 21 Mar 2009 04:22:15 -0000 To: commits@directory.apache.org From: kayyagari@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090321042215.85DCF23888EB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kayyagari Date: Sat Mar 21 04:22:13 2009 New Revision: 756874 URL: http://svn.apache.org/viewvc?rev=756874&view=rev Log: o moved the modify operation logic to a new method o added code for deleting entries based on UUID(yet to be implemented at the partition level) 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=756874&r1=756873&r2=756874&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 Sat Mar 21 04:22:13 2009 @@ -106,6 +106,9 @@ /** flag to indicate whether the consumer was diconncted */ private boolean disconnected; + + /** the core session */ + private CoreSession session; /** * @return the config @@ -148,7 +151,7 @@ } - public void init( DirectoryService directoryservice ) + public void init( DirectoryService directoryservice ) throws Exception { this.directoryService = directoryservice; @@ -156,6 +159,8 @@ cookieDir.mkdir(); cookieFile = new File( cookieDir, String.valueOf( config.getReplicaId() ) ); + + session = directoryService.getAdminSession(); } @@ -385,7 +390,6 @@ LOG.debug( "state name {}", state.name() ); LOG.debug( "entryUUID = {}", UUID.nameUUIDFromBytes( syncStateCtrl.getEntryUUID() ) ); - CoreSession session = directoryService.getAdminSession(); switch ( state ) { @@ -400,48 +404,12 @@ break; case MODIFY : - Entry localEntry = session.lookup( remoteEntry.getDn() ); - LOG.debug( "modifying entry with dn {}", remoteEntry.getDn().getUpName() ); - - List mods = new ArrayList(); - Iterator itr = localEntry.iterator(); - - while ( itr.hasNext() ) - { - EntryAttribute localAttr = itr.next(); - String attrId = localAttr.getId(); - Modification mod; - EntryAttribute remoteAttr = remoteEntry.get( attrId ); - - if ( remoteAttr != null ) // would be better if we compare the values also? or will it consume more time? - { - mod = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, remoteAttr ); - remoteEntry.remove( remoteAttr ); - } - else - { - mod = new ServerModification( ModificationOperation.REMOVE_ATTRIBUTE, localAttr ); - } - - mods.add( mod ); - } - - if( remoteEntry.size() > 0 ) - { - itr = remoteEntry.iterator(); - while( itr.hasNext() ) - { - mods.add( new ServerModification( ModificationOperation.ADD_ATTRIBUTE, itr.next() ) ); - } - } - - session.modify( remoteEntry.getDn(), mods ); - + modify( remoteEntry ); break; case DELETE : LOG.debug( "deleting entry with dn {}", remoteEntry.getDn().getUpName() ); - directoryService.getAdminSession().delete( remoteEntry.getDn() ); + session.delete( remoteEntry.getDn() ); break; } } @@ -476,8 +444,27 @@ List 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() ); + if( uuidList != null ) + { + for( byte[] uuid : uuidList ) + { + LOG.info( "uuid: {}", StringTools.utf8ToString( uuid ) ); + } + } + + // if refreshDeletes set to true then delete all the entries with entryUUID + // present in the syncIdSet + if( syncInfoValue.isRefreshDeletes() && ( uuidList != null ) ) + { + for( byte[] uuid : uuidList ) + { + // TODO similar to delete based on DN there should be + // a method to delete an Entry based on entryUUID + LOG.debug( "FIXME deleting the entry with entryUUID: {}", UUID.nameUUIDFromBytes( uuid ) ); + } + } + LOG.info( "refreshDone: " + syncInfoValue.isRefreshDone() ); } catch ( DecoderException de ) @@ -665,7 +652,6 @@ syncCookie = new byte[ fin.read() ]; fin.read( syncCookie ); fin.close(); - LOG.debug( "read the cookie from file: " + StringTools.utf8ToString( syncCookie ) ); } } @@ -687,4 +673,46 @@ cookieFile.delete(); } } + + + private void modify( Entry remoteEntry ) throws Exception + { + LOG.debug( "modifying entry with dn {}", remoteEntry.getDn().getUpName() ); + + Entry localEntry = session.lookup( remoteEntry.getDn() ); + + List mods = new ArrayList(); + Iterator itr = localEntry.iterator(); + + while ( itr.hasNext() ) + { + EntryAttribute localAttr = itr.next(); + String attrId = localAttr.getId(); + Modification mod; + EntryAttribute remoteAttr = remoteEntry.get( attrId ); + + if ( remoteAttr != null ) // would be better if we compare the values also? or will it consume more time? + { + mod = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, remoteAttr ); + remoteEntry.remove( remoteAttr ); + } + else + { + mod = new ServerModification( ModificationOperation.REMOVE_ATTRIBUTE, localAttr ); + } + + mods.add( mod ); + } + + if( remoteEntry.size() > 0 ) + { + itr = remoteEntry.iterator(); + while( itr.hasNext() ) + { + mods.add( new ServerModification( ModificationOperation.ADD_ATTRIBUTE, itr.next() ) ); + } + } + + session.modify( remoteEntry.getDn(), mods ); + } }