From f73b655466092169abac34833fb628fce1fcdebe Mon Sep 17 00:00:00 2001
From: jcduff <jcduff@localhost>
Date: Thu, 23 Oct 2008 14:04:24 +0000
Subject: [PATCH] The commit will bring the following features :     - An updated version of the underlying database. BDB JE 3.3 is now used.     - Attribute API refactoring providing a better abstraction and offering improved performances.     - A new GUI called the Control-Panel to replace the Status-Panel: the specifications for this       GUI are available on OpenDS Wiki and contains a link to a mockup.        See <https://www.opends.org/wiki/page/ControlPanelUISpecification>.     - Some changes in the replication protocol to implement "Assured Replication Mode". The        specifications are on OpenDS Wiki at <https://www.opends.org/wiki/page/AssuredMode> and section 7       described some of the replication changes required to support this. Assured Replication is not finished,       but the main replication protocol changes to support it are done. As explained by Gilles on an email on       the Dev mailing list (http://markmail.org/message/46rgo3meq3vriy4a), with these changes the newer versions       of OpenDS may not be able to replicate with OpenDS 1.0 instances.     - Support for Service Tags on the platforms where the functionality is available and enabled. Specifications       are published at <https://www.opends.org/wiki/page/OpenDSServiceTagEnabled>. For more information on       Service Tags see <http://wikis.sun.com/display/ServiceTag/Sun+Service+Tag+FAQ>.     - The Admin Connector service. In order to provide agentry of the OpenDS server at any time, a new service       has been added, dedicated to the administration, configuration and monitoring of the server.       An overview of the Admin Connector service and it's use is available on the       OpenDS wiki <https://www.opends.org/wiki/page/ManagingAdministrationTrafficToTheServer>     - Updates to the various command line tools to support the Admin Connector service.     - Some internal re-architecting of the server to put the foundation of future developments such as virtual       directory services. The new NetworkGroups and WorkFlow internal services which have been specified in       <https://www.opends.org/wiki/page/BasicOperationRoutingThroughNetworkGroup> are now implemented.     - Many bug fixes...

---
 opends/src/server/org/opends/server/backends/jeb/JECompressedSchema.java |  101 ++++++++++++++++++++++++++++++++------------------
 1 files changed, 64 insertions(+), 37 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/jeb/JECompressedSchema.java b/opends/src/server/org/opends/server/backends/jeb/JECompressedSchema.java
index ed75f82..f480da1 100644
--- a/opends/src/server/org/opends/server/backends/jeb/JECompressedSchema.java
+++ b/opends/src/server/org/opends/server/backends/jeb/JECompressedSchema.java
@@ -28,23 +28,18 @@
 
 
 
+import static org.opends.messages.JebMessages.*;
+import static org.opends.server.loggers.debug.DebugLogger.*;
+import static org.opends.server.util.StaticUtils.*;
+
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import com.sleepycat.je.Cursor;
-import com.sleepycat.je.Database;
-import com.sleepycat.je.DatabaseConfig;
-import com.sleepycat.je.DatabaseEntry;
-import com.sleepycat.je.DatabaseException;
-import com.sleepycat.je.DeadlockException;
-import com.sleepycat.je.Environment;
-import com.sleepycat.je.LockMode;
-import com.sleepycat.je.OperationStatus;
-
 import org.opends.messages.Message;
 import org.opends.server.api.CompressedSchema;
 import org.opends.server.core.DirectoryServer;
@@ -54,17 +49,24 @@
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.protocols.asn1.ASN1Sequence;
 import org.opends.server.types.Attribute;
+import org.opends.server.types.AttributeBuilder;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
+import org.opends.server.types.Attributes;
 import org.opends.server.types.ByteArray;
 import org.opends.server.types.DebugLogLevel;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.ObjectClass;
 
