RE: Shutdown openjms server (0.7.6.1) and all of its threads without stopping vm

"Tim Anderson" <[email protected]>
Newsgroups gmane.comp.java.openjms.user
Message-ID <[email protected]>
You can't shut down an embedded server cleanly in 0.7.6 when using
TCP, HTTP,  or RMI connectors, without performing a System.exit().
 
Can you explain the reason you can't use the JMS 1.1 API?
It's backward compatible with 1.0.2.
The above has been resolved in 0.7.7, which uses JMS 1.1.
 
-Tim
 
  _____  

From: openjms-user-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
[mailto:openjms-user-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org] On Behalf Of Simon Bredel
Sent: Friday, 3 February 2006 10:43 PM
To: [email protected]
Subject: [openjms-user] Shutdown openjms server (0.7.6.1) and all of its
threads without stopping vm



Hello,

I'm trying to run a openjms server inside a tomcat.
Because it is necessary that the jms server can be stopped and restarted via
the Tomcat manager web application,
I wrote the class attatched below to start and stop the server as a spring
bean.
Spring calls the afterPropertiesSet() method on startup and the destroy()
method on shutdown.
The Problem on shutdown is, that the
org.exolab.jms.server.AdminConnection.stopServer() 
also stops the java vm by calling System.exit(0), what stopped the whole
Tomcat in my case.
To avoid this, I removed this line in the code to test what happens. 
The vm staid alive, but trying to restart ended with an exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'jmsServer' defined in ServletContext resource
[/WEB-INF/jms-broker.xml]: Initialization of bean failed; ! nested exception
is org.exolab.jms.server.ServerException: Failed to initialise server for
the tcp connector
org.exolab.jms.server.ServerException: 
java.net.BindException: Address in use: JVM_Bind
      at java.net.PlainSocketImpl.socketBind(Native Method)
      at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:447)
      at java.net.ServerSocket.<init>(ServerSocket.java:165)
      at
org.exolab.core.mipc.MultiplexConnectionServer.<init>(MultiplexConnectionSer
ver.java:135)
      at
org.exolab.core.mipc.MultiplexConnectionServer.<init>(MultiplexConnectionSer
ver.java:118)
      at
org.exolab.jms.server.mipc.IpcJmsServer.createServer(IpcJmsServer.java:236)
      at org.exolab.jms.server.mipc.IpcJmsServer.init(IpcJmsServer.java:129)
   &nb! sp;  at org.exolab.jms.server.JmsServer.initConnector(JmsServer.j
ava:367)
      at org.exolab.jms.server.JmsServer.initConnectors(JmsServer.java:321)
      at org.exolab.jms.server.JmsServer.init(JmsServer.java:197)

I can see that there are still some threads alive after the
admin.stopServer() method has called and
one of of it still uses the needet port. 

The Threads I recognized were:
 - PDM-LockManager
 - Missing message castor.misc.threadLocalDaemonName
 - two other unnamed Threads started by the JmsServer.init() method

I have made shure that all clients who had been connected to the 
server have been closed, so are their connections and sessions.
I browsed the archive for solutions but couldn't find an answer.
Does anybody know a solution for my problem?
Unfortunately I am bound to JMS 1.0.2 so I am using openjms-0.7.6.1 and
cannot change to an actual version of openjms.
The Tomcat version I use is 4x.

  ! ;  

The class I modified (org.exolab.jms.server.AdminConnection):

 public void stopServer() {
        // todo perform neccesary clean up for a much nicer shutdown.
        // probably should inform all clients.

        _log.info("Stopping all services");
        ServiceManager.instance().removeAll();
        _log.info("Server Shutdown scheduled for 5 secs");
        Runnable r = new Runnable() {

            public void run() {
                try {
                    Thread.sleep(5000);
--! >         // dont shut down java vm
-->         //      System.exit(0);
                } catch (Exception err) {
                    //
                }
            }
        };
        Thread t = new Thread(r);
        t.start();
    }

My class:

public class JmsServer implements InitializingBean, DisposableBean{

    private JmsServer jmsServer = null;
    private String configPath = null;
    private String lockPath = null;    private String adminConnectionUrl =
null;
    
    public void setConfig(String configPath){
        this.configPath = configPath;
    }    
    
    public void setLock(String lockPath){
        this.lockPath = lockPath;
    }
    
    public void setAdminConnectionUrl(String url)
    {
        this.adminConnectionUrl = url;
    }
    
    /* (non-Javadoc)
     * @see
org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
     */
    public void afterPropertiesSet() throws Exception 
    {
    !     String webappRoot = System.getProperty("webapp.root ");
        
        String absoluteLockPath = webappRoot + this.lock;
        File file = new File(absoluteLockPath);     
        if (file.exists()){
            file.delete();
        }
     
        String absoluteConfigPath = webappRoot + this.config;     
        this.broker = new JmsServer(absoluteConfigPath);
        this.broker.init();        
    }
    
    /* (non-Javadoc)
     * @see org.springframework.beans.factory.DisposableBean#dest! roy()
     */
    public void destroy() throws Exception 
    {        
        JmsAdminServerIfc admin =
AdminConnectionFactory.create(this.adminConnectionUrl);
        admin.stopServer();
    }   
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.