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

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.core.throttle;
  2. import net.javacoding.jspider.api.model.Site;
  3. import net.javacoding.jspider.core.logging.LogFactory;
  4. import net.javacoding.jspider.core.logging.Log;
  5. import net.javacoding.jspider.core.throttle.impl.DistributedLoadThrottleProvider;
  6. import net.javacoding.jspider.core.util.config.*;
  7. /**
  8.  * Factory class that is responsible to create Throttle component instances
  9.  * for use by the engine.
  10.  *
  11.  * <p>
  12.  * Since we use a pluggable component setup, the throttle provider class and
  13.  * the parameters used by the throttle component implementation are stored
  14.  * in the jspider.properties file, under the conf/ folder, in the subfolder
  15.  * of the used configuration.
  16.  * </p>
  17.  *
  18.  * $Id: ThrottleFactory.java,v 1.9 2003/04/03 15:57:19 vanrogu Exp $
  19.  *
  20.  * @author G黱ther Van Roey
  21.  */
  22. public class ThrottleFactory {
  23.     /**
  24.      * Creates a Throttle instance, based upon the settings in the config file.
  25.      * @return Throttle instance
  26.      */
  27.     public Throttle createThrottle(Site site) {
  28.         PropertySet props = ConfigurationFactory.getConfiguration().getSiteConfiguration(site);
  29.         PropertySet throttleProps = new MappedPropertySet ( ConfigConstants.SITE_THROTTLE, props );
  30.         Class providerClass = throttleProps.getClass(ConfigConstants.SITE_THROTTLE_PROVIDER, DistributedLoadThrottleProvider.class);
  31.         Log log = LogFactory.getLog(ThrottleFactory.class);
  32.         log.info("Throttle provider class is '" + providerClass + "'");
  33.         try {
  34.             ThrottleProvider provider = (ThrottleProvider) providerClass.newInstance();
  35.             PropertySet throttleConfigProps = new MappedPropertySet ( ConfigConstants.SITE_THROTTLE_CONFIG, throttleProps );
  36.             return provider.createThrottle(throttleConfigProps);
  37.         } catch (InstantiationException e) {
  38.             log.error("InstantiationException on Throttle", e);
  39.             return null;
  40.         } catch (IllegalAccessException e) {
  41.             log.error("IllegalAccessException on Throttle", e);
  42.             return null;
  43.         }
  44.     }
  45. }