Interpreter Cancel method

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Interpreter Cancel method

bart.jourquin
Dear Beanshell2 developers,

I use Beanshell since several years and came along the Beanshell2 project yesterday. Thank you for the work.

A feature I miss is the possibility to cancel a running script in an interpreter. Therefore, I slightly modified the interpreter.java code, introducing a "cancel" method:

        public boolean isCanceled = false; // Use a public variable instead of getter() for performance issues
       
        Interpreter localInterpreter = null; // Defined globally instead as in "eval()"
       
        public void cancel() {
                isCanceled = true;
                if (localInterpreter != null) {
                        localInterpreter.cancel();
                }
        }


Further, I introduced the following code in each BSH*.java sources that implement a public Object eval(CallStack callstack, Interpreter interpreter)

        public Object eval(CallStack callstack, Interpreter interpreter)
                        throws EvalError {

        if (interpreter.isCanceled) return null;

        // Original unchanged code
        }


The modified interpreter.java and an example of a BSH*.java code is attached to this mail. The code changes can be easily found between "BAJ 20110727" tags.

Do you think this could be introduced in your source tree ?

Regards

Interpreter.java
BSHWhileStatement.java
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interpreter Cancel method

fschmidt
Administrator
Have you tried just using Thread.interrupt() ?
Loading...