From 6879d04bd633e99ef7013bffafce2ef04adc3006 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 19 Sep 2014 14:55:35 +0000
Subject: [PATCH] Checkpoint commit for OPENDJ-1206 : Create a new ReplicationBackend/ChangelogBackend to support cn=changelog

---
 opendj3-server-dev/src/server/org/opends/server/backends/task/TaskBackend.java |  362 +++++++++++++++++----------------------------------
 1 files changed, 121 insertions(+), 241 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/task/TaskBackend.java b/opendj3-server-dev/src/server/org/opends/server/backends/task/TaskBackend.java
index 0ea9955..a0e6b5e 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/task/TaskBackend.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/task/TaskBackend.java
@@ -45,7 +45,6 @@
 import org.forgerock.opendj.ldap.ModificationType;
 import org.forgerock.opendj.ldap.SearchScope;
 import org.forgerock.util.Reject;
-import org.opends.server.admin.Configuration;
 import org.opends.server.admin.server.ConfigurationChangeListener;
 import org.opends.server.admin.std.server.TaskBackendCfg;
 import org.opends.server.api.Backend;
@@ -70,51 +69,53 @@
  * recurring basis.
  */
 public class TaskBackend
-       extends Backend
+       extends Backend<TaskBackendCfg>
        implements ConfigurationChangeListener<TaskBackendCfg>
 {
   private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
 
 
-  // The current configuration state.
+  /** The current configuration state. */
   private TaskBackendCfg currentConfig;
 
-  // The DN of the configuration entry for this backend.
+  /** The DN of the configuration entry for this backend. */
   private DN configEntryDN;
 
-  // The DN of the entry that will serve as the parent for all recurring task
-  // entries.
+  /**
+   * The DN of the entry that will serve as the parent for all recurring task
+   * entries.
+   */
   private DN recurringTaskParentDN;
 
-  // The DN of the entry that will serve as the parent for all scheduled task
-  // entries.
+  /**
+   * The DN of the entry that will serve as the parent for all scheduled task
+   * entries.
+   */
   private DN scheduledTaskParentDN;
 
-  // The DN of the entry that will serve as the root for all task entries.
+  /** The DN of the entry that will serve as the root for all task entries. */
   private DN taskRootDN;
 
-  // The set of base DNs defined for this backend.
+  /** The set of base DNs defined for this backend. */
   private DN[] baseDNs;
 
-  // The set of supported controls for this backend.
-  private HashSet<String> supportedControls;
-
-  // The set of supported features for this backend.
-  private HashSet<String> supportedFeatures;
-
-  // The length of time in seconds after a task is completed that it should be
-  // removed from the set of scheduled tasks.
+  /**
+   * The length of time in seconds after a task is completed that it should be
+   * removed from the set of scheduled tasks.
+   */
   private long retentionTime;
 
-  // The e-mail address to use for the sender from notification messages.
+  /** The e-mail address to use for the sender from notification messages. */
   private String notificationSenderAddress;
 
-  // The path to the task backing file.
+  /** The path to the task backing file. */
   private String taskBackingFile;
 
-  // The task scheduler that will be responsible for actually invoking scheduled
-  // tasks.
+  /**
+   * The task scheduler that will be responsible for actually invoking scheduled
+   * tasks.
+   */
   private TaskScheduler taskScheduler;
 
 
@@ -133,19 +134,13 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
-  public void configureBackend(Configuration config)
-         throws ConfigException
+  /** {@inheritDoc} */
+  @Override
+  public void configureBackend(TaskBackendCfg cfg) throws ConfigException
   {
-    Reject.ifNull(config);
-    Reject.ifFalse(config instanceof TaskBackendCfg);
+    Reject.ifNull(cfg);
 
-    TaskBackendCfg cfg = (TaskBackendCfg)config;
-
-    DN[] baseDNs = new DN[cfg.getBaseDN().size()];
+    final DN[] baseDNs = new DN[cfg.getBaseDN().size()];
     cfg.getBaseDN().toArray(baseDNs);
 
     ConfigEntry configEntry = DirectoryServer.getConfigEntry(cfg.dn());
@@ -155,10 +150,9 @@
 
     // Make sure that the provided set of base DNs contains exactly one value.
     // We will only allow one base for task entries.
-    if ((baseDNs == null) || (baseDNs.length == 0))
+    if (baseDNs.length == 0)
     {
-      LocalizableMessage message = ERR_TASKBE_NO_BASE_DNS.get();
-      throw new ConfigException(message);
+      throw new ConfigException(ERR_TASKBE_NO_BASE_DNS.get());
     }
     else if (baseDNs.length > 1)
     {
@@ -172,7 +166,7 @@
       taskRootDN = baseDNs[0];
 
       String recurringTaskBaseString = RECURRING_TASK_BASE_RDN + "," +
-                                       taskRootDN.toString();
+                                       taskRootDN;
       try
       {
         recurringTaskParentDN = DN.valueOf(recurringTaskBaseString);
@@ -188,7 +182,7 @@
       }
 
       String scheduledTaskBaseString = SCHEDULED_TASK_BASE_RDN + "," +
-                                       taskRootDN.toString();
+                                       taskRootDN;
       try
       {
         scheduledTaskParentDN = DN.valueOf(scheduledTaskBaseString);
@@ -229,19 +223,13 @@
     // Get the path to the task data backing file.
     taskBackingFile = cfg.getTaskBackingFile();
 
-    // Define an empty sets for the supported controls and features.
-    supportedControls = new HashSet<String>(0);
-    supportedFeatures = new HashSet<String>(0);
-
     currentConfig = cfg;
   }
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void initializeBackend()
          throws ConfigException, InitializationException
   {
@@ -271,10 +259,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void finalizeBackend()
   {
     currentConfig.removeTaskChangeListener(this);
@@ -313,10 +299,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public DN[] getBaseDNs()
   {
     return baseDNs;
@@ -324,10 +308,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public long getEntryCount()
   {
     if (taskScheduler != null)
@@ -340,10 +322,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean isLocal()
   {
     // For the purposes of this method, this is a local backend.
@@ -352,10 +332,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean isIndexed(AttributeType attributeType, IndexType indexType)
   {
     // All searches in this backend will always be considered indexed.
@@ -364,10 +342,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public ConditionResult hasSubordinates(DN entryDN)
          throws DirectoryException
   {
@@ -381,10 +357,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public long numSubordinates(DN entryDN, boolean subtree)
       throws DirectoryException
   {
@@ -439,10 +413,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public Entry getEntry(DN entryDN)
          throws DirectoryException
   {
@@ -497,10 +469,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void addEntry(Entry entry, AddOperation addOperation)
          throws DirectoryException
   {
@@ -543,10 +513,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void deleteEntry(DN entryDN, DeleteOperation deleteOperation)
          throws DirectoryException
   {
@@ -620,10 +588,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void replaceEntry(Entry oldEntry, Entry newEntry,
       ModifyOperation modifyOperation) throws DirectoryException
   {
@@ -810,24 +776,20 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void renameEntry(DN currentDN, Entry entry,
                                    ModifyDNOperation modifyDNOperation)
          throws DirectoryException
   {
-    LocalizableMessage message = ERR_TASKBE_MODIFY_DN_NOT_SUPPORTED.get();
-    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
+    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
+        ERR_BACKEND_MODIFY_DN_NOT_SUPPORTED.get(currentDN, getBackendID()));
   }
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void search(SearchOperation searchOperation)
          throws DirectoryException, CanceledOperationException {
     // Look at the base DN and scope for the search operation to decide which
@@ -928,9 +890,8 @@
                                          scheduledTaskParentDN, null);
           }
 
-          if (((searchScope == SearchScope.BASE_OBJECT) ||
-               (searchScope == SearchScope.WHOLE_SUBTREE)) &&
-              searchFilter.matchesEntry(e))
+          if ((searchScope == SearchScope.BASE_OBJECT || searchScope == SearchScope.WHOLE_SUBTREE)
+              && searchFilter.matchesEntry(e))
           {
             searchOperation.returnEntry(e, null);
           }
@@ -956,9 +917,8 @@
                                          recurringTaskParentDN, null);
           }
 
-          if (((searchScope == SearchScope.BASE_OBJECT) ||
-               (searchScope == SearchScope.WHOLE_SUBTREE)) &&
-              searchFilter.matchesEntry(e))
+          if ((searchScope == SearchScope.BASE_OBJECT || searchScope == SearchScope.WHOLE_SUBTREE)
+              && searchFilter.matchesEntry(e))
           {
             searchOperation.returnEntry(e, null);
           }
@@ -981,12 +941,9 @@
     if (searchRoot)
     {
       Entry e = taskScheduler.getTaskRootEntry();
-      if (searchFilter.matchesEntry(e))
+      if (searchFilter.matchesEntry(e) && !searchOperation.returnEntry(e, null))
       {
-        if (! searchOperation.returnEntry(e, null))
-        {
-          return;
-        }
+        return;
       }
     }
 
@@ -994,75 +951,59 @@
     if (searchScheduledParent)
     {
       Entry e = taskScheduler.getScheduledTaskParentEntry();
-      if (searchFilter.matchesEntry(e))
+      if (searchFilter.matchesEntry(e) && !searchOperation.returnEntry(e, null))
       {
-        if (! searchOperation.returnEntry(e, null))
-        {
-          return;
-        }
+        return;
       }
     }
 
 
-    if (searchScheduledTasks)
+    if (searchScheduledTasks
+        && !taskScheduler.searchScheduledTasks(searchOperation))
     {
-      if (! taskScheduler.searchScheduledTasks(searchOperation))
-      {
-        return;
-      }
+      return;
     }
 
 
     if (searchRecurringParent)
     {
       Entry e = taskScheduler.getRecurringTaskParentEntry();
-      if (searchFilter.matchesEntry(e))
-      {
-        if (! searchOperation.returnEntry(e, null))
-        {
-          return;
-        }
-      }
-    }
-
-
-    if (searchRecurringTasks)
-    {
-      if (! taskScheduler.searchRecurringTasks(searchOperation))
+      if (searchFilter.matchesEntry(e) && !searchOperation.returnEntry(e, null))
       {
         return;
       }
     }
+
+
+    if (searchRecurringTasks
+        && !taskScheduler.searchRecurringTasks(searchOperation))
+    {
+      return;
+    }
   }
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
-  public HashSet<String> getSupportedControls()
+  /** {@inheritDoc} */
+  @Override
+  public Set<String> getSupportedControls()
   {
-    return supportedControls;
+    return Collections.emptySet();
   }
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
-  public HashSet<String> getSupportedFeatures()
+  /** {@inheritDoc} */
+  @Override
+  public Set<String> getSupportedFeatures()
   {
-    return supportedFeatures;
+    return Collections.emptySet();
   }
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean supportsLDIFExport()
   {
     // LDIF exports are supported.
@@ -1071,10 +1012,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void exportLDIF(LDIFExportConfig exportConfig)
          throws DirectoryException
   {
@@ -1143,82 +1082,47 @@
     }
     finally
     {
-      try
-      {
-        ldifWriter.close();
-      }
-      catch (Exception e)
-      {
-        logger.traceException(e);
-      }
-      try
-      {
-        ldifReader.close();
-      }
-      catch (Exception e)
-      {
-        logger.traceException(e);
-      }
+      close(ldifWriter, ldifReader);
     }
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean supportsLDIFImport()
   {
-    // This backend does not support LDIF imports.
     return false;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public LDIFImportResult importLDIF(LDIFImportConfig importConfig)
          throws DirectoryException
   {
-    // This backend does not support LDIF imports.
-    LocalizableMessage message = ERR_TASKBE_IMPORT_NOT_SUPPORTED.get();
-    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
+    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
+        ERR_BACKEND_IMPORT_NOT_SUPPORTED.get(getBackendID()));
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean supportsBackup()
   {
-    // This backend does provide a backup/restore mechanism.
     return true;
   }
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean supportsBackup(BackupConfig backupConfig,
                                 StringBuilder unsupportedReason)
   {
-    // This backend does provide a backup/restore mechanism.
     return true;
   }
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void createBackup(BackupConfig backupConfig)
          throws DirectoryException
   {
@@ -1415,16 +1319,7 @@
       inputStream.close();
     } catch (Exception e) {
       logger.traceException(e);
-
-      try {
-        inputStream.close();
-      } catch (Exception e2) {
-      }
-
-      try {
-        zipStream.close();
-      } catch (Exception e2) {
-      }
+      close(inputStream, zipStream);
 
       message = ERR_TASKS_BACKUP_CANNOT_BACKUP_TASKS_FILE.get(baseName,
         stackTraceToSingleLineString(e));
@@ -1492,10 +1387,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void removeBackup(BackupDirectory backupDirectory,
                            String backupID)
          throws DirectoryException
@@ -1546,10 +1439,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean supportsRestore()
   {
     // This backend does provide a backup/restore mechanism.
@@ -1558,10 +1449,8 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void restoreBackup(RestoreConfig restoreConfig)
          throws DirectoryException
   {
@@ -1874,22 +1763,17 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
-  public boolean isConfigurationAcceptable(Configuration configuration,
+  /** {@inheritDoc} */
+  @Override
+  public boolean isConfigurationAcceptable(TaskBackendCfg config,
                                            List<LocalizableMessage> unacceptableReasons)
   {
-    TaskBackendCfg config = (TaskBackendCfg) configuration;
     return isConfigAcceptable(config, unacceptableReasons, null);
   }
 
 
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public boolean isConfigurationChangeAcceptable(TaskBackendCfg configEntry,
                                             List<LocalizableMessage> unacceptableReasons)
@@ -1925,8 +1809,8 @@
     try
     {
       String tmpBackingFile = config.getTaskBackingFile();
-      if ((taskBackingFile == null) ||
-          (! taskBackingFile.equals(tmpBackingFile)))
+      if (taskBackingFile == null ||
+          !taskBackingFile.equals(tmpBackingFile))
       {
         File f = getFileForPath(tmpBackingFile);
         if (f.exists())
@@ -1981,9 +1865,7 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public ConfigChangeResult applyConfigurationChange(TaskBackendCfg configEntry)
   {
@@ -2213,9 +2095,7 @@
 
 
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public void preloadEntryCache() throws UnsupportedOperationException {
     throw new UnsupportedOperationException("Operation not supported.");

--
Gitblit v1.10.0