binding issues
Sundararajan Athijegannathan
sundararajan.athijegannathan at oracle.com
Thu Jan 12 12:54:37 UTC 2017
That does not give us much info. to debug the issue :( Please provide us
with a simple test case that reproduces the issue mentioned.
Thanks,
-Sundar
On 12/01/17, 5:02 PM, Andreas Mueller wrote:
> I figured out what the problem is. Here is my Javascript callback
> function, simplified:
>
> stream.create().memoryGroup("queues", "name").onCreate(function (memoryGroup,
> key) {
> stream.create().memory(key);
> print("Add:"+ key+"="+stream.memory(key));
> });
> The “stream” variable is set in the bindings before evaluating the script:
>
> ScriptContext newContext = new SimpleScriptContext();
> streamContext.engineScope =
> newContext.getBindings(ScriptContext.ENGINE_SCOPE);
> streamContext.engineScope.put("stream", streamContext.stream);
>
> Now, the first statement in the function accesses:
>
> com.swiftmq.impl.streams.Stream at 47273fd1
>
> But the second statement (print) has a different “stream” instance:
>
> com.swiftmq.impl.streams.Stream at 6222f856
>
> That’s why I’m not getting data set in the “stream” because they are
> different instances. Seems like a binding issue.
>
> How can this happen?
>
> --
> Andreas Mueller
> IIT Software GmbH
> http://www.swiftmq.com
>
>
>
>> On 12.01.2017, at 11:13, Sundararajan Athijegannathan
>> <sundararajan.athijegannathan at oracle.com
>> <mailto:sundararajan.athijegannathan at oracle.com>> wrote:
>>
>> Not sure what you mean by "engine is shared between scripts". Each
>> separate Nashorn ScriptEngine instance is isolated. Nothing is shared
>> across different script engine instances. There are no java level
>> "statics" (i.e., process wide globals) that cut across engine
>> instances. On the same engine, there is compiled code is shared
>> (.class and Class objects in some cases) when possible. That should
>> also not result in any issue (there may be bugs).
>>
>> Hope I addressed your questions,
>> -Sundar
>>
>> On 12/01/17, 1:42 PM, Andreas Mueller wrote:
>>> Will do.
>>>
>>> Can you tell me whether the engine is shared between scripts? Is
>>> there a way to use one engine per script and to start absolute clean
>>> (no caches, no refs from previous runs) just like when the JVM was
>>> started?
>>>
>>> Thanks,
>>> Andreas
>>>
>>>> Am 12.01.2017 um 05:23 schrieb Sundararajan
>>>> Athijegannathan<sundararajan.athijegannathan at oracle.com
>>>> <mailto:sundararajan.athijegannathan at oracle.com>>:
>>>>
>>>> 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
>>>>>
>>>
>>>
>>> IIT Software GmbH
>>> Münsterstr. 111, 48145 Münster, Germany
>>> Phone: +49 (0)2506 3049340
>>> Managing Director: Andreas Müller
>>> District Court: Amtsgericht Münster, HRB 16294
>>> VAT-No: DE199945912
>>>
>>> This e-mail may contain confidential and/or privileged information.
>>> If you are not the intended recipient (or have received this e-mail
>>> in error) please notify the sender immediately and destroy this
>>> e-mail. Any unauthorized copying, disclosure or distribution of the
>>> material in this e-mail is strictly forbidden.
>>>
>>>
>
>
>
> ------------------------------------------------------------------------
> IIT Software GmbH
> Münsterstr. 111, 48145 Münster, Germany
> Phone: +49 (0)2506 3049340
> Managing Director: Andreas Müller
> District Court: Amtsgericht Münster, HRB 16294
> VAT-No: DE199945912
>
> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
>
More information about the nashorn-dev
mailing list