1 package net.javacoding.jspider.core.throttle; 2 3 4 import net.javacoding.jspider.api.model.Site; 5 import net.javacoding.jspider.core.logging.LogFactory; 6 import net.javacoding.jspider.core.logging.Log; 7 import net.javacoding.jspider.core.throttle.impl.DistributedLoadThrottleProvider; 8 import net.javacoding.jspider.core.util.config.*; 9 10 11 26 public class ThrottleFactory { 27 28 29 33 public Throttle createThrottle(Site site) { 34 PropertySet props = ConfigurationFactory.getConfiguration().getSiteConfiguration(site); 35 PropertySet throttleProps = new MappedPropertySet ( ConfigConstants.SITE_THROTTLE, props ); 36 Class providerClass = throttleProps.getClass(ConfigConstants.SITE_THROTTLE_PROVIDER, DistributedLoadThrottleProvider.class); 37 Log log = LogFactory.getLog(ThrottleFactory.class); 38 log.info("Throttle provider class is '" + providerClass + "'"); 39 40 try { 41 ThrottleProvider provider = (ThrottleProvider) providerClass.newInstance(); 42 PropertySet throttleConfigProps = new MappedPropertySet ( ConfigConstants.SITE_THROTTLE_CONFIG, throttleProps ); 43 return provider.createThrottle(throttleConfigProps); 44 } catch (InstantiationException e) { 45 log.error("InstantiationException on Throttle", e); 46 return null; 47 } catch (IllegalAccessException e) { 48 log.error("IllegalAccessException on Throttle", e); 49 return null; 50 } 51 52 } 53 } 54 | Popular Tags |