From 269a1d06ff820c287bb21a03fa76e3314110516a Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 22 Apr 2013 10:28:50 +0000
Subject: [PATCH] OPENDJ-832 Leverage the work queue for processing requests received on the HTTP connection handler

---
 opends/src/server/org/opends/server/core/DirectoryServer.java |   55 +++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/opends/src/server/org/opends/server/core/DirectoryServer.java b/opends/src/server/org/opends/server/core/DirectoryServer.java
index b6047f4..385f641 100644
--- a/opends/src/server/org/opends/server/core/DirectoryServer.java
+++ b/opends/src/server/org/opends/server/core/DirectoryServer.java
@@ -37,10 +37,8 @@
 import static org.opends.server.schema.SchemaConstants.*;
 import static org.opends.server.util.DynamicConstants.*;
 import static org.opends.server.util.ServerConstants.*;
-import static org.opends.server.util.StaticUtils.getExceptionMessage;
-import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
-import static org.opends.server.util.StaticUtils.toLowerCase;
-import static org.opends.server.util.Validator.ensureNotNull;
+import static org.opends.server.util.StaticUtils.*;
+import static org.opends.server.util.Validator.*;
 
 import java.io.*;
 import java.lang.management.ManagementFactory;
@@ -7287,15 +7285,16 @@
 
 
   /**
-   * Adds the provided operation to the work queue so that it will be processed
-   * by one of the worker threads.
+   * Runs all the necessary checks prior to adding an operation to the work
+   * queue. It throws a DirectoryException if one of the check fails.
    *
-   * @param  operation  The operation to be added to the work queue.
-   *
-   * @throws  DirectoryException  If a problem prevents the operation from being
-   *                              added to the queue (e.g., the queue is full).
+   * @param operation
+   *          The operation to be added to the work queue.
+   * @throws DirectoryException
+   *           If a check failed preventing the operation from being added to
+   *           the queue
    */
-  public static void enqueueRequest(Operation operation)
+  private static void checkCanEnqueueRequest(Operation operation)
          throws DirectoryException
   {
     ClientConnection clientConnection = operation.getClientConnection();
@@ -7348,7 +7347,6 @@
          break;
 
       }
-
     }
 
 
@@ -7420,12 +7418,41 @@
           // determination up to the modify operation itself.
       }
     }
+  }
 
-
-
+  /**
+   * Adds the provided operation to the work queue so that it will be processed
+   * by one of the worker threads.
+   *
+   * @param  operation  The operation to be added to the work queue.
+   *
+   * @throws  DirectoryException  If a problem prevents the operation from being
+   *                              added to the queue (e.g., the queue is full).
+   */
+  public static void enqueueRequest(Operation operation)
+      throws DirectoryException
+  {
+    checkCanEnqueueRequest(operation);
     directoryServer.workQueue.submitOperation(operation);
   }
 
+  /**
+   * Tries to add the provided operation to the work queue if not full so that
+   * it will be processed by one of the worker threads.
+   *
+   * @param operation
+   *          The operation to be added to the work queue.
+   * @return true if the operation could be enqueued, false otherwise
+   * @throws DirectoryException
+   *           If a problem prevents the operation from being added to the queue
+   *           (e.g., the queue is full).
+   */
+  public static boolean tryEnqueueRequest(Operation operation)
+      throws DirectoryException
+  {
+    checkCanEnqueueRequest(operation);
+    return directoryServer.workQueue.trySubmitOperation(operation);
+  }
 
 
   /**

--
Gitblit v1.10.0