KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > core > throttle > ThrottleFactory


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 /**
12  * Factory class that is responsible to create Throttle component instances
13  * for use by the engine.
14  *
15  * <p>
16  * Since we use a pluggable component setup, the throttle provider class and
17  * the parameters used by the throttle component implementation are stored
18  * in the jspider.properties file, under the conf/ folder, in the subfolder
19  * of the used configuration.
20  * </p>
21  *
22  * $Id: ThrottleFactory.java,v 1.9 2003/04/03 15:57:19 vanrogu Exp $
23  *
24  * @author Günther Van Roey
25  */

26 public class ThrottleFactory {
27
28
29     /**
30      * Creates a Throttle instance, based upon the settings in the config file.
31      * @return Throttle instance
32      */

33     public Throttle createThrottle(Site site) {
34         PropertySet props = ConfigurationFactory.getConfiguration().getSiteConfiguration(site);
35         PropertySet throttleProps = new MappedPropertySet ( ConfigConstants.SITE_THROTTLE, props );
36         Class JavaDoc 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 JavaDoc e) {
45             log.error("InstantiationException on Throttle", e);
46             return null;
47         } catch (IllegalAccessException JavaDoc e) {
48             log.error("IllegalAccessException on Throttle", e);
49             return null;
50         }
51
52     }
53 }
54
Popular Tags