From 4fe1767665733394131391080c5c101738a6651c Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Tue, 03 Mar 2015 23:18:53 +0000
Subject: [PATCH] Minor pluggable backend code cleanup:
---
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java | 70 ++++++++++++++++++++---------------
1 files changed, 40 insertions(+), 30 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java
index 5dfb6f4..65d285c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java
@@ -32,7 +32,6 @@
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
-import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ExecutionException;
@@ -61,10 +60,13 @@
import org.opends.server.types.*;
/**
- * This is an implementation of a Directory Server Backend which stores entries
- * locally in a Berkeley DB JE database.
+ * This is an implementation of a Directory Server Backend which stores entries locally in a
+ * Berkeley DB JE database.
+ *
+ * @param <C>
+ * the type of the BackendCfg for the current backend
*/
-public abstract class BackendImpl extends Backend<PluggableBackendCfg> implements
+public abstract class BackendImpl<C extends PluggableBackendCfg> extends Backend<C> implements
ConfigurationChangeListener<PluggableBackendCfg>
{
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
@@ -81,6 +83,10 @@
private DN[] baseDNs;
private MonitorProvider<?> rootContainerMonitor;
+
+ /** The underlying storage engine. */
+ private Storage storage;
+
/** The controls supported by this backend. */
private static final Set<String> supportedControls = new HashSet<String>(Arrays.asList(
OID_SUBTREE_DELETE_CONTROL,
@@ -138,12 +144,13 @@
/** {@inheritDoc} */
@Override
- public void configureBackend(PluggableBackendCfg cfg) throws ConfigException
+ public void configureBackend(C cfg) throws ConfigException
{
Reject.ifNull(cfg);
this.cfg = cfg;
baseDNs = this.cfg.getBaseDN().toArray(new DN[0]);
+ storage = configureStorage(cfg);
}
/** {@inheritDoc} */
@@ -292,8 +299,16 @@
@Override
public boolean supports(BackendOperation backendOperation)
{
- // it supports all the operations so far
- return true;
+ switch (backendOperation)
+ {
+ case BACKUP:
+ case RESTORE:
+ // Responsibility of the underlying storage.
+ return storage.supportsBackupAndRestore();
+ default: // INDEXING, LDIF_EXPORT, LDIF_IMPORT
+ // Responsibility of this pluggable backend.
+ return true;
+ }
}
/** {@inheritDoc} */
@@ -754,49 +769,39 @@
@Override
public void createBackup(BackupConfig backupConfig) throws DirectoryException
{
- BackupManager backupManager = new BackupManager(getBackendID());
- File backendDir = getBackupDirectory(cfg);
- Storage storage = newStorageInstance();
- backupConfig.setFilesToBackupFilter(storage.getFilesToBackupFilter());
- backupManager.createBackup(backendDir, backupConfig);
+ new BackupManager(getBackendID()).createBackup(storage, backupConfig);
}
- /**
- * Returns the storage corresponding to the backend class defined in the configuration.
- * @return the storage corresponding to the backend class defined in the configuration
- */
- protected abstract Storage newStorageInstance();
-
/** {@inheritDoc} */
@Override
public void removeBackup(BackupDirectory backupDirectory, String backupID)
throws DirectoryException
{
- BackupManager backupManager = new BackupManager(getBackendID());
- backupManager.removeBackup(backupDirectory, backupID);
+ new BackupManager(getBackendID()).removeBackup(backupDirectory, backupID);
}
/** {@inheritDoc} */
@Override
- public void restoreBackup(RestoreConfig restoreConfig)
- throws DirectoryException
+ public void restoreBackup(RestoreConfig restoreConfig) throws DirectoryException
{
- BackupManager backupManager = new BackupManager(getBackendID());
- File backendDir = getBackupDirectory(cfg);
- backupManager.restoreBackup(backendDir, restoreConfig);
+ new BackupManager(getBackendID()).restoreBackup(storage, restoreConfig);
}
/**
- * Returns the backup directory.
+ * Creates the storage engine which will be used by this pluggable backend. Implementations should
+ * create and configure a new storage engine but not open it.
*
- * @param cfg the configuration for this backend
- * @return the backup directory
+ * @param cfg
+ * the configuration object
+ * @return The storage engine to be used by this pluggable backend.
+ * @throws ConfigException
+ * If there is an error in the configuration.
*/
- protected abstract File getBackupDirectory(PluggableBackendCfg cfg);
+ protected abstract Storage configureStorage(C cfg) throws ConfigException;
/** {@inheritDoc} */
@Override
- public boolean isConfigurationAcceptable(PluggableBackendCfg config, List<LocalizableMessage> unacceptableReasons)
+ public boolean isConfigurationAcceptable(C config, List<LocalizableMessage> unacceptableReasons)
{
return isConfigurationChangeAcceptable(config, unacceptableReasons);
}
@@ -969,4 +974,9 @@
EntryCachePreloader preloader = new EntryCachePreloader(this);
preloader.preload();
}
+
+ Storage getStorage()
+ {
+ return storage;
+ }
}
--
Gitblit v1.10.0