Quantcast

Interrupting a beanshell script in JConsole

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

Interrupting a beanshell script in JConsole

Jean-Philippe Daigle-4
Say you're running a loop in a beanshell script, like this:

while(true){ print("uh-oh!"); };

The above will run forever and I haven't found a way to interrupt it.
I've tried:
* ctrl+c
* pause key
* break key
* ctrl+break

Is there any way to interrupt a loop running in a JConsole?

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interrupting a beanshell script in JConsole

David Lee
Close the console window ?

David A. Lee
[hidden email]  
http://www.calldei.com
http://www.xmlsh.org
812-482-5224



Jean-Philippe Daigle wrote:

> Say you're running a loop in a beanshell script, like this:
>
> while(true){ print("uh-oh!"); };
>
> The above will run forever and I haven't found a way to interrupt it.
> I've tried:
> * ctrl+c
> * pause key
> * break key
> * ctrl+break
>
> Is there any way to interrupt a loop running in a JConsole?
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge  
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize  
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>  

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interrupting a beanshell script in JConsole

Jean-Philippe Daigle-4
On Mon, Jul 20, 2009 at 5:52 PM, David A. Lee <[hidden email]> wrote:

> Close the console window ?
>
> David A. Lee
> [hidden email]  http://www.calldei.com
> http://www.xmlsh.org
> 812-482-5224
>
>
>
> Jean-Philippe Daigle wrote:
>
>> Say you're running a loop in a beanshell script, like this:
>>
>> while(true){ print("uh-oh!"); };
>>
>> The above will run forever and I haven't found a way to interrupt it.
>> I've tried:
>> * ctrl+c
>> * pause key
>> * break key
>> * ctrl+break
>>
>> Is there any way to interrupt a loop running in a JConsole?
>>
>>
Yes, closing the console works quite well, but I was looking to interrupt
the loop without losing the session.

An example would be if you have a loop running that prints out statistics
every 5 seconds, and you want to interrupt it and use your session some
more.
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interrupting a beanshell script in JConsole

David Lee
Same as in java, I know no way to do this.  There is no equivilent to
signals in java.
The best I can suggest is to "simulate a breakpoint".
That is intersperse your loop to a callback into your own code like
for( ... ) {
   code
   if( my_breakpoint_is_set)
      throw new MyException("stop here");
}


David A. Lee
[hidden email]  
http://www.calldei.com
http://www.xmlsh.org
812-482-5224



Jean-Philippe Daigle wrote:

> On Mon, Jul 20, 2009 at 5:52 PM, David A. Lee <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Close the console window ?
>
>     David A. Lee
>     [hidden email] <mailto:[hidden email]>  http://www.calldei.com
>     http://www.xmlsh.org
>     812-482-5224
>
>
>
>     Jean-Philippe Daigle wrote:
>
>         Say you're running a loop in a beanshell script, like this:
>
>         while(true){ print("uh-oh!"); };
>
>         The above will run forever and I haven't found a way to
>         interrupt it.
>         I've tried:
>         * ctrl+c
>         * pause key
>         * break key
>         * ctrl+break
>
>         Is there any way to interrupt a loop running in a JConsole?
>
>
> Yes, closing the console works quite well, but I was looking to
> interrupt the loop without losing the session.
>
> An example would be if you have a loop running that prints out
> statistics every 5 seconds, and you want to interrupt it and use your
> session some more.
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interrupting a beanshell script in JConsole

Jean-Philippe Daigle-4
Thanks, David.
I can't see a clean fix either. I've experimented with subclassing
JConsole and catching the Ctrl+C keyPressed(), but there's no good way
to stop the interpreter. A crazy hack I imagined that would handle
ctrl+c correctly might be:

* Subclass JConsole and provide your own keyPressed(KeyEvent)
implementation that calls JConsole's, BUT detects ctrl+c and sets some
global flag to terminate loops.
* Never ever ever do while(true) in a script, always do while(!flag).
* Reset flag to false on every keystroke that's NOT a ctrl-C.

Looks ugly, but being mindful of this in scripts (as you suggested)
seems to be the way to go.


On Mon, Jul 20, 2009 at 9:48 PM, David A. Lee<[hidden email]> wrote:

