| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions Copyright 2006 Sun Microsystems, Inc. |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | import org.opends.server.core.Operation; |
| | | import org.opends.server.types.CancelRequest; |
| | | import org.opends.server.types.CancelResult; |
| | | import org.opends.server.types.DebugLogCategory; |
| | | import org.opends.server.types.DebugLogSeverity; |
| | | import org.opends.server.types.DisconnectReason; |
| | | import org.opends.server.types.ErrorLogCategory; |
| | | import org.opends.server.types.ErrorLogSeverity; |
| | | |
| | | import static org.opends.server.loggers.Debug.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugCought; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugInfo; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugWarning; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.server.loggers.Error.*; |
| | | import static org.opends.server.messages.CoreMessages.*; |
| | | import static org.opends.server.messages.MessageHandler.*; |
| | |
| | | public class TraditionalWorkerThread |
| | | extends DirectoryThread |
| | | { |
| | | /** |
| | | * The fully-qualified name of this class for debugging purposes. |
| | | */ |
| | | private static final String CLASS_NAME = |
| | | "org.opends.server.core.WorkerThread"; |
| | | |
| | | |
| | | |
| | |
| | | { |
| | | super("Worker Thread " + threadID); |
| | | |
| | | assert debugConstructor(CLASS_NAME, String.valueOf(workQueue), |
| | | String.valueOf(threadID)); |
| | | |
| | | this.workQueue = workQueue; |
| | | |
| | |
| | | */ |
| | | public void setStoppedByReducedThreadNumber() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "setStoppedByReducedThreadNumber"); |
| | | |
| | | stoppedByReducedThreadNumber = true; |
| | | } |
| | |
| | | */ |
| | | public boolean isActive() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "isActive"); |
| | | |
| | | return (isAlive() && (operation != null)); |
| | | } |
| | |
| | | */ |
| | | public void run() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "run"); |
| | | assert debugMessage(DebugLogCategory.CORE_SERVER, DebugLogSeverity.INFO, |
| | | CLASS_NAME, "run", getName() + " starting."); |
| | | |
| | | workerThread = currentThread(); |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugMessage(DebugLogCategory.CORE_SERVER, |
| | | DebugLogSeverity.WARNING, CLASS_NAME, "run", |
| | | "Uncaught exception in worker thread while " + |
| | | "processing operation " + |
| | | String.valueOf(operation) + ": " + e); |
| | | assert debugException(CLASS_NAME, "run", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugWarning( |
| | | "Uncaught exception in worker thread while processing " + |
| | | "operation %s: %s", String.valueOf(operation), e); |
| | | |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | try |
| | | { |
| | |
| | | } |
| | | catch (Exception e2) |
| | | { |
| | | assert debugMessage(DebugLogCategory.CORE_SERVER, |
| | | DebugLogSeverity.WARNING, CLASS_NAME, "run", |
| | | "Exception in worker thread while trying to " + |
| | | "log a message about an uncaught exception " + e + |
| | | ": " + e2); |
| | | assert debugException(CLASS_NAME, "run", e2); |
| | | if (debugEnabled()) |
| | | { |
| | | debugWarning( |
| | | "Exception in worker thread while trying to log a " + |
| | | "message about an uncaught exception %s: %s", e, e2); |
| | | |
| | | debugCought(DebugLogLevel.ERROR, e2); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | catch (Exception e2) |
| | | { |
| | | assert debugException(CLASS_NAME, "run", e2); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e2); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // If we have gotten here, then we presume that the server thread is |
| | | // shutting down. However, if that's not the case then that is a problem |
| | | // and we will want to log a message. |
| | |
| | | } |
| | | |
| | | |
| | | assert debugMessage(DebugLogCategory.CORE_SERVER, DebugLogSeverity.INFO, |
| | | CLASS_NAME, "run", getName() + " exiting."); |
| | | if (debugEnabled()) |
| | | { |
| | | debugInfo(getName() + " exiting."); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public void shutDown() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "shutDown"); |
| | | assert debugMessage(DebugLogCategory.CORE_SERVER, |
| | | DebugLogSeverity.INFO, CLASS_NAME, "shutDown", |
| | | getName() + " being signaled to shut down."); |
| | | |
| | | if (debugEnabled()) |
| | | { |
| | | debugInfo(getName() + " being signaled to shut down."); |
| | | } |
| | | |
| | | // Set a flag that indicates that the thread should stop running. |
| | | shutdownRequested = true; |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugMessage(DebugLogCategory.CORE_SERVER, |
| | | DebugLogSeverity.WARNING, CLASS_NAME, "shutDown", |
| | | "Caught an exception while trying to interrupt " + |
| | | "the worker thread waiting for work: " + e); |
| | | assert debugException(CLASS_NAME, "shutDown", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugWarning( |
| | | "Caught an exception while trying to interrupt the worker " + |
| | | "thread waiting for work: %s", e); |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | else |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugMessage(DebugLogCategory.CORE_SERVER, |
| | | DebugLogSeverity.WARNING, CLASS_NAME, "shutDown", |
| | | "Caught an exception while trying to abandon the " + |
| | | "operation in progress for the worker thread: " + |
| | | e); |
| | | assert debugException(CLASS_NAME, "shutDown", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugWarning( |
| | | "Caught an exception while trying to abandon the " + |
| | | "operation in progress for the worker thread: %s", e); |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | } |