Class ScriptedDecideRule

java.lang.Object
org.archive.modules.deciderules.DecideRule
org.archive.modules.deciderules.ScriptedDecideRule
All Implemented Interfaces:
Serializable, HasKeyedProperties, org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

public class ScriptedDecideRule extends DecideRule implements org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean
Rule which runs a JSR-223 script to make its decision. Script source may be provided via a file local to the crawler or an inline configuration string. The source must include a one-argument function "decisionFor" which returns the appropriate DecideResult. Variables available to the script include 'object' (the object to be evaluated, typically a CrawlURI), 'self' (this ScriptedDecideRule instance), and 'context' (the crawl's ApplicationContext, from which all named crawl beans are easily reachable). TODO: provide way to trigger reload of script mid-crawl; perhaps by watching for a certain applicationEvent?
Author:
gojomo
See Also:
  • Field Details

    • engineName

      protected String engineName
      engine name; default "beanshell"
    • scriptSource

      protected ReadSource scriptSource
    • isolateThreads

      protected boolean isolateThreads
      Whether each ToeThread should get its own independent script engine, or they should share synchronized access to one engine. Default is true, meaning each thread gets its own isolated engine.
    • appCtx

      protected org.springframework.context.ApplicationContext appCtx
    • threadEngine

      protected transient ThreadLocal<ScriptEngine> threadEngine
    • sharedEngine

      protected transient ScriptEngine sharedEngine
  • Constructor Details

    • ScriptedDecideRule

      public ScriptedDecideRule()
  • Method Details

    • getEngineName

      public String getEngineName()
    • setEngineName

      public void setEngineName(String name)
    • getScriptSource

      public ReadSource getScriptSource()
    • setScriptSource

      public void setScriptSource(ReadSource scriptSource)
    • getIsolateThreads

      public boolean getIsolateThreads()
    • setIsolateThreads

      public void setIsolateThreads(boolean isolateThreads)
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • innerDecide

      public DecideResult innerDecide(CrawlURI uri)
      Specified by:
      innerDecide in class DecideRule
    • getEngine

      protected ScriptEngine getEngine()
      Get the proper ScriptEngine instance -- either shared or local to this thread.
      Returns:
      ScriptEngine to use
    • newEngine

      protected ScriptEngine newEngine()
      Create a new ScriptEngine instance, preloaded with any supplied source file and the variables 'self' (this ScriptedDecideRule) and 'context' (the ApplicationContext).
      Returns:
      the new Interpreter instance