Hi, 

This is what i did to make NutchConf behave not so static, 
without patching any of those 195 places Stefan mentioned.

NutchConf.get() yields the current config. 
OpenConf sets a new current config.
finally CloseConf closes this config.

But be warned about issues with the plugin cache mentioned earlier.

Greeting Marcel Schnippe.

public class NutchConf {
 //...
 
  public static final NutchConf DEFAULT = new NutchConf(); 
  private static ThreadLocal threadNutchConf = new ThreadLocal() {
     protected synchronized Object initialValue() {
       Stack confs = new Stack();
       confs.add(NutchConf.DEFAULT);
       return confs;
     }
  };
  /** Return the current default configuration. (see [EMAIL PROTECTED] 
#OpenConf}) */
  public static NutchConf get() { 
    return (NutchConf) (((Stack) 
(threadNutchConf.get())).lastElement());};
  /** Open new thread specific configuration, which will be returned by
   * calls to [EMAIL PROTECTED] #get} until finally closed by  [EMAIL 
PROTECTED] #CloseConf}.
   * @param conf a NutchConf generated with new NutchConf and [EMAIL PROTECTED] 
#addConfResource}.
   */
  public static void OpenConf (NutchConf conf) {
    Stack confs = (Stack) (threadNutchConf.get());
    confs.add(conf);
  };
  /** Close configuration opend by [EMAIL PROTECTED] #OpenConf}, return to 
previous 
or 
    default+site configuration */
  public static void CloseConf() { 
    ((Stack) (threadNutchConf.get())).pop();
  };

 //...
};

Reply via email to