From 176919e2700e49462eadc0f412237579e4d76165 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Sun, 16 Jul 2006 04:22:43 +0000
Subject: [PATCH] Update the task backend to change the format of the ds-cfg-task-retention-time configuration attribute from an integer (with the value specified in seconds) to an integer with unit (specified as an integer value followed by a unit of "seconds", "minutes", "hours", "days", or "weeks").  Also change the syntax of the attribute in the schema from integer to directory string.

---
 opends/src/server/org/opends/server/backends/task/TaskBackend.java |   68 +++++++++++++++++++++++----------
 1 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/task/TaskBackend.java b/opends/src/server/org/opends/server/backends/task/TaskBackend.java
index 02463c0..7096611 100644
--- a/opends/src/server/org/opends/server/backends/task/TaskBackend.java
+++ b/opends/src/server/org/opends/server/backends/task/TaskBackend.java
@@ -31,6 +31,7 @@
 import java.io.File;
 import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -39,7 +40,7 @@
 import org.opends.server.config.ConfigAttribute;
 import org.opends.server.config.ConfigEntry;
 import org.opends.server.config.ConfigException;
-import org.opends.server.config.IntegerConfigAttribute;
+import org.opends.server.config.IntegerWithUnitConfigAttribute;
 import org.opends.server.config.StringConfigAttribute;
 import org.opends.server.core.AddOperation;
 import org.opends.server.core.CancelledOperationException;
@@ -88,6 +89,15 @@
 
 
 
+  /**
+   * The set of time units that will be used for expressing the task retention
+   * time.
+   */
+  private static final LinkedHashMap<String,Double> timeUnits =
+       new LinkedHashMap<String,Double>();
+
+
+
   // The DN of the configuration entry for this backend.
   private DN configEntryDN;
 
@@ -124,6 +134,17 @@
 
 
 
+  static
+  {
+    timeUnits.put("seconds", 1.0);
+    timeUnits.put("minutes", 60.0);
+    timeUnits.put("hours", (60.0*60.0));
+    timeUnits.put("days", (24.0*60.0*60.0));
+    timeUnits.put("weeks", (7.0*24.0*60.0*60.0));
+  }
+
+
+
   /**
    * Creates a new backend with the provided information.  All backend
    * implementations must implement a default constructor that use
@@ -237,13 +258,14 @@
     // Get the retention time that will be used to determine how long task
     // information stays around once the associated task is completed.
     int msgID = MSGID_TASKBE_DESCRIPTION_RETENTION_TIME;
-    IntegerConfigAttribute retentionStub =
-         new IntegerConfigAttribute(ATTR_TASK_RETENTION_TIME, getMessage(msgID),
-                                    true, false, false, true, 0, false, 0);
+    IntegerWithUnitConfigAttribute retentionStub =
+         new IntegerWithUnitConfigAttribute(ATTR_TASK_RETENTION_TIME,
+                                            getMessage(msgID), false, timeUnits,
+                                            true, 0, false, 0);
     try
     {
-      IntegerConfigAttribute retentionAttr =
-           (IntegerConfigAttribute)
+      IntegerWithUnitConfigAttribute retentionAttr =
+           (IntegerWithUnitConfigAttribute)
            configEntry.getConfigAttribute(retentionStub);
       if (retentionAttr == null)
       {
@@ -251,7 +273,7 @@
       }
       else
       {
-        retentionTime = retentionAttr.activeValue();
+        retentionTime = retentionAttr.activeCalculatedValue();
       }
     }
     catch (Exception e)
@@ -1260,9 +1282,11 @@
                                            taskBackingFile));
 
     description = getMessage(MSGID_TASKBE_DESCRIPTION_RETENTION_TIME);
-    attrList.add(new IntegerConfigAttribute(ATTR_TASK_RETENTION_TIME,
-                                            description, true, false, false,
-                                            true, 0, false, 0, retentionTime));
+    attrList.add(new IntegerWithUnitConfigAttribute(ATTR_TASK_RETENTION_TIME,
+                                                    description, false,
+                                                    timeUnits, true, 0, false,
+                                                    0, retentionTime,
+                                                    "seconds"));
 
     return attrList;
   }
@@ -1363,13 +1387,14 @@
 
 
     description = getMessage(MSGID_TASKBE_DESCRIPTION_RETENTION_TIME);
-    IntegerConfigAttribute retentionStub =
-         new IntegerConfigAttribute(ATTR_TASK_RETENTION_TIME, description,
-                                    true, false, false, true, 0, false, 0);
+    IntegerWithUnitConfigAttribute retentionStub =
+         new IntegerWithUnitConfigAttribute(ATTR_TASK_RETENTION_TIME,
+                                            description, false, timeUnits,
+                                            true, 0, false, 0);
     try
     {
-      IntegerConfigAttribute retentionAttr =
-           (IntegerConfigAttribute)
+      IntegerWithUnitConfigAttribute retentionAttr =
+           (IntegerWithUnitConfigAttribute)
            configEntry.getConfigAttribute(retentionStub);
       if (retentionAttr == null)
       {
@@ -1494,13 +1519,14 @@
 
     long tmpRetentionTime = retentionTime;
     description = getMessage(MSGID_TASKBE_DESCRIPTION_RETENTION_TIME);
-    IntegerConfigAttribute retentionStub =
-         new IntegerConfigAttribute(ATTR_TASK_RETENTION_TIME, description,
-                                    true, false, false, true, 0, false, 0);
+    IntegerWithUnitConfigAttribute retentionStub =
+         new IntegerWithUnitConfigAttribute(ATTR_TASK_RETENTION_TIME,
+                                            description, false, timeUnits,
+                                            true, 0, false, 0);
     try
     {
-      IntegerConfigAttribute retentionAttr =
-           (IntegerConfigAttribute)
+      IntegerWithUnitConfigAttribute retentionAttr =
+           (IntegerWithUnitConfigAttribute)
            configEntry.getConfigAttribute(retentionStub);
       if (retentionAttr == null)
       {
@@ -1514,7 +1540,7 @@
       }
       else
       {
-        tmpRetentionTime = retentionTime;
+        tmpRetentionTime = retentionAttr.activeCalculatedValue();
       }
     }
     catch (Exception e)

--
Gitblit v1.10.0