directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1385340 - in /directory/apacheds/branches/apacheds-mvbt: jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ prot...
Date Sun, 16 Sep 2012 18:44:36 GMT
Author: elecharny
Date: Sun Sep 16 18:44:35 2012
New Revision: 1385340

URL: http://svn.apache.org/viewvc?rev=1385340&view=rev
Log:
o Simplified the StringSerializer
o Speedup the UuidSerializer a bit
o Created a static instance of StringSerializer, using it instead of creating a new object

Modified:
    directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
    directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
    directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializer.java
    directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/UuidSerializer.java
    directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializerTest.java
    directory/apacheds/branches/apacheds-mvbt/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/provider/ReplicaEventLog.java
    directory/apacheds/branches/apacheds-mvbt/protocol-ldap/src/test/java/org/apache/directory/server/ldap/JournalTest.java

Modified: directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=1385340&r1=1385339&r2=1385340&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
Sun Sep 16 18:44:35 2012
@@ -214,7 +214,7 @@ public class JdbmIndex<K, V> extends Abs
         {
             forward = new JdbmTable<K, String>( schemaManager, attributeType.getOid()
+ FORWARD_BTREE, numDupLimit,
                 recMan,
-                comp, UuidComparator.INSTANCE, new StringSerializer(), UuidSerializer.INSTANCE
);
+                comp, UuidComparator.INSTANCE, StringSerializer.INSTANCE, UuidSerializer.INSTANCE
);
         }
         else
         {

Modified: directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java?rev=1385340&r1=1385339&r2=1385340&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
Sun Sep 16 18:44:35 2012
@@ -69,7 +69,7 @@ public class JdbmMasterTable extends Jdb
         super( schemaManager, DBF, recMan, UuidComparator.INSTANCE, UuidSerializer.INSTANCE,
             new EntrySerializer( schemaManager ) );
         adminTbl = new JdbmTable<String, String>( schemaManager, "admin", recMan, STRING_COMPARATOR,
-            new StringSerializer(), new StringSerializer() );
+            StringSerializer.INSTANCE, StringSerializer.INSTANCE );
         String seqValue = adminTbl.get( SEQPROP_KEY );
 
         if ( null == seqValue )
@@ -87,7 +87,7 @@ public class JdbmMasterTable extends Jdb
     {
         super( schemaManager, DBF, recMan, UuidComparator.INSTANCE, UuidSerializer.INSTANCE,
serializer );
         adminTbl = new JdbmTable<String, String>( schemaManager, dbName, recMan, STRING_COMPARATOR,
-            new StringSerializer(), new StringSerializer() );
+            StringSerializer.INSTANCE, StringSerializer.INSTANCE );
         String seqValue = adminTbl.get( SEQPROP_KEY );
 
         if ( null == seqValue )

