Package org.archive.modules.deciderules
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 Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.context.ApplicationContext
protected String
engine name; default "beanshell"protected boolean
Whether each ToeThread should get its own independent script engine, or they should share synchronized access to one engine.protected ReadSource
protected ScriptEngine
protected ThreadLocal<ScriptEngine>
Fields inherited from class org.archive.modules.deciderules.DecideRule
comment, kp
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected ScriptEngine
Get the proper ScriptEngine instance -- either shared or local to this thread.boolean
innerDecide
(CrawlURI uri) protected ScriptEngine
Create a new ScriptEngine instance, preloaded with any supplied source file and the variables 'self' (this ScriptedDecideRule) and 'context' (the ApplicationContext).void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) void
setEngineName
(String name) void
setIsolateThreads
(boolean isolateThreads) void
setScriptSource
(ReadSource scriptSource) Methods inherited from class org.archive.modules.deciderules.DecideRule
accepts, decisionFor, getComment, getEnabled, getKeyedProperties, onlyDecision, setComment, setEnabled
-
Field Details
-
engineName
engine name; default "beanshell" -
scriptSource
-
isolateThreads
protected boolean isolateThreadsWhether 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
-
-
Constructor Details
-
ScriptedDecideRule
public ScriptedDecideRule()
-
-
Method Details
-
getEngineName
-
setEngineName
-
getScriptSource
-
setScriptSource
-
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 interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
innerDecide
- Specified by:
innerDecide
in classDecideRule
-
getEngine
Get the proper ScriptEngine instance -- either shared or local to this thread.- Returns:
- ScriptEngine to use
-
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
-