From 1649148841be6bc4ac6381d0592dc9ab52438044 Mon Sep 17 00:00:00 2001
From: abobrov <abobrov@localhost>
Date: Sun, 02 Sep 2007 13:05:17 +0000
Subject: [PATCH] - [Issue 1481] Ability to set any JE property in config.ldif - [Issue 2031] provide core JE configurable attributes for FileSystemEntryCache - fixes to entry cache config manager for proper configuration, re-configuration, error reporting.

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

diff --git a/opends/src/server/org/opends/server/backends/jeb/ConfigurableEnvironment.java b/opends/src/server/org/opends/server/backends/jeb/ConfigurableEnvironment.java
index 68ffafb..caebba9 100644
--- a/opends/src/server/org/opends/server/backends/jeb/ConfigurableEnvironment.java
+++ b/opends/src/server/org/opends/server/backends/jeb/ConfigurableEnvironment.java
@@ -35,8 +35,11 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.SortedSet;
+import java.util.StringTokenizer;
+import org.opends.messages.Message;
 
-import static org.opends.server.loggers.debug.DebugLogger.*;
 import org.opends.server.loggers.debug.DebugTracer;
 import org.opends.server.admin.std.server.JEBackendCfg;
 import org.opends.server.admin.std.meta.JEBackendCfgDefn;
@@ -44,6 +47,9 @@
 import org.opends.server.admin.BooleanPropertyDefinition;
 import org.opends.server.admin.PropertyDefinition;
 
+import static org.opends.server.loggers.debug.DebugLogger.*;
+import static org.opends.messages.ConfigMessages.*;
+
 /**
  * This class maps JE properties to configuration attributes.
  */
@@ -166,6 +172,13 @@
 
 
   /**
+   * The name of the attribute which may specify any native JE properties.
+   */
+  public static final String ATTR_JE_PROPERTY =
+       ConfigConstants.NAME_PREFIX_CFG + "je-property";
+
+
+  /**
    * A map of JE property names to the corresponding configuration attribute.
    */
   private static HashMap<String, String> attrMap =
@@ -391,6 +404,92 @@
       envConfig.setConfigParam(jeProperty, value);
     }
 
+    // See if there are any native JE properties specified in the config
+    // and if so try to parse, evaluate and set them.
+    SortedSet<String> jeProperties = cfg.getJEProperty();
+    try {
+      envConfig = setJEProperties(envConfig, jeProperties, attrMap);
+    } catch (ConfigException e) {
+      throw e;
+    }
+
+    return envConfig;
+  }
+
+
+
+  /**
+   * Parse, validate and set native JE environment properties for
+   * a given environment config.
+   *
+   * @param  envConfig The JE environment config for which to set
+   *                   the properties.
+   * @param  jeProperties The JE environment properties to parse,
+   *                      validate and set.
+   * @param  configAttrMap Component supported JE properties to
+   *                       their configuration attributes map.
+   * @return An environment config instance with given properties
+   *         set.
+   * @throws ConfigException If there is an error while parsing,
+   *         validating and setting any of the properties provided.
+   */
+  public static EnvironmentConfig setJEProperties(EnvironmentConfig envConfig,
+    SortedSet<String> jeProperties, HashMap<String, String> configAttrMap)
+    throws ConfigException
+  {
+    if (jeProperties.isEmpty()) {
+      // return default config.
+      return envConfig;
+    }
+
+    // Set to catch duplicate properties.
+    HashSet<String> uniqueJEProperties = new HashSet<String>();
+
+    // Iterate through the config values associated with a JE property.
+    for (String jeEntry : jeProperties)
+    {
+      StringTokenizer st = new StringTokenizer(jeEntry, "=");
+      if (st.countTokens() == 2) {
+        String jePropertyName = st.nextToken();
+        String jePropertyValue = st.nextToken();
+        // Check if it is a duplicate.
+        if (uniqueJEProperties.contains(jePropertyName)) {
+          Message message = ERR_CONFIG_JE_DUPLICATE_PROPERTY.get(
+              jePropertyName);
+            throw new ConfigException(message);
+        }
+        // Set JE property.
+        try {
+          envConfig.setConfigParam(jePropertyName, jePropertyValue);
+          // This is a special case that JE cannot validate before
+          // actually setting it. Validate it before it gets to JE.
+          if (jePropertyName.equals("java.util.logging.level")) {
+            java.util.logging.Level.parse(jePropertyValue);
+          }
+          // If this property shadows an existing config attribute.
+          if (configAttrMap.containsKey(jePropertyName)) {
+            Message message = ERR_CONFIG_JE_PROPERTY_SHADOWS_CONFIG.get(
+              jePropertyName, attrMap.get(jePropertyName));
+            throw new ConfigException(message);
+          }
+          // Add this property to unique set.
+          uniqueJEProperties.add(jePropertyName);
+        } catch(IllegalArgumentException e) {
+          if (debugEnabled()) {
+            TRACER.debugCaught(DebugLogLevel.ERROR, e);
+          }
+          Message message =
+            ERR_CONFIG_JE_PROPERTY_INVALID.get(
+            jeEntry, e.getMessage());
+          throw new ConfigException(message, e.getCause());
+        }
+      } else {
+        Message message =
+          ERR_CONFIG_JE_PROPERTY_INVALID_FORM.get(jeEntry);
+        throw new ConfigException(message);
+      }
+    }
+
     return envConfig;
   }
 

--
Gitblit v1.10.0