-import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.server.loggers.debug.DebugLogger.*;
-import static org.opends.messages.JebMessages.*;
-import static org.opends.server.util.StaticUtils.*;
+import com.sleepycat.je.Cursor;
+import com.sleepycat.je.Database;
+import com.sleepycat.je.DatabaseConfig;
+import com.sleepycat.je.DatabaseEntry;
+import com.sleepycat.je.DatabaseException;
+import com.sleepycat.je.DeadlockException;
+import com.sleepycat.je.Environment;
+import com.sleepycat.je.LockMode;
+import com.sleepycat.je.OperationStatus;
 
 
 
@@ -108,7 +110,7 @@
   private ConcurrentHashMap<ByteArray,AttributeType> atDecodeMap;
 
   // The map between encoded representations and attribute options.
-  private ConcurrentHashMap<ByteArray,LinkedHashSet<String>> aoDecodeMap;
+  private ConcurrentHashMap<ByteArray,Set<String>> aoDecodeMap;
 
   // The map between encoded representations and object class sets.
   private ConcurrentHashMap<ByteArray,Map<ObjectClass,String>> ocDecodeMap;
@@ -116,7 +118,7 @@
   // The map between attribute descriptions and their encoded
   // representations.
   private ConcurrentHashMap<AttributeType,
-               ConcurrentHashMap<LinkedHashSet<String>,ByteArray>> adEncodeMap;
+               ConcurrentHashMap<Set<String>,ByteArray>> adEncodeMap;
 
   // The map between object class sets and encoded representations.
   private ConcurrentHashMap<Map<ObjectClass,String>,ByteArray> ocEncodeMap;
@@ -148,11 +150,11 @@
     this.environment = environment;
 
     atDecodeMap = new ConcurrentHashMap<ByteArray,AttributeType>();
-    aoDecodeMap = new ConcurrentHashMap<ByteArray,LinkedHashSet<String>>();
+    aoDecodeMap = new ConcurrentHashMap<ByteArray,Set<String>>();
     ocDecodeMap = new ConcurrentHashMap<ByteArray,Map<ObjectClass,String>>();
     adEncodeMap =
          new ConcurrentHashMap<AttributeType,
-                  ConcurrentHashMap<LinkedHashSet<String>,ByteArray>>();
+                  ConcurrentHashMap<Set<String>,ByteArray>>();
     ocEncodeMap = new ConcurrentHashMap<Map<ObjectClass,String>,ByteArray>();
 
     adCounter = new AtomicInteger(1);
@@ -287,11 +289,11 @@
         atDecodeMap.put(token, attrType);
         aoDecodeMap.put(token, options);
 
-        ConcurrentHashMap<LinkedHashSet<String>,ByteArray> map =
+        ConcurrentHashMap<Set<String>,ByteArray> map =
              adEncodeMap.get(attrType);
         if (map == null)
         {
-          map = new ConcurrentHashMap<LinkedHashSet<String>,ByteArray>(1);
+          map = new ConcurrentHashMap<Set<String>,ByteArray>(1);
           map.put(options, token);
           adEncodeMap.put(attrType, map);
         }
