From ef298d57b65dcb807518a787f8464083bf6af98d Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 02 Jan 2014 10:14:22 +0000
Subject: [PATCH] Added tests for BoundedWorkQueueStrategy (finally).
---
opends/src/server/org/opends/server/core/BoundedWorkQueueStrategy.java | 38 ++++++++++++++++++++++++++++++++------
1 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/opends/src/server/org/opends/server/core/BoundedWorkQueueStrategy.java b/opends/src/server/org/opends/server/core/BoundedWorkQueueStrategy.java
index 573c854..12e7403 100644
--- a/opends/src/server/org/opends/server/core/BoundedWorkQueueStrategy.java
+++ b/opends/src/server/org/opends/server/core/BoundedWorkQueueStrategy.java
@@ -21,7 +21,7 @@
* CDDL HEADER END
*
*
- * Copyright 2013 ForgeRock AS
+ * Copyright 2013-2014 ForgeRock AS
*/
package org.opends.server.core;
@@ -63,13 +63,23 @@
else
{
int cpus = Runtime.getRuntime().availableProcessors();
- int numWorkerThreads =
- DirectoryServer.getWorkQueue().getNumWorkerThreads();
this.maxNbConcurrentOperations =
- Math.max(cpus, numWorkerThreads * 25 / 100);
+ Math.max(cpus, getNumWorkerThreads() * 25 / 100);
}
}
+ /**
+ * Return the maximum number of worker threads that can be used by the
+ * WorkQueue (The WorkQueue could have a thread pool which adjusts its size).
+ *
+ * @return the maximum number of worker threads that can be used by the
+ * WorkQueue
+ */
+ protected int getNumWorkerThreads()
+ {
+ return DirectoryServer.getWorkQueue().getNumWorkerThreads();
+ }
+
/** {@inheritDoc} */
@Override
public void enqueueRequest(final Operation operation)
@@ -83,13 +93,13 @@
if (maxNbConcurrentOperations == 0)
{ // unlimited concurrent operations
- if (!DirectoryServer.tryEnqueueRequest(operation))
+ if (!tryEnqueueRequest(operation))
{ // avoid potential deadlocks by running in the current thread
operation.run();
}
}
else if (nbRunningOperations.getAndIncrement() > maxNbConcurrentOperations
- || !DirectoryServer.tryEnqueueRequest(wrap(operation)))
+ || !tryEnqueueRequest(wrap(operation)))
{ // avoid potential deadlocks by running in the current thread
try
{
@@ -104,6 +114,22 @@
}
}
+ /**
+ * 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 op
+ * 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).
+ */
+ protected boolean tryEnqueueRequest(Operation op) throws DirectoryException
+ {
+ return DirectoryServer.tryEnqueueRequest(op);
+ }
+
private Operation wrap(final Operation operation)
{
if (operation instanceof AbandonOperation)
--
Gitblit v1.10.0