From 17ec2cfa9d04e6942a694ab5c3778ac26f17bb35 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 19 Apr 2016 12:59:39 +0000
Subject: [PATCH] code cleanup
---
opendj-server-legacy/src/main/java/org/opends/server/backends/task/TaskBackend.java | 193 +++++++++---------------------------------------
1 files changed, 36 insertions(+), 157 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/task/TaskBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/task/TaskBackend.java
index e1edd45..3a8d2ee 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/task/TaskBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/task/TaskBackend.java
@@ -36,6 +36,7 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.server.ConfigChangeResult;
import org.forgerock.opendj.config.server.ConfigException;
+import org.forgerock.opendj.config.server.ConfigurationChangeListener;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
import org.forgerock.opendj.ldap.DN;
@@ -43,9 +44,8 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.schema.AttributeType;
-import org.forgerock.util.Reject;
-import org.forgerock.opendj.config.server.ConfigurationChangeListener;
import org.forgerock.opendj.server.config.server.TaskBackendCfg;
+import org.forgerock.util.Reject;
import org.opends.server.api.Backend;
import org.opends.server.api.Backupable;
import org.opends.server.core.AddOperation;
@@ -85,29 +85,17 @@
extends Backend<TaskBackendCfg>
implements ConfigurationChangeListener<TaskBackendCfg>, Backupable
{
-
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
-
-
/** The current configuration state. */
private TaskBackendCfg currentConfig;
-
/** 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. */
private DN taskRootDN;
@@ -125,11 +113,7 @@
/** 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;
private ServerContext serverContext;
@@ -146,8 +130,6 @@
// Perform all initialization in initializeBackend.
}
-
-
@Override
public void configureBackend(TaskBackendCfg cfg, ServerContext serverContext) throws ConfigException
{
@@ -206,12 +188,10 @@
}
}
-
// Get the retention time that will be used to determine how long task
// information stays around once the associated task is completed.
retentionTime = cfg.getTaskRetentionTime();
-
// Get the notification sender address.
notificationSenderAddress = cfg.getNotificationSenderAddress();
if (notificationSenderAddress == null)
@@ -227,16 +207,12 @@
}
}
-
// Get the path to the task data backing file.
taskBackingFile = cfg.getTaskBackingFile();
currentConfig = cfg;
}
-
-
- /** {@inheritDoc} */
@Override
public void openBackend()
throws ConfigException, InitializationException
@@ -245,11 +221,9 @@
taskScheduler = new TaskScheduler(serverContext, this);
taskScheduler.start();
-
// Register with the Directory Server as a configurable component.
currentConfig.addTaskChangeListener(this);
-
// Register the task base as a private suffix.
try
{
@@ -265,9 +239,6 @@
}
}
-
-
- /** {@inheritDoc} */
@Override
public void closeBackend()
{
@@ -321,9 +292,6 @@
return -1;
}
-
-
- /** {@inheritDoc} */
@Override
public boolean isIndexed(AttributeType attributeType, IndexType indexType)
{
@@ -331,9 +299,6 @@
return true;
}
-
-
- /** {@inheritDoc} */
@Override
public ConditionResult hasSubordinates(DN entryDN)
throws DirectoryException
@@ -346,14 +311,12 @@
return ConditionResult.valueOf(ret != 0);
}
- /** {@inheritDoc} */
@Override
public long getNumberOfEntriesInBaseDN(DN baseDN) throws DirectoryException {
checkNotNull(baseDN, "baseDN must not be null");
return numSubordinates(baseDN, true) + 1;
}
- /** {@inheritDoc} */
@Override
public long getNumberOfChildren(DN parentDN) throws DirectoryException {
checkNotNull(parentDN, "parentDN must not be null");
@@ -411,9 +374,6 @@
}
}
-
-
- /** {@inheritDoc} */
@Override
public Entry getEntry(DN entryDN)
throws DirectoryException
@@ -466,9 +426,6 @@
}
}
-
-
- /** {@inheritDoc} */
@Override
public void addEntry(Entry entry, AddOperation addOperation)
throws DirectoryException
@@ -510,9 +467,6 @@
throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
}
-
-
- /** {@inheritDoc} */
@Override
public void deleteEntry(DN entryDN, DeleteOperation deleteOperation)
throws DirectoryException
@@ -535,7 +489,6 @@
throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message);
}
-
// Look at the state of the task. We will allow pending and completed
// tasks to be removed, but not running tasks.
TaskState state = t.getTaskState();
@@ -585,9 +538,6 @@
}
}
-
-
- /** {@inheritDoc} */
@Override
public void replaceEntry(Entry oldEntry, Entry newEntry,
ModifyOperation modifyOperation) throws DirectoryException
@@ -685,7 +635,7 @@
LocalizableMessage message = INFO_TASKBE_RUNNING_TASK_CANCELLED.get();
t.interruptTask(TaskState.STOPPED_BY_ADMINISTRATOR, message);
}
- return;
+ return;
}
else
{
@@ -720,8 +670,6 @@
}
}
-
-
/**
* Helper to determine if requested modifications are acceptable.
* @param modifyOperation associated with requested modifications.
@@ -765,9 +713,6 @@
return true;
}
-
-
- /** {@inheritDoc} */
@Override
public void renameEntry(DN currentDN, Entry entry,
ModifyDNOperation modifyDNOperation)
@@ -777,9 +722,6 @@
ERR_BACKEND_MODIFY_DN_NOT_SUPPORTED.get(currentDN, getBackendID()));
}
-
-
- /** {@inheritDoc} */
@Override
public void search(SearchOperation searchOperation)
throws DirectoryException, CanceledOperationException {
@@ -926,7 +868,6 @@
}
}
-
if (searchRoot)
{
Entry e = taskScheduler.getTaskRootEntry();
@@ -936,7 +877,6 @@
}
}
-
if (searchScheduledParent)
{
Entry e = taskScheduler.getScheduledTaskParentEntry();
@@ -946,14 +886,12 @@
}
}
-
if (searchScheduledTasks
&& !taskScheduler.searchScheduledTasks(searchOperation))
{
return;
}
-
if (searchRecurringParent)
{
Entry e = taskScheduler.getRecurringTaskParentEntry();
@@ -963,7 +901,6 @@
}
}
-
if (searchRecurringTasks
&& !taskScheduler.searchRecurringTasks(searchOperation))
{
@@ -971,23 +908,18 @@
}
}
-
-
- /** {@inheritDoc} */
@Override
public Set<String> getSupportedControls()
{
return Collections.emptySet();
}
- /** {@inheritDoc} */
@Override
public Set<String> getSupportedFeatures()
{
return Collections.emptySet();
}
- /** {@inheritDoc} */
@Override
public boolean supports(BackendOperation backendOperation)
{
@@ -1003,44 +935,15 @@
}
}
- /** {@inheritDoc} */
@Override
- public void exportLDIF(LDIFExportConfig exportConfig)
- throws DirectoryException
+ public void exportLDIF(LDIFExportConfig exportConfig) throws DirectoryException
{
File taskFile = getFileForPath(taskBackingFile);
- // Read from.
- LDIFReader ldifReader;
- try
+ try (LDIFReader ldifReader = newLDIFReader(taskFile);
+ LDIFWriter ldifWriter = newLDIFWriter(exportConfig))
{
- ldifReader = new LDIFReader(new LDIFImportConfig(taskFile.getPath()));
- }
- catch (Exception e)
- {
- LocalizableMessage message = ERR_TASKS_CANNOT_EXPORT_TO_FILE.get(e);
- throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message, e);
- }
-
- // Write to.
- LDIFWriter ldifWriter;
- try
- {
- ldifWriter = new LDIFWriter(exportConfig);
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- LocalizableMessage message = ERR_TASKS_CANNOT_EXPORT_TO_FILE.get(
- stackTraceToSingleLineString(e));
- throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
- message);
- }
-
- // Copy record by record.
- try
- {
+ // Copy record by record.
while (true)
{
Entry e = null;
@@ -1054,7 +957,7 @@
}
catch (LDIFException le)
{
- if (! le.canContinueReading())
+ if (!le.canContinueReading())
{
LocalizableMessage message = ERR_TASKS_CANNOT_EXPORT_TO_FILE.get(e);
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message, le);
@@ -1068,13 +971,35 @@
{
logger.traceException(e);
}
- finally
+ }
+
+ private LDIFReader newLDIFReader(File taskFile) throws DirectoryException
+ {
+ try
{
- close(ldifWriter, ldifReader);
+ return new LDIFReader(new LDIFImportConfig(taskFile.getPath()));
+ }
+ catch (Exception e)
+ {
+ LocalizableMessage message = ERR_TASKS_CANNOT_EXPORT_TO_FILE.get(e);
+ throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message, e);
}
}
- /** {@inheritDoc} */
+ private LDIFWriter newLDIFWriter(LDIFExportConfig exportConfig) throws DirectoryException
+ {
+ try
+ {
+ return new LDIFWriter(exportConfig);
+ }
+ catch (Exception e)
+ {
+ logger.traceException(e);
+ LocalizableMessage message = ERR_TASKS_CANNOT_EXPORT_TO_FILE.get(stackTraceToSingleLineString(e));
+ throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
+ }
+ }
+
@Override
public LDIFImportResult importLDIF(LDIFImportConfig importConfig, ServerContext sContext) throws DirectoryException
{
@@ -1082,28 +1007,24 @@
ERR_BACKEND_IMPORT_NOT_SUPPORTED.get(getBackendID()));
}
- /** {@inheritDoc} */
@Override
public void createBackup(BackupConfig backupConfig) throws DirectoryException
{
new BackupManager(getBackendID()).createBackup(this, backupConfig);
}
- /** {@inheritDoc} */
@Override
public void removeBackup(BackupDirectory backupDirectory, String backupID) throws DirectoryException
{
new BackupManager(getBackendID()).removeBackup(backupDirectory, backupID);
}
- /** {@inheritDoc} */
@Override
public void restoreBackup(RestoreConfig restoreConfig) throws DirectoryException
{
new BackupManager(getBackendID()).restoreBackup(this, restoreConfig);
}
- /** {@inheritDoc} */
@Override
public boolean isConfigurationAcceptable(TaskBackendCfg config,
List<LocalizableMessage> unacceptableReasons,
@@ -1112,9 +1033,6 @@
return isConfigAcceptable(config, unacceptableReasons, null);
}
-
-
- /** {@inheritDoc} */
@Override
public boolean isConfigurationChangeAcceptable(TaskBackendCfg configEntry,
List<LocalizableMessage> unacceptableReasons)
@@ -1123,8 +1041,6 @@
taskBackingFile);
}
-
-
/**
* Indicates whether the provided configuration is acceptable for this task
* backend.
@@ -1146,7 +1062,6 @@
{
boolean configIsAcceptable = true;
-
try
{
String tmpBackingFile = config.getTaskBackingFile();
@@ -1204,15 +1119,11 @@
return configIsAcceptable;
}
-
-
- /** {@inheritDoc} */
@Override
public ConfigChangeResult applyConfigurationChange(TaskBackendCfg configEntry)
{
final ConfigChangeResult ccr = new ConfigChangeResult();
-
String tmpBackingFile = taskBackingFile;
try
{
@@ -1256,10 +1167,8 @@
ccr.setResultCode(DirectoryServer.getServerErrorResultCode());
}
-
long tmpRetentionTime = configEntry.getTaskRetentionTime();
-
if (ccr.getResultCode() == ResultCode.SUCCESS)
{
// Everything looks OK, so apply the changes.
@@ -1270,7 +1179,6 @@
ccr.addMessage(INFO_TASKBE_UPDATED_RETENTION_TIME.get(retentionTime));
}
-
if (! taskBackingFile.equals(tmpBackingFile))
{
taskBackingFile = tmpBackingFile;
@@ -1280,7 +1188,6 @@
}
}
-
String tmpNotificationAddress = configEntry.getNotificationSenderAddress();
if (tmpNotificationAddress == null)
{
@@ -1296,13 +1203,10 @@
}
notificationSenderAddress = tmpNotificationAddress;
-
currentConfig = configEntry;
return ccr;
}
-
-
/**
* Retrieves the DN of the configuration entry for this task backend.
*
@@ -1313,8 +1217,6 @@
return configEntryDN;
}
-
-
/**
* Retrieves the path to the backing file that will hold the scheduled and
* recurring task definitions.
@@ -1328,8 +1230,6 @@
return f.getPath();
}
-
-
/**
* Retrieves the sender address that should be used for e-mail notifications
* of task completion.
@@ -1342,8 +1242,6 @@
return notificationSenderAddress;
}
-
-
/**
* Retrieves the length of time in seconds that information for a task should
* be retained after processing on it has completed.
@@ -1356,8 +1254,6 @@
return retentionTime;
}
-
-
/**
* Retrieves the DN of the entry that is the root for all task information in
* the Directory Server.
@@ -1370,8 +1266,6 @@
return taskRootDN;
}
-
-
/**
* Retrieves the DN of the entry that is the immediate parent for all
* recurring task information in the Directory Server.
@@ -1384,8 +1278,6 @@
return recurringTaskParentDN;
}
-
-
/**
* Retrieves the DN of the entry that is the immediate parent for all
* scheduled task information in the Directory Server.
@@ -1398,8 +1290,6 @@
return scheduledTaskParentDN;
}
-
-
/**
* Retrieves the scheduled task for the entry with the provided DN.
*
@@ -1413,8 +1303,6 @@
return taskScheduler.getScheduledTask(taskEntryDN);
}
-
-
/**
* Retrieves the recurring task for the entry with the provided DN.
*
@@ -1429,9 +1317,6 @@
return taskScheduler.getRecurringTask(taskEntryDN);
}
-
-
- /** {@inheritDoc} */
@Override
public File getDirectory()
{
@@ -1450,21 +1335,18 @@
};
}
- /** {@inheritDoc} */
@Override
public ListIterator<Path> getFilesToBackup() throws DirectoryException
{
return BackupManager.getFiles(getDirectory(), getFilesToBackupFilter(), getBackendID()).listIterator();
}
- /** {@inheritDoc} */
@Override
public boolean isDirectRestore()
{
return true;
}
- /** {@inheritDoc} */
@Override
public Path beforeRestore() throws DirectoryException
{
@@ -1472,13 +1354,10 @@
return BackupManager.saveCurrentFilesToDirectory(this, getBackendID());
}
- /** {@inheritDoc} */
@Override
public void afterRestore(Path restoreDirectory, Path saveDirectory) throws DirectoryException
{
// restore was successful, delete the save directory
StaticUtils.recursiveDelete(saveDirectory.toFile());
}
-
}
-
--
Gitblit v1.10.0