mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
02.14.2014 ef298d57b65dcb807518a787f8464083bf6af98d
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)