@@ -438,16 +440,16 @@
          throws DirectoryException
   {
     AttributeType type = attribute.getAttributeType();
-    LinkedHashSet<String> options = attribute.getOptions();
+    Set<String> options = attribute.getOptions();
 
-    ConcurrentHashMap<LinkedHashSet<String>,ByteArray> map =
+    ConcurrentHashMap<Set<String>,ByteArray> map =
          adEncodeMap.get(type);
     if (map == null)
     {
       byte[] tokenArray;
       synchronized (adEncodeMap)
       {
-        map = new ConcurrentHashMap<LinkedHashSet<String>,ByteArray>(1);
+        map = new ConcurrentHashMap<Set<String>,ByteArray>(1);
 
         int intValue = adCounter.getAndIncrement();
         tokenArray = encodeInt(intValue);
@@ -521,11 +523,10 @@
    */
   private byte[] encodeAttribute(byte[] adArray, Attribute attribute)
   {
-    LinkedHashSet<AttributeValue> values = attribute.getValues();
     int totalValuesLength = 0;
-    byte[][] subArrays = new  byte[values.size()*2][];
+    byte[][] subArrays = new  byte[attribute.size()*2][];
     int pos = 0;
-    for (AttributeValue v : values)
+    for (AttributeValue v : attribute)
     {
       byte[] vBytes = v.getValueBytes();
       byte[] lBytes = ASN1Element.encodeLength(vBytes.length);
@@ -537,7 +538,7 @@
     }
 
     byte[] adArrayLength = ASN1Element.encodeLength(adArray.length);
-    byte[] countBytes = ASN1Element.encodeLength(values.size());
+    byte[] countBytes = ASN1Element.encodeLength(attribute.size());
     int totalLength = adArrayLength.length + adArray.length +
                       countBytes.length + totalValuesLength;
     byte[] array = new byte[totalLength];
@@ -591,7 +592,7 @@
     System.arraycopy(encodedEntry, pos, adArray.array(), 0, adArrayLength);
     pos += adArrayLength;
     AttributeType attrType = atDecodeMap.get(adArray);
-    LinkedHashSet<String> options = aoDecodeMap.get(adArray);
+    Set<String> options = aoDecodeMap.get(adArray);
     if ((attrType == null) || (options == null))
     {
       Message message = ERR_JEB_COMPSCHEMA_UNRECOGNIZED_AD_TOKEN.get(
@@ -614,17 +615,16 @@
     }
 
 
-    // Read the appropriate number of values.
-    LinkedHashSet<AttributeValue> values =
-         new LinkedHashSet<AttributeValue>(numValues);
-    for (int i=0; i < numValues; i++)
+    // For the common case of a single value with no options, generate
+    // less garbage.
+    if (numValues == 1 && options.isEmpty())
     {
       int valueLength = encodedEntry[pos] & 0x7F;
       if (valueLength != encodedEntry[pos++])
       {
         int valueLengthBytes = valueLength;
         valueLength = 0;
-        for (int j=0; j < valueLengthBytes; j++, pos++)
+        for (int j = 0; j < valueLengthBytes; j++, pos++)
         {
           valueLength = (valueLength << 8) | (encodedEntry[pos] & 0xFF);
         }
@@ -632,11 +632,38 @@
 
       byte[] valueBytes = new byte[valueLength];
       System.arraycopy(encodedEntry, pos, valueBytes, 0, valueLength);
-      pos += valueLength;
-      values.add(new AttributeValue(attrType, new ASN1OctetString(valueBytes)));
-    }
 
-    return new Attribute(attrType, attrType.getPrimaryName(), options, values);
+      return Attributes.create(attrType, new AttributeValue(attrType,
+          new ASN1OctetString(valueBytes)));
+    }
+    else
+    {
+      // Read the appropriate number of values.
+      AttributeBuilder builder = new AttributeBuilder(attrType);
+      builder.setOptions(options);
+      builder.setInitialCapacity(numValues);
+      for (int i = 0; i < numValues; i++)
+      {
+        int valueLength = encodedEntry[pos] & 0x7F;
+        if (valueLength != encodedEntry[pos++])
+        {
+          int valueLengthBytes = valueLength;
+          valueLength = 0;
+          for (int j = 0; j < valueLengthBytes; j++, pos++)
+          {
+            valueLength = (valueLength << 8) | (encodedEntry[pos] & 0xFF);
+          }
+        }
+
+        byte[] valueBytes = new byte[valueLength];
+        System.arraycopy(encodedEntry, pos, valueBytes, 0, valueLength);
+        pos += valueLength;
+        builder.add(new AttributeValue(attrType,
+            new ASN1OctetString(valueBytes)));
+      }
+
+      return builder.toAttribute();
+    }
   }
 
 

--
Gitblit v1.10.0