turning off the beanshell server

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

turning off the beanshell server

John Leveille
Hello,

I have been experimenting with the beanshell command

server(port)

in order to remotely access my weblogic runtime environment.  I am doing
this in my sandbox development environment as a way of adhoc
manipulation of the runtime objects -- very cool!  Now I have
encountered a problem.  When I redeploy my web application I have some
code that removes the interpreter from application scope and it should
get garbage collected.  However, before it can get collected, the next
version of my app fires up and the interpreter tries to bind to the same
port and gets an "address in use" error.

Is there some way to send something to the interpreter at web app
destroy time in order to stop the server mode?   I am thinking something
like this

<at init>
o = server(port)

<at destroy>
o.stop()

Thanks,
John Leveille



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: turning off the beanshell server

patniemeyer

On Dec 16, 2005, at 2:13 PM, John Leveille wrote:

> Is there some way to send something to the interpreter at web app  
> destroy time in order to stop the server mode?   I am thinking  
> something like this

I'm afraid that this is just a dumb omission.  We will fix it in the  
future.

But the server() command is just the following script:

/**
         Create a remote BeanShell listener service attached to
         the current interpreter, listening on the specified port.
*/
import bsh.util.Httpd;
import bsh.util.Sessiond;

bsh.help.server = "usage: server(int port)";

void server(int port ) {
         new Thread( new Httpd( port ) ).start();
         print("Httpd started on port: "+port);
         new Thread( new Sessiond( global.namespace, port+1 ) ).start();
         print("Sessiond started on port: "+ (port+1));
}

If you don't mind using the deprecated stop() method on thread you  
could kill it that way.

More generally, stopping threads blocked on I/O in Java has always  
been problematic.  This was addressed n Java 5 with the NIO package.

The best you can do prior to 1.5 is to use the setSoTimeout() method  
on the ServerSocket (used by Httpd) to set a timeout value... then  
check a flag to see if it's time to quit.


thanks,
Pat


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users