mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-09-26 15:46:31 +00:00
HER-1984 save script state - implement by adding a map to the application context for arbitrary use, and make sure the app context is available in all scripting environments
* PathSharingContext.java
new member variable ConcurrentHashMap data and accessor getData()
* ScriptedProcessor.java, ScriptedDecideRule.java
make appCtx available to scripts; also remove unused member sharedMap
* ActionDirectory.java
formatting fix
This commit is contained in:
@@ -20,8 +20,6 @@
|
||||
package org.archive.modules;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -106,8 +104,6 @@ implements ApplicationContextAware, InitializingBean {
|
||||
transient protected ThreadLocal<ScriptEngine> threadEngine =
|
||||
new ThreadLocal<ScriptEngine>();
|
||||
protected ScriptEngine sharedEngine;
|
||||
/** map for optional use by scripts */
|
||||
public Map<Object,Object> sharedMap = new ConcurrentHashMap<Object,Object>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -135,12 +131,14 @@ implements ApplicationContextAware, InitializingBean {
|
||||
// synchronization is harmless for local thread engine,
|
||||
// necessary for shared engine
|
||||
engine.put("curi",curi);
|
||||
engine.put("appCtx", appCtx);
|
||||
try {
|
||||
engine.eval("process(curi)");
|
||||
} catch (ScriptException e) {
|
||||
logger.log(Level.WARNING,e.getMessage(),e);
|
||||
} finally {
|
||||
engine.put("curi", null);
|
||||
engine.put("appCtx", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
package org.archive.modules.deciderules;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -106,8 +104,6 @@ implements ApplicationContextAware, InitializingBean {
|
||||
transient protected ThreadLocal<ScriptEngine> threadEngine =
|
||||
new ThreadLocal<ScriptEngine>();
|
||||
transient protected ScriptEngine sharedEngine;
|
||||
/** map for optional use by scripts */
|
||||
public Map<Object,Object> sharedMap = new ConcurrentHashMap<Object,Object>();
|
||||
|
||||
public ScriptedDecideRule() {
|
||||
}
|
||||
@@ -128,12 +124,14 @@ implements ApplicationContextAware, InitializingBean {
|
||||
// necessary for shared engine
|
||||
try {
|
||||
engine.put("object",uri);
|
||||
engine.put("appCtx", appCtx);
|
||||
return (DecideResult)engine.eval("decisionFor(object)");
|
||||
} catch (ScriptException e) {
|
||||
logger.log(Level.WARNING,e.getMessage(),e);
|
||||
return DecideResult.NONE;
|
||||
} finally {
|
||||
engine.put("object", null);
|
||||
engine.put("appCtx", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user