> Same as in java, I know no way to do this.  There is no equivilent to
> signals in java.
> The best I can suggest is to "simulate a breakpoint".
> That is intersperse your loop to a callback into your own code like
> for( ... ) {
>    code
>    if( my_breakpoint_is_set)
>       throw new MyException("stop here");
> }
>
>
> David A. Lee
> [hidden email]
> http://www.calldei.com
> http://www.xmlsh.org
> 812-482-5224
>
> Jean-Philippe Daigle wrote:
>
> On Mon, Jul 20, 2009 at 5:52 PM, David A. Lee <[hidden email]> wrote:
>>
>> Close the console window ?
>>
>> David A. Lee
>> [hidden email]  http://www.calldei.com
>> http://www.xmlsh.org
>> 812-482-5224
>>
>>
>>
>> Jean-Philippe Daigle wrote:
>>>
>>> Say you're running a loop in a beanshell script, like this:
>>>
>>> while(true){ print("uh-oh!"); };
>>>
>>> The above will run forever and I haven't found a way to interrupt it.
>>> I've tried:
>>> * ctrl+c
>>> * pause key
>>> * break key
>>> * ctrl+break
>>>
>>> Is there any way to interrupt a loop running in a JConsole?
>>>
>
> Yes, closing the console works quite well, but I was looking to interrupt
> the loop without losing the session.
>
> An example would be if you have a loop running that prints out statistics
> every 5 seconds, and you want to interrupt it and use your session some
> more.
>

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interrupting a beanshell script in JConsole

Jean-Philippe Daigle-4
Here we go, in case this can help anyone else. I setup an anonymous
subclass of JConsole that handles ctrl+c, and then always write loops
as "while(!loopexit)". It's a bit of an ugly hack, but it seems to
work for my app:

        final String LOOPEXIT = "loopexit";
        /*
         * Loops in bsh scripts should always check the state of
         * "loopexit" in order to process Ctrl+C:
         *
         * while(!loopexit) { ... };
         */
        JConsole console = new JConsole() {
                @Override
                public void keyPressed(KeyEvent e) {
                        super.keyPressed(e);
                        try {
                                if (e.getKeyCode() == KeyEvent.VK_C
                                        && ((e.getModifiers() & InputEvent.CTRL_MASK) > 0)) {
                                        // ctrl+c, set loopexit
                                        interpreter.set(LOOPEXIT, true);
                                } else {
                                        // Any other key: clear loopflag
                                        interpreter.set(LOOPEXIT, false);
                                }
                        } catch (EvalError e1) {
                                e1.printStackTrace();
                        }
                }
        };
        interpreter = new Interpreter(console);
        try {
                interpreter.set(LOOPEXIT, false);
        } catch (EvalError e) {
                e.printStackTrace();
        }



On Mon, Jul 20, 2009 at 11:23 PM, Jean-Philippe
Daigle<[hidden email]> wrote:

> Thanks, David.
> I can't see a clean fix either. I've experimented with subclassing
> JConsole and catching the Ctrl+C keyPressed(), but there's no good way
> to stop the interpreter. A crazy hack I imagined that would handle
> ctrl+c correctly might be:
>
> * Subclass JConsole and provide your own keyPressed(KeyEvent)
> implementation that calls JConsole's, BUT detects ctrl+c and sets some
> global flag to terminate loops.
> * Never ever ever do while(true) in a script, always do while(!flag).
> * Reset flag to false on every keystroke that's NOT a ctrl-C.
>
> Looks ugly, but being mindful of this in scripts (as you suggested)
> seems to be the way to go.
>
>
> On Mon, Jul 20, 2009 at 9:48 PM, David A. Lee<[hidden email]> wrote:
>> Same as in java, I know no way to do this.  There is no equivilent to
>> signals in java.
>> The best I can suggest is to "simulate a breakpoint".
>> That is intersperse your loop to a callback into your own code like
>> for( ... ) {
>>    code
>>    if( my_breakpoint_is_set)
>>       throw new MyException("stop here");
>> }
>>
>>
>> David A. Lee
>> [hidden email]
>> http://www.calldei.com
>> http://www.xmlsh.org
>> 812-482-5224
>>
>> Jean-Philippe Daigle wrote:
>>
>> On Mon, Jul 20, 2009 at 5:52 PM, David A. Lee <[hidden email]> wrote:
>>>
>>> Close the console window ?
>>>
>>> David A. Lee
>>> [hidden email]  http://www.calldei.com
>>> http://www.xmlsh.org
>>> 812-482-5224
>>>
>>>
>>>
>>> Jean-Philippe Daigle wrote:
>>>>
>>>> Say you're running a loop in a beanshell script, like this:
>>>>
>>>> while(true){ print("uh-oh!"); };
>>>>
>>>> The above will run forever and I haven't found a way to interrupt it.
>>>> I've tried:
>>>> * ctrl+c
>>>> * pause key
>>>> * break key
>>>> * ctrl+break
>>>>
>>>> Is there any way to interrupt a loop running in a JConsole?
>>>>
>>
>> Yes, closing the console works quite well, but I was looking to interrupt
>> the loop without losing the session.
>>
>> An example would be if you have a loop running that prints out statistics
>> every 5 seconds, and you want to interrupt it and use your session some
>> more.
>>
>

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Loading...