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/MonitorBackend.java |  368 +++++++++++++--------------------------------------
 1 files changed, 97 insertions(+), 271 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/MonitorBackend.java b/opendj3-server-dev/src/server/org/opends/server/backends/MonitorBackend.java
index 8a942f1..10ef54c 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/MonitorBackend.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/MonitorBackend.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2012-2014 ForgeRock AS.
+ *      Portions copyright 2012-2014 ForgeRock AS.
  */
 package org.opends.server.backends;
 
@@ -34,7 +34,6 @@
 import org.forgerock.opendj.ldap.ConditionResult;
 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.MonitorBackendCfg;
 import org.opends.server.api.Backend;
@@ -60,38 +59,31 @@
  * requested monitor and dynamically generate the associated entry. It will also
  * construct a base monitor entry with some useful server-wide data.
  */
-public class MonitorBackend extends Backend implements
+public class MonitorBackend extends Backend<MonitorBackendCfg> implements
     ConfigurationChangeListener<MonitorBackendCfg>
 {
   private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
-  // The set of user-defined attributes that will be included in the base
-  // monitor entry.
+  /** The set of user-defined attributes that will be included in the base
+   * monitor entry.
+   */
   private ArrayList<Attribute> userDefinedAttributes;
 
-  // The set of objectclasses that will be used in monitor entries.
+  /** The set of objectclasses that will be used in monitor entries. */
   private HashMap<ObjectClass, String> monitorObjectClasses;
 
-  // The DN of the configuration entry for this backend.
+  /** The DN of the configuration entry for this backend. */
   private DN configEntryDN;
 
-  // The current configuration state.
+  /** The current configuration state. */
   private MonitorBackendCfg currentConfig;
 
-  // The DN for the base monitor entry.
+  /** The DN for the base monitor entry. */
   private DN baseMonitorDN;
 
-  // The set of base DNs for this backend.
+  /** The set of base DNs 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;
-
-
-
   /**
    * Creates a new backend with the provided information. All backend
    * implementations must implement a default constructor that use
@@ -102,24 +94,16 @@
     super();
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void addEntry(final Entry entry, final AddOperation addOperation)
       throws DirectoryException
   {
     throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
-        ERR_MONITOR_ADD_NOT_SUPPORTED.get(entry.getName()));
+        ERR_BACKEND_ADD_NOT_SUPPORTED.get(entry.getName(), getBackendID()));
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public ConfigChangeResult applyConfigurationChange(
       final MonitorBackendCfg backendCfg)
@@ -175,19 +159,14 @@
     return new ConfigChangeResult(resultCode, adminActionRequired, messages);
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
-  public void configureBackend(final Configuration config)
+  /** {@inheritDoc} */
+  @Override
+  public void configureBackend(final MonitorBackendCfg config)
       throws ConfigException
   {
     Reject.ifNull(config);
-    Reject.ifFalse(config instanceof MonitorBackendCfg);
 
-    final MonitorBackendCfg cfg = (MonitorBackendCfg) config;
+    final MonitorBackendCfg cfg = config;
     final ConfigEntry configEntry = DirectoryServer.getConfigEntry(cfg.dn());
 
     // Make sure that a configuration entry was provided. If not, then we will
@@ -236,10 +215,6 @@
         OC_MONITOR_ENTRY, true);
     monitorObjectClasses.put(monitorOC, OC_MONITOR_ENTRY);
 
-    // Define an empty sets for the supported controls and features.
-    supportedControls = new HashSet<String>(0);
-    supportedFeatures = new HashSet<String>(0);
-
     // Create the set of base DNs that we will handle. In this case, it's just
     // the DN of the base monitor entry.
     try
@@ -261,50 +236,33 @@
     currentConfig = cfg;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void createBackup(final BackupConfig backupConfig)
       throws DirectoryException
   {
-    // This backend does not provide a backup/restore mechanism.
-    final LocalizableMessage message = ERR_MONITOR_BACKUP_AND_RESTORE_NOT_SUPPORTED.get();
-    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
+    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
+        ERR_BACKEND_BACKUP_AND_RESTORE_NOT_SUPPORTED.get(getBackendID()));
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void deleteEntry(final DN entryDN,
       final DeleteOperation deleteOperation) throws DirectoryException
   {
     throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
-        ERR_MONITOR_DELETE_NOT_SUPPORTED.get(entryDN));
+        ERR_BACKEND_DELETE_NOT_SUPPORTED.get(entryDN, getBackendID()));
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean entryExists(final DN entryDN) throws DirectoryException
   {
     return getDIT().containsKey(entryDN);
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void exportLDIF(final LDIFExportConfig exportConfig)
       throws DirectoryException
   {
@@ -335,14 +293,7 @@
     {
       logger.traceException(e);
 
-      try
-      {
-        ldifWriter.close();
-      }
-      catch (final Exception e2)
-      {
-        logger.traceException(e2);
-      }
+      close(ldifWriter);
 
       final LocalizableMessage message = ERR_MONITOR_UNABLE_TO_EXPORT_BASE
           .get(stackTraceToSingleLineString(e));
@@ -363,14 +314,7 @@
       {
         logger.traceException(e);
 
-        try
-        {
-          ldifWriter.close();
-        }
-        catch (final Exception e2)
-        {
-          logger.traceException(e2);
-        }
+        close(ldifWriter);
 
         final LocalizableMessage message = ERR_MONITOR_UNABLE_TO_EXPORT_PROVIDER_ENTRY
             .get(monitorProvider.getMonitorInstanceName(),
@@ -380,23 +324,11 @@
       }
     }
 
-    // Close the monitor provider and return.
-    try
-    {
-      ldifWriter.close();
-    }
-    catch (final Exception e)
-    {
-      logger.traceException(e);
-    }
+    close(ldifWriter);
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void finalizeBackend()
   {
     currentConfig.removeMonitorChangeListener(this);
@@ -410,31 +342,22 @@
     }
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public DN[] getBaseDNs()
   {
     return baseDNs;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public Entry getEntry(final DN entryDN) throws DirectoryException
   {
     // If the requested entry was null, then throw an exception.
     if (entryDN == null)
     {
-      final LocalizableMessage message = ERR_MONITOR_GET_ENTRY_NULL.get();
       throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
-          message);
+          ERR_BACKEND_GET_ENTRY_NULL.get(getBackendID()));
     }
 
     // If the requested entry was the monitor base entry, then retrieve it
@@ -456,45 +379,29 @@
     return getEntry(entryDN, dit);
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public long getEntryCount()
   {
     return getDIT().size();
   }
 
-
-
-  /**
-   * {@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 ConditionResult hasSubordinates(final DN entryDN)
       throws DirectoryException
   {
@@ -508,26 +415,17 @@
     return ConditionResult.UNDEFINED;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public LDIFImportResult importLDIF(final LDIFImportConfig importConfig)
       throws DirectoryException
   {
-    // This backend does not support LDIF imports.
-    final LocalizableMessage message = ERR_MONITOR_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 void initializeBackend() throws ConfigException,
       InitializationException
   {
@@ -549,11 +447,7 @@
     }
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public boolean isConfigurationChangeAcceptable(
       final MonitorBackendCfg backendCfg,
@@ -564,12 +458,8 @@
     return true;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean isIndexed(final AttributeType attributeType,
       final IndexType indexType)
   {
@@ -577,24 +467,16 @@
     return true;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean isLocal()
   {
     // For the purposes of this method, this is a local backend.
     return true;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public long numSubordinates(final DN entryDN, final boolean subtree)
       throws DirectoryException
   {
@@ -622,50 +504,33 @@
     }
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public void preloadEntryCache() throws UnsupportedOperationException
   {
     throw new UnsupportedOperationException("Operation not supported.");
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void removeBackup(final BackupDirectory backupDirectory,
       final String backupID) throws DirectoryException
   {
-    // This backend does not provide a backup/restore mechanism.
-    final LocalizableMessage message = ERR_MONITOR_BACKUP_AND_RESTORE_NOT_SUPPORTED.get();
-    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
+    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
+        ERR_BACKEND_BACKUP_AND_RESTORE_NOT_SUPPORTED.get(getBackendID()));
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void renameEntry(final DN currentDN, final Entry entry,
       final ModifyDNOperation modifyDNOperation) throws DirectoryException
   {
     throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
-        ERR_MONITOR_MODIFY_DN_NOT_SUPPORTED.get(currentDN));
+        ERR_BACKEND_MODIFY_DN_NOT_SUPPORTED.get(currentDN, getBackendID()));
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void replaceEntry(final Entry oldEntry, final Entry newEntry,
       final ModifyOperation modifyOperation) throws DirectoryException
   {
@@ -673,26 +538,17 @@
         ERR_MONITOR_MODIFY_NOT_SUPPORTED.get(newEntry.getName(), configEntryDN));
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void restoreBackup(final RestoreConfig restoreConfig)
       throws DirectoryException
   {
-    // This backend does not provide a backup/restore mechanism.
-    final LocalizableMessage message = ERR_MONITOR_BACKUP_AND_RESTORE_NOT_SUPPORTED.get();
-    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
+    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
+        ERR_BACKEND_BACKUP_AND_RESTORE_NOT_SUPPORTED.get(getBackendID()));
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public void search(final SearchOperation searchOperation)
       throws DirectoryException
   {
@@ -717,7 +573,7 @@
         }
         matchedDN = matchedDN.parent();
       }
-      final LocalizableMessage message = ERR_MEMORYBACKEND_ENTRY_DOESNT_EXIST.get(baseDN);
+      final LocalizableMessage message = ERR_BACKEND_ENTRY_DOESNT_EXIST.get(baseDN, getBackendID());
       throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message,
           matchedDN, null);
     }
@@ -743,37 +599,23 @@
     }
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean supportsBackup()
   {
-    // This backend does not provide a backup/restore mechanism.
     return false;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean supportsBackup(final BackupConfig backupConfig,
       final StringBuilder unsupportedReason)
   {
-    // This backend does not provide a backup/restore mechanism.
     return false;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean supportsLDIFExport()
   {
     // We can export all the monitor entries as a point-in-time snapshot.
@@ -782,27 +624,17 @@
     return false;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean supportsLDIFImport()
   {
-    // This backend does not support LDIF imports.
     return false;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
+  /** {@inheritDoc} */
+  @Override
   public boolean supportsRestore()
   {
-    // This backend does not provide a backup/restore mechanism.
     return false;
   }
 
@@ -890,13 +722,12 @@
     monitorUserAttrs.put(currentTimeAttr.getAttributeType(), currentTimeList);
 
     // Add the uptime as a human-readable string.
-    long upSeconds = ((System.currentTimeMillis() - DirectoryServer
-        .getStartTime()) / 1000);
-    final long upDays = (upSeconds / 86400);
+    long upSeconds = (System.currentTimeMillis() - DirectoryServer.getStartTime()) / 1000;
+    final long upDays = upSeconds / 86400;
     upSeconds %= 86400;
-    final long upHours = (upSeconds / 3600);
+    final long upHours = upSeconds / 3600;
     upSeconds %= 3600;
-    final long upMinutes = (upSeconds / 60);
+    final long upMinutes = upSeconds / 60;
     upSeconds %= 60;
     final LocalizableMessage upTimeStr = INFO_MONITOR_UPTIME.get(upDays, upHours,
         upMinutes, upSeconds);
@@ -1160,17 +991,12 @@
   private boolean isMonitorConfigAttribute(final Attribute attribute)
   {
     final AttributeType attrType = attribute.getAttributeType();
-    if (attrType.hasName(ATTR_COMMON_NAME)
+    return attrType.hasName(ATTR_COMMON_NAME)
         || attrType.hasName(ATTR_BACKEND_ENABLED.toLowerCase())
         || attrType.hasName(ATTR_BACKEND_CLASS.toLowerCase())
         || attrType.hasName(ATTR_BACKEND_BASE_DN.toLowerCase())
         || attrType.hasName(ATTR_BACKEND_ID.toLowerCase())
-        || attrType.hasName(ATTR_BACKEND_WRITABILITY_MODE.toLowerCase()))
-    {
-      return true;
-    }
-
-    return false;
+        || attrType.hasName(ATTR_BACKEND_WRITABILITY_MODE.toLowerCase());
   }
 
 }

--
Gitblit v1.10.0