From f108de7fc4fddeaf70f73996fd4e9b62b2f692c0 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Tue, 07 Nov 2006 21:54:31 +0000
Subject: [PATCH] Update the work queue API to provide new isIdle and waitUntilIdle methods that may be used to determine whether the queue is currently idle (i.e., that it is not being used to process any operations).

---
 opendj-sdk/opends/src/server/org/opends/server/extensions/TraditionalWorkQueue.java |   55 ++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/extensions/TraditionalWorkQueue.java b/opendj-sdk/opends/src/server/org/opends/server/extensions/TraditionalWorkQueue.java
index e1f3124..ba635fa 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/extensions/TraditionalWorkQueue.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/extensions/TraditionalWorkQueue.java
@@ -142,18 +142,7 @@
 
 
   /**
-   * Initializes this work queue based on the information in the provided
-   * configuration entry.
-   *
-   * @param  configEntry  The configuration entry that contains the information
-   *                      to use to initialize this work queue.
-   *
-   * @throws  ConfigException  If the provided configuration entry does not have
-   *                           a valid work queue configuration.
-   *
-   * @throws  InitializationException  If a problem occurs during initialization
-   *                                   that is not related to the server
-   *                                   configuration.
+   * {@inheritDoc}
    */
   public void initializeWorkQueue(ConfigEntry configEntry)
          throws ConfigException, InitializationException
@@ -315,13 +304,7 @@
 
 
   /**
-   * Performs any necessary finalization for this work queue,
-   * including ensuring that all active operations are interrupted or
-   * will be allowed to complete, and that all pending operations will
-   * be cancelled.
-   *
-   * @param  reason  The human-readable reason that the work queue is being
-   *                 shut down.
+   * {@inheritDoc}
    */
   public void finalizeWorkQueue(String reason)
   {
@@ -1089,5 +1072,39 @@
 
     return new ConfigChangeResult(ResultCode.SUCCESS, false, resultMessages);
   }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isIdle()
+  {
+    assert debugEnter(CLASS_NAME, "isIdle");
+
+    if (opQueue.size() > 0)
+    {
+      return false;
+    }
+
+    queueLock.lock();
+
+    try
+    {
+      for (TraditionalWorkerThread t : workerThreads)
+      {
+        if (t.isActive())
+        {
+          return false;
+        }
+      }
+
+      return true;
+    }
+    finally
+    {
+      queueLock.unlock();
+    }
+  }
 }
 

--
Gitblit v1.10.0