KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > core > throttle > impl > DistributedLoadThrottleProvider


1 package net.javacoding.jspider.core.throttle.impl;
2
3
4 import net.javacoding.jspider.core.throttle.Throttle;
5 import net.javacoding.jspider.core.throttle.ThrottleProvider;
6 import net.javacoding.jspider.core.util.config.PropertySet;
7 import net.javacoding.jspider.core.logging.LogFactory;
8 import net.javacoding.jspider.core.logging.Log;
9
10
11 /**
12  * Throttle provider class for the Distributed Load Throttle implementation.
13  * This class will generate throttle implementations when refernced from the
14  * configuration file (default).
15  *
16  * $Id: DistributedLoadThrottleProvider.java,v 1.7 2003/04/03 15:57:20 vanrogu Exp $
17  *
18  * @author Günther Van Roey
19  */

20 public class DistributedLoadThrottleProvider implements ThrottleProvider {
21
22     public static final String JavaDoc INTERVAL = "interval";
23     public static final int INTERVAL_DEFAULT = 1000;
24     public static final int INTERVAL_MIN = 250;
25
26     /**
27      * Method that instantiates the Throttle implementation.
28      * @return Throttle instance
29      */

30     public Throttle createThrottle(PropertySet props) {
31
32         /* get the interval from the configuration. */
33         int interval = props.getInteger(INTERVAL, INTERVAL_DEFAULT);
34
35         Log log = LogFactory.getLog(DistributedLoadThrottleProvider.class);
36
37         if (interval < INTERVAL_MIN) {
38             log.warn("Throttle interval < " + INTERVAL_MIN + " ms is dangereous - set to minimum allowed of " + INTERVAL_MIN + " ms");
39             interval = INTERVAL_MIN;
40         }
41
42         log.debug("throttle interval set to " + interval + " ms.");
43
44         return new DistributedLoadThrottleImpl(interval);
45     }
46 }
47
Popular Tags