| | |
| | | |
| | | |
| | | 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.*; |
| | |
| | | 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 |
| | |
| | | |
| | | |
| | | |
| | | |
| | | // 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; |
| | | |
| | |
| | | this.taskScheduler = taskScheduler; |
| | | this.threadID = threadID; |
| | | |
| | | task = null; |
| | | notifyLock = new Object(); |
| | | exitRequested = false; |
| | | |
| | | setAssociatedTask(null); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public Task getTask() |
| | | { |
| | | return task; |
| | | return getAssociatedTask(); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public void setTask(Task task) |
| | | { |
| | | this.task = task; |
| | | setAssociatedTask(task); |
| | | |
| | | synchronized (notifyLock) |
| | | { |
| | |
| | | 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) |
| | | { |
| | |
| | | { |
| | | while (! exitRequested) |
| | | { |
| | | if (task == null) |
| | | if (getAssociatedTask() == null) |
| | | { |
| | | try |
| | | { |
| | |
| | | |
| | | try |
| | | { |
| | | TaskState returnState = task.execute(); |
| | | task.setTaskState(returnState); |
| | | TaskState returnState = getAssociatedTask().execute(); |
| | | getAssociatedTask().setTaskState(returnState); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | 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; |
| | |
| | | } |
| | | } |
| | | |
| | | 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. |
| | |
| | | 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; |
| | | } |