From a0c742dc589e56e8b1a7498de1d165e039f58aac Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Mon, 30 Jul 2007 23:30:38 +0000
Subject: [PATCH] Update the task backend to provide a mechanism for sending e-mail messages to notify administrators whenever a given task has been completed. It is possible to specify a set of administrators that should be notified only if the task does not complete successfully, and/or a set of administrators that should be notified regardless of the task's success or failure. The basic framework for this capability has always been in place, and this change only provides the final implementation that actually generates and sends the e-mail message.
---
opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskThread.java | 50 ++++++++++++++++++++++++++++++--------------------
1 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskThread.java b/opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskThread.java
index 0b75daf..7f69593 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskThread.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskThread.java
@@ -29,11 +29,13 @@
import org.opends.server.api.DirectoryThread;
-import org.opends.server.types.ErrorLogSeverity;
-
-import static org.opends.server.loggers.debug.DebugLogger.*;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.types.DebugLogLevel;
+import org.opends.server.types.ErrorLogCategory;
+import org.opends.server.types.ErrorLogSeverity;
+
+import static org.opends.server.loggers.ErrorLogger.*;
+import static org.opends.server.loggers.debug.DebugLogger.*;
import static org.opends.server.messages.BackendMessages.*;
import static org.opends.server.messages.MessageHandler.*;
import static org.opends.server.util.StaticUtils.*;
@@ -41,6 +43,7 @@
import java.util.Map;
+
/**
* This class defines a thread that will be used to execute a scheduled task
* within the server and provide appropriate notification that the task is
@@ -56,16 +59,12 @@
-
// Indicates whether a request has been made for this thread to exit.
private boolean exitRequested;
// The thread ID for this task thread.
private int threadID;
- // The task currently being processed by this thread.
- private Task task;
-
// The reference to the scheduler with which this thread is associated.
private TaskScheduler taskScheduler;
@@ -90,9 +89,10 @@
this.taskScheduler = taskScheduler;
this.threadID = threadID;
- task = null;
notifyLock = new Object();
exitRequested = false;
+
+ setAssociatedTask(null);
}
@@ -106,7 +106,7 @@
*/
public Task getTask()
{
- return task;
+ return getAssociatedTask();
}
@@ -119,7 +119,7 @@
*/
public void setTask(Task task)
{
- this.task = task;
+ setAssociatedTask(task);
synchronized (notifyLock)
{
@@ -142,11 +142,11 @@
public void interruptTask(TaskState interruptState, String interruptReason,
boolean exitThread)
{
- if (task != null)
+ if (getAssociatedTask() != null)
{
try
{
- task.interruptTask(interruptState, interruptReason);
+ getAssociatedTask().interruptTask(interruptState, interruptReason);
}
catch (Exception e)
{
@@ -173,7 +173,7 @@
{
while (! exitRequested)
{
- if (task == null)
+ if (getAssociatedTask() == null)
{
try
{
@@ -195,8 +195,8 @@
try
{
- TaskState returnState = task.execute();
- task.setTaskState(returnState);
+ TaskState returnState = getAssociatedTask().execute();
+ getAssociatedTask().setTaskState(returnState);
}
catch (Exception e)
{
@@ -205,17 +205,20 @@
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
+ Task task = getAssociatedTask();
+
int msgID = MSGID_TASK_EXECUTE_FAILED;
String message = getMessage(msgID,
String.valueOf(task.getTaskEntry().getDN()),
stackTraceToSingleLineString(e));
- task.addLogMessage(ErrorLogSeverity.FATAL_ERROR, msgID, message);
+ logError(ErrorLogCategory.TASK, ErrorLogSeverity.FATAL_ERROR, message,
+ msgID);
task.setTaskState(TaskState.STOPPED_BY_ERROR);
}
- Task completedTask = task;
- task = null;
+ Task completedTask = getAssociatedTask();
+ setAssociatedTask(null);
if (! taskScheduler.threadDone(this, completedTask))
{
exitRequested = true;
@@ -223,13 +226,16 @@
}
}
- if (task != null)
+ if (getAssociatedTask() != null)
{
+ Task task = getAssociatedTask();
task.setTaskState(TaskState.STOPPED_BY_SHUTDOWN);
taskScheduler.threadDone(this, task);
}
}
+
+
/**
* Retrieves any relevent debug information with which this tread is
* associated so they can be included in debug messages.
@@ -239,7 +245,11 @@
public Map<String, String> getDebugProperties()
{
Map<String, String> properties = super.getDebugProperties();
- properties.put("task", task.toString());
+
+ if (getAssociatedTask() != null)
+ {
+ properties.put("task", getAssociatedTask().toString());
+ }
return properties;
}
--
Gitblit v1.10.0