From eee90cc3e34f4e5a7d562ee9e60c66a61816985c Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Tue, 16 Oct 2007 20:19:45 +0000
Subject: [PATCH] Issue 2368: tasks should be interruptable. The four schedulable task (import-ldif, export-ldif, backup, and restore) can now be interrupted for purposes of cancellation. The manage-tasks utility now allows the user to cancel any one of these tasks if they are currently running. If interrupted while executing, the tasks try to break out of their work loop as soon as possible and return a 'stopped by administrator' status. Both the backup and export-ldif tasks perform some cleanup (removing the abandoned backup or exported LDIF file) if they are cancelled.
---
opends/src/server/org/opends/server/tasks/ImportTask.java | 30 ++++++++++++++++++++++++++++--
1 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/opends/src/server/org/opends/server/tasks/ImportTask.java b/opends/src/server/org/opends/server/tasks/ImportTask.java
index 2d451dc..5b3410e 100644
--- a/opends/src/server/org/opends/server/tasks/ImportTask.java
+++ b/opends/src/server/org/opends/server/tasks/ImportTask.java
@@ -26,6 +26,7 @@
*/
package org.opends.server.tasks;
import org.opends.messages.Message;
+import org.opends.messages.TaskMessages;
import static org.opends.messages.TaskMessages.*;
import static org.opends.messages.ToolMessages.*;
@@ -169,6 +170,7 @@
ArrayList<String> includeFilterStrings = null;
ArrayList<String> ldifFiles = null;
+ private LDIFImportConfig importConfig;
/**
* {@inheritDoc}
@@ -482,6 +484,30 @@
}
+ /**
+ * {@inheritDoc}
+ */
+ public void interruptTask(TaskState interruptState, Message interruptReason)
+ {
+ if (TaskState.STOPPED_BY_ADMINISTRATOR.equals(interruptState) &&
+ importConfig != null)
+ {
+ addLogMessage(TaskMessages.INFO_TASK_STOPPED_BY_ADMIN.get(
+ interruptReason));
+ setTaskInterruptState(interruptState);
+ importConfig.cancel();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isInterruptable()
+ {
+ return true;
+ }
+
/**
* {@inheritDoc}
@@ -731,7 +757,7 @@
// Create the LDIF import configuration to use when reading the LDIF.
ArrayList<String> fileList = new ArrayList<String>(ldifFiles);
- LDIFImportConfig importConfig = new LDIFImportConfig(fileList);
+ importConfig = new LDIFImportConfig(fileList);
importConfig.setAppendToExistingData(append);
importConfig.setReplaceExistingEntries(replaceExisting);
importConfig.setCompressed(isCompressed);
@@ -942,6 +968,6 @@
// Clean up after the import by closing the import config.
importConfig.close();
- return TaskState.COMPLETED_SUCCESSFULLY;
+ return getFinalTaskState();
}
}
--
Gitblit v1.10.0