[jira] [Commented] (JEXL-194) synchronize on iterableValue in foreach statement
[ https://issues.apache.org/jira/browse/JEXL-194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15293504#comment-15293504 ] Dmitri Blinov commented on JEXL-194: Another train of thoughts... As an implementation to the extension of statement executions in JEXL we could introduce the use of annotations to each statement or block in the script, i.e. {code} @synchronized(items) {for (x : items) ...} @silent @lenient {null.tryMe()} {code} >From the JexlEngine point of view, each annotation could be implemented in the >form of Interceptor interface, for example {code} public interface Interceptor { public Object onStart(JexlStatement block, String annotation, Object.. args); public void onCatch(JexlStatement block, Exception ex); public void onFinally(JexlStatement block); } {code} JexlEngine could be given a method to register annotation interceptor based on annotation name, and the one for default interceptor. The engine should call each Interceptor.onStart() method in the order the annotations are applied to the statement in the script, finishing with the default interceptor if registered. The Interceptor.onCatch() method should be called only if execution had thrown any exception. Interceptor.onFinally() method should be called after the statement execution regardless of any exceptions, to provide guaranteed resource unlocking/cleaning if necessary. The Interceptor.onCatch() and Interceptor.onFinally() methods should be called in backward order respectively. The JexlStatement is the proposed new interface to somehow identify the statement or block of code which may also provide some info about it's stack frame. The annotation syntax should allow for zero, one or more parameters. Those parameters should be evaluated before interceptor execution and submitted to the Interceptor.onStart() method. In the absence of any matching interceptors corresponding to the annotation name, JexlEngine should simply ignore that, or write some diagnostic message in the log file. Such implementation could provide developers with excellent tool to add various checks and enhancements to scripting without pushing for new features that eventually would mess up the basic code. The JEXL-185 issue could also be dropped since tracing could be added easily via interceptors. > synchronize on iterableValue in foreach statement > - > > Key: JEXL-194 > URL: https://issues.apache.org/jira/browse/JEXL-194 > Project: Commons JEXL > Issue Type: Improvement >Affects Versions: 3.0 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Minor > > Since it is a requirement to synchronize on simple Collections and > synchronized Collections while iterating over them and since jexl has no > instrument to control synchronization in script, I think its reasonable to > implement synchronization in jexl itself on iterableValue. In case of > concurrent collections it will possibly block other threads only if they are > synchronizing on those collections themselves, which will be complementary to > required synchronization in jexl. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (JEXL-194) synchronize on iterableValue in foreach statement
[ https://issues.apache.org/jira/browse/JEXL-194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15282778#comment-15282778 ] Dmitri Blinov commented on JEXL-194: Thanks for the hint, I'll give it a try > synchronize on iterableValue in foreach statement > - > > Key: JEXL-194 > URL: https://issues.apache.org/jira/browse/JEXL-194 > Project: Commons JEXL > Issue Type: Improvement >Affects Versions: 3.0 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Minor > > Since it is a requirement to synchronize on simple Collections and > synchronized Collections while iterating over them and since jexl has no > instrument to control synchronization in script, I think its reasonable to > implement synchronization in jexl itself on iterableValue. In case of > concurrent collections it will possibly block other threads only if they are > synchronizing on those collections themselves, which will be complementary to > required synchronization in jexl. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (JEXL-194) synchronize on iterableValue in foreach statement
[ https://issues.apache.org/jira/browse/JEXL-194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15282561#comment-15282561 ] Henri Biestro commented on JEXL-194: As a temporary workaround, you already can run code under a 'synchronized' monitor as in : {code} public static class Synchronizer extends MapContext { private final JexlContext context; public Synchronizer(JexlContext ctxt) { this.context = ctxt; } public Object call(Object var, JexlScript script) { String[] parms = script.getParameters(); boolean varisarg = parms != null && parms.length == 1; if (var == null) { return varisarg? script.execute(context, var) : script.execute(context); } else { synchronized (var) { return varisarg? script.execute(context, var) : script.execute(context); } } } } @Test public void test196() throws Exception { Mapns = new TreeMap (); ns.put("synchronized", Synchronizer.class); JexlContext jc = new MapContext(); JexlEngine jexl = new JexlBuilder().namespaces(ns).create(); JexlScript js0 = jexl.createScript("synchronized:call(x, (y)->{y.size()})", "x"); Object size = js0.execute(jc, "foobar"); Assert.assertEquals(6, size); } {code} > synchronize on iterableValue in foreach statement > - > > Key: JEXL-194 > URL: https://issues.apache.org/jira/browse/JEXL-194 > Project: Commons JEXL > Issue Type: Improvement >Affects Versions: 3.0 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Minor > > Since it is a requirement to synchronize on simple Collections and > synchronized Collections while iterating over them and since jexl has no > instrument to control synchronization in script, I think its reasonable to > implement synchronization in jexl itself on iterableValue. In case of > concurrent collections it will possibly block other threads only if they are > synchronizing on those collections themselves, which will be complementary to > required synchronization in jexl. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (JEXL-194) synchronize on iterableValue in foreach statement
[ https://issues.apache.org/jira/browse/JEXL-194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15279844#comment-15279844 ] Dmitri Blinov commented on JEXL-194: If my thoughts may be of any use here, it seems options are either to introduce kind of *synchronized* keyword into JEXL syntax to protect needed blocks of code, which would give maximum flexibility, or at least introduce specialized form of *for statement* (lets say, foreach {}), which unlike basic version of *for statement* would lock collection for the duration of iteration, while necessarily synchronizing any modification (not sure about access) operators inside JEXL. May be more promising approach would be to provide extension points for *statements* in a way JexlArithmetic provides for *operators*, where it would be possible to add some custom logic without polluting JEXL code with questionable implementations. > synchronize on iterableValue in foreach statement > - > > Key: JEXL-194 > URL: https://issues.apache.org/jira/browse/JEXL-194 > Project: Commons JEXL > Issue Type: Improvement >Affects Versions: 3.0 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Minor > > Since it is a requirement to synchronize on simple Collections and > synchronized Collections while iterating over them and since jexl has no > instrument to control synchronization in script, I think its reasonable to > implement synchronization in jexl itself on iterableValue. In case of > concurrent collections it will possibly block other threads only if they are > synchronizing on those collections themselves, which will be complementary to > required synchronization in jexl. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (JEXL-194) synchronize on iterableValue in foreach statement
[ https://issues.apache.org/jira/browse/JEXL-194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15274208#comment-15274208 ] Henri Biestro commented on JEXL-194: There is no requirement to synchronize simple Collections if they are used only for iteration/access (i.e. readonly and/or unmodifiable) and it is not JEXL's role to solve concurrent iteration/write access to user structures. Besides, protecting iteration but not modification or access (array{S,G}et/property{S,G}et) leaves the concurrency hole wide open in most cases. I'll try and seek an alternative route that could allow an easy specialization of iteration through operators, something like a forEach method that would return a (Closable) Iterator. > synchronize on iterableValue in foreach statement > - > > Key: JEXL-194 > URL: https://issues.apache.org/jira/browse/JEXL-194 > Project: Commons JEXL > Issue Type: Improvement >Affects Versions: 3.0 >Reporter: Dmitri Blinov >Priority: Minor > > Since it is a requirement to synchronize on simple Collections and > synchronized Collections while iterating over them and since jexl has no > instrument to control synchronization in script, I think its reasonable to > implement synchronization in jexl itself on iterableValue. In case of > concurrent collections it will possibly block other threads only if they are > synchronizing on those collections themselves, which will be complementary to > required synchronization in jexl. -- This message was sent by Atlassian JIRA (v6.3.4#6332)