DistributedLoadThrottleProvider.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:2k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.core.throttle.impl;
  2. import net.javacoding.jspider.core.throttle.Throttle;
  3. import net.javacoding.jspider.core.throttle.ThrottleProvider;
  4. import net.javacoding.jspider.core.util.config.PropertySet;
  5. import net.javacoding.jspider.core.logging.LogFactory;
  6. import net.javacoding.jspider.core.logging.Log;
  7. /**
  8.  * Throttle provider class for the Distributed Load Throttle implementation.
  9.  * This class will generate throttle implementations when refernced from the
  10.  * configuration file (default).
  11.  *
  12.  * $Id: DistributedLoadThrottleProvider.java,v 1.7 2003/04/03 15:57:20 vanrogu Exp $
  13.  *
  14.  * @author G黱ther Van Roey
  15.  */
  16. public class DistributedLoadThrottleProvider implements ThrottleProvider {
  17.     public static final String INTERVAL = "interval";
  18.     public static final int INTERVAL_DEFAULT = 1000;
  19.     public static final int INTERVAL_MIN = 250;
  20.     /**
  21.      * Method that instantiates the Throttle implementation.
  22.      * @return Throttle instance
  23.      */
  24.     public Throttle createThrottle(PropertySet props) {
  25.         /* get the interval from the configuration. */
  26.         int interval = props.getInteger(INTERVAL, INTERVAL_DEFAULT);
  27.         Log log = LogFactory.getLog(DistributedLoadThrottleProvider.class);
  28.         if (interval < INTERVAL_MIN) {
  29.             log.warn("Throttle interval < " + INTERVAL_MIN + " ms is dangereous - set to minimum allowed of " + INTERVAL_MIN + " ms");
  30.             interval = INTERVAL_MIN;
  31.         }
  32.         log.debug("throttle interval set to " + interval + " ms.");
  33.         return new DistributedLoadThrottleImpl(interval);
  34.     }
  35. }