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

matthew_swift
18.14.2010 779e8d65b79e9fada98dd5f070c3359bb963b169
opends/src/server/org/opends/server/core/networkgroups/ResourceLimitsPolicyFactory.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *    Copyright 2009 Sun Microsystems, Inc.
 *    Copyright 2009-2010 Sun Microsystems, Inc.
 */
package org.opends.server.core.networkgroups;
@@ -131,7 +131,13 @@
    // The maximum time for a search.
    private int timeLimit;
    // The time interval for throughput limits
    private long interval;
    private long intervalStartTime = 0;
    // The max number of operations during the interval
    private int maxOperationsPerInterval;
    private int operationsPerInterval = 0;
    /**
     * Creates a new resource limits policy.
@@ -306,6 +312,29 @@
        }
      }
      // Check the throughput
      if (operation != null && maxOperationsPerInterval > 0) {
        synchronized(mutex) {
          long now = System.currentTimeMillis();
          // if the start time has never been set, or the interval has already
          // expired, reset the start time and number of operations
          if (intervalStartTime == 0 || now > (intervalStartTime + interval)) {
            intervalStartTime = now;
            operationsPerInterval = 0;
          }
          operationsPerInterval++;
          if (operationsPerInterval > maxOperationsPerInterval) {
            messages.add(INFO_ERROR_MAX_THROUGHPUT_EXCEEDED.get(
                maxOperationsPerInterval,interval));
            result = false;
          }
        }
        if (!result) {
          return result;
        }
      }
      return true;
    }
@@ -438,6 +467,19 @@
      }
      minSearchSubstringLength = configuration.getMinSubstringLength();
      // Update the Max Ops Per Time Interval parameters
      long previousInterval = interval;
      int previousMax = maxOperationsPerInterval;
      interval = configuration.getMaxOpsInterval();
      maxOperationsPerInterval = configuration.getMaxOpsPerInterval();
      // If the values have been modified, reset the counters
      if ((previousInterval != interval)
          || (previousMax != maxOperationsPerInterval)) {
        intervalStartTime = 0;
        operationsPerInterval = 0;
      }
    }
  }
@@ -448,7 +490,13 @@
      ResourceLimitsQOSPolicyCfg configuration,
      List<Message> unacceptableReasons)
  {
    // Always valid.
    // maxOpsPerInterval must be positive
    long tmpMaxOps = configuration.getMaxOpsInterval();
    if (tmpMaxOps < 0) {
      unacceptableReasons.add(ERR_MAX_OPS_PER_INTERVAL.get(tmpMaxOps));
      return false;
    }
    return true;
  }