Modified: directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializer.java?rev=1385340&r1=1385339&r2=1385340&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializer.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializer.java
Sun Sep 16 18:44:35 2012
@@ -34,24 +34,36 @@ public class StringSerializer implements
 {
     private static final long serialVersionUID = -173163945773783649L;
 
+    /** A static instance of a StringSerializer */
+    public static StringSerializer INSTANCE = new StringSerializer();
+
+
+    /**
+     * Default private constructor
+     */
+    private StringSerializer()
+    {
+    }
+
 
     /* (non-Javadoc)
      * @see jdbm.helper.Serializer#deserialize(byte[])
      */
-    public Object deserialize( byte[] bites ) throws IOException
+    public Object deserialize( byte[] bytes ) throws IOException
     {
-        if ( bites.length == 0 )
+        if ( bytes.length == 0 )
         {
             return "";
         }
 
-        char[] strchars = new char[bites.length >> 1];
-        for ( int ii = 0, jj = 0; ii < strchars.length; ii++, jj = ii << 1 )
+        char[] strchars = new char[bytes.length >> 1];
+        int pos = 0;
+
+        for ( int i = 0; i < bytes.length; i += 2 )
         {
-            int ch = bites[jj] << 8 & 0x0000FF00;
-            ch |= bites[jj + 1] & 0x000000FF;
-            strchars[ii] = ( char ) ch;
+            strchars[pos++] = ( char ) ( ( ( bytes[i] << 8 ) & 0x0000FF00 ) | (
bytes[i + 1] & 0x000000FF ) );
         }
+
         return new String( strchars );
     }
 
@@ -70,10 +82,12 @@ public class StringSerializer implements
 
         char[] strchars = ( ( String ) str ).toCharArray();
         byte[] bites = new byte[strchars.length << 1];
-        for ( int ii = 0, jj = 0; ii < strchars.length; ii++, jj = ii << 1 )
+        int pos = 0;
+
+        for ( char c : strchars )
         {
-            bites[jj] = ( byte ) ( strchars[ii] >> 8 & 0x00FF );
-            bites[jj + 1] = ( byte ) ( strchars[ii] & 0x00FF );
+            bites[pos++] = ( byte ) ( c >> 8 & 0x00FF );
+            bites[pos++] = ( byte ) ( c & 0x00FF );
         }
 
         return bites;

Modified: directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/UuidSerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/UuidSerializer.java?rev=1385340&r1=1385339&r2=1385340&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/UuidSerializer.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/UuidSerializer.java
Sun Sep 16 18:44:35 2012
@@ -24,11 +24,9 @@ import java.io.IOException;
 
 import jdbm.helper.Serializer;
 
-import org.apache.directory.shared.util.Strings;
-
 
 /**
- * A {@link Serializer} for Longs
+ * A {@link Serializer} for UUIDs
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -38,16 +36,22 @@ public class UuidSerializer implements S
     public static final UuidSerializer INSTANCE = new UuidSerializer();
 
 
+    /**
+     * {@inheritDoc}
+     */
     public byte[] serialize( Object o ) throws IOException
     {
         String uuid = ( String ) o;
 
-        return Strings.getBytesUtf8( uuid );
+        return StringSerializer.INSTANCE.serialize( uuid );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Object deserialize( byte[] bytes ) throws IOException
     {
-        return Strings.utf8ToString( bytes );
+        return StringSerializer.INSTANCE.deserialize( bytes );
     }
 }

Modified: directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializerTest.java?rev=1385340&r1=1385339&r2=1385340&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializerTest.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializerTest.java
Sun Sep 16 18:44:35 2012
@@ -20,15 +20,16 @@
 package org.apache.directory.server.core.partition.impl.btree.jdbm;
 
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.IOException;
 
 import org.apache.commons.lang.RandomStringUtils;
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import static org.junit.Assert.assertEquals;
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 
 /**
@@ -42,10 +43,11 @@ public class StringSerializerTest
     @Test
     public void testRandom() throws IOException
     {
-        StringSerializer serializer = new StringSerializer();
-        for ( int ii = 0; ii < 100; ii++ )
+        StringSerializer serializer = StringSerializer.INSTANCE;
+
+        for ( int i = 0; i < 100; i++ )
         {
-            String str = RandomStringUtils.random( ii );
+            String str = RandomStringUtils.random( i );
             byte[] serialized = serializer.serialize( str );
             String deserialized = ( String ) serializer.deserialize( serialized );
             assertEquals( str, deserialized );
@@ -57,6 +59,7 @@ public class StringSerializerTest
     {
         int ch = bites[0] << 8 & 0x0000FF00;
         ch |= bites[1] & 0x000000FF;
+
         return ( char ) ch;
     }
 
@@ -66,6 +69,7 @@ public class StringSerializerTest
         byte[] bites = new byte[2];
         bites[0] = ( byte ) ( ch >> 8 & 0x00FF );
         bites[1] = ( byte ) ( ch & 0x00FF );
+
         return bites;
     }
 

Modified: directory/apacheds/branches/apacheds-mvbt/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/provider/ReplicaEventLog.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/provider/ReplicaEventLog.java?rev=1385340&r1=1385339&r2=1385340&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/provider/ReplicaEventLog.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/provider/ReplicaEventLog.java
Sun Sep 16 18:44:35 2012
@@ -122,7 +122,7 @@ public class ReplicaEventLog implements 
         comparator.setSchemaManager( schemaManager );
 
         journal = new JdbmTable<String, ReplicaEventMessage>( schemaManager, "replication",
recman, comparator,
-            new StringSerializer(), new ReplicaEventMessageSerializer( schemaManager ) );
+            StringSerializer.INSTANCE, new ReplicaEventMessageSerializer( schemaManager )
);
     }
 
 

Modified: directory/apacheds/branches/apacheds-mvbt/protocol-ldap/src/test/java/org/apache/directory/server/ldap/JournalTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/protocol-ldap/src/test/java/org/apache/directory/server/ldap/JournalTest.java?rev=1385340&r1=1385339&r2=1385340&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/protocol-ldap/src/test/java/org/apache/directory/server/ldap/JournalTest.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/protocol-ldap/src/test/java/org/apache/directory/server/ldap/JournalTest.java
Sun Sep 16 18:44:35 2012
@@ -136,7 +136,7 @@ public class JournalTest
         comparator.setSchemaManager( schemaManager );
 
         journal = new JdbmTable<String, ReplicaEventMessage>( schemaManager, "test",
recman, comparator,
-            new StringSerializer(), new ReplicaEventMessageSerializer( schemaManager ) );
+            StringSerializer.INSTANCE, new ReplicaEventMessageSerializer( schemaManager )
);
 
     }
 
@@ -226,7 +226,7 @@ public class JournalTest
 
             pos++;
         }
-        
+
         cursor.close();
     }
 
@@ -272,7 +272,7 @@ public class JournalTest
             journal.sync();
             deleted++;
         }
-        
+
         deleteCursor.close();
 
         // Now check that the first mod is the 501th
@@ -286,7 +286,7 @@ public class JournalTest
         ReplicaEventMessage replicaEventMessage = tuple.getValue();
         assertEquals( ChangeType.ADD, replicaEventMessage.getChangeType() );
         assertEquals( "test500", replicaEventMessage.getEntry().get( "ou" ).getString() );
-        
+
         cursor.close();
     }
 



Mime
View raw message