nutch-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrzej Bialecki ...@getopt.org>
Subject Static initializers
Date Tue, 20 Dec 2005 13:19:14 GMT
Hi,

This was mentioned before: there are many places in Nutch that rely on 
static initializers. This is so-so or sometimes plainly bad, depending 
on a situation.

I'm facing a problem now with URLFilters. I need to run several fetchers 
inside a single VM, with different parameters such as different url 
patterns (which is handled by URLFilters). But even if I specify 
different NutchConf-s to each fetcher, the list of implementations and 
the instances of URLFilter[] in URLFilters are initialized only once, 
and this happens from the default configuration obtained through a call 
to static NutchConf.get().

I would like to change it somehow, but I'm not sure how... One way to 
solve this would be to instantiate the plugins based on a concrete 
NutchConf instance, like this:

URLFilters:

    private URLFilters(NutchConf) {
       // initialize plugins based on this instance of NutchConf
    }

    public static URLFilters get(NutchConf conf) {
       URLFilters res = (URLFilters)conf.get("urlfilters.key");
       if (res == null) {
          res = new URLFilters(conf);
          conf.put("urlfilters.key", res);
       }
       return res;
    }

In case you are running with a single NutchConf per JVM it doesn't change anything. In case
you want to run several different configs in a single JVM this approach provides the solution.
We could follow this strategy for other plugin registry facades. Comments?


-- 
Best regards,
Andrzej Bialecki     <><
 ___. ___ ___ ___ _ _   __________________________________
[__ || __|__/|__||\/|  Information Retrieval, Semantic Web
___|||__||  \|  ||  |  Embedded Unix, System Integration
http://www.sigram.com  Contact: info at sigram dot com



Mime
View raw message