Hi,
right this is a know problem and discussed several times, we should start solving this. :-) I suggest that we make the Plugin Class implementing the Configurable interface. In case a plugin needs any configuration value it will request them from the plugin instance. The next step would be changing the plugin Registry from a singleton to a normal object that need to be instantiated with a nutch configuration object in the constructor.

In general I suggest we use a Inversion of control style mechanism (http://www.martinfowler.com/articles/injection.html) to solve these kind of problems, this is from my point of view the cleanest possible solution and allows also changing e.g. configuration objects until runtime.


Stefan


Am 20.12.2005 um 14:19 schrieb Andrzej Bialecki:

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




Reply via email to