Will you please submit a bug with a compilable/runnable test case attached?

Thanks,
-Sundar

On 11/01/17, 11:09 PM, Andreas Mueller wrote:
Hi,

it seems I have a problem understanding Nashorn’s bindings...

I have multiple scripts, each independent of each other. They should run 
concurrently with their own context and engine scope bindings. This is created 
as follows for each script:

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName((String) 
entity.getProperty("script-language").getValue());
if (engine == null)
     throw new Exception("Engine for script-language '" + 
entity.getProperty("script-language").getValue() + "' not found!");
ScriptContext newContext = new SimpleScriptContext();
streamContext.engineScope = newContext.getBindings(ScriptContext.ENGINE_SCOPE);

Internally we have a Java-based processor which calls Javascript functions 
(callbacks). It is always the same thread.

It works fine when I start a script the first time. If I stop it (without 
stopping the JVM) and restart it (it runs through the code above) or if I run 
another script concurrently, I’m getting problems in so far that calls inside a 
Javascript callback to Java objects that set data don’t work. The data is not 
null on the Javascript callback but null inside the Java method.

Here is an example callback:

stream.create().memoryGroup("queues", "name").onCreate(function (memoryGroup, 
key) {
     stream.create().memory(key);
     print("Add:"+ key+"="+stream.memory(key));
});

The above “stream.create().memory(key)” is a Java method that has a printout:

AddMem: orderpos, mem=HeapMemory{name='orderpos’}

But when I retrieve it with "stream.memory(key)” in the print statement of the 
Javascript function I’m getting:

Add:orderpos=null

For me this points to the bindings, e.g. a binding from a previous running 
instance of the script or something else. Can somebody provide some help? What 
do I need to do to have always a clean instance of a binding when I rerun a 
script without stopping the JVM?

Thanks,
Andreas

Reply via email to