close a TopicConnection with the ExceptionListener, op enjms-0.7.6.1

Simon Bredel <simonbredel-S0/[email protected]> Wed, 17 May 2006 17:04:13 +0200
Newsgroups gmane.comp.java.openjms.user
Organization http://freemail.web.de/
Message-ID <[email protected]>

Hi,

I'm using openjms-0.7.6.1 and I would like to know if I do something wrong.

I have a broker running inside an application server.

I have an application on another server which connects to the broker.
In this application, I use several topic subscribers and publishers on different topics.
Each client (publisher/subscriber) uses a different TopicSession, but the all should share the same TopicConnection.
I open a TopicConnection the way explained on website:

connectionFactory = (TopicConnectionFactory) context.lookup("JmsTopicConnectionFactory");
TopicConnection connection = connectionFactory.createTopicConnection(user, pwd);

I implemented the Interface javax.jms.ExceptionListener for recognizing when the connection fails, when this happens, I want to shut down all clients (publishers, subscribers, which also implement the ExceptionListener interface) and shut down the connection:

public class ConnectionExceptionListener implements ExceptionListener{

 private Set clients = new HashSet();
 private TopicConnection connection;


 public ConnectionExceptionListener(TopicConnection connection) {
 this.connection = connection;
 }

 public void addClient(ExceptionListener exceptionListener) throws JMSException
 {
 this.clients.add(exceptionListener);
 }

 public void onException(JMSException ex)
 {
 this.connection.close();

 for (Iterator iter = this.clients.iterator(); iter.hasNext();)
 {
 ExceptionListener exceptionListener = (ExceptionListener) iter.next();
 exceptionListener.onException(ex);
 }
 this.clients.clear();
 this.clients = null;
 }
}

I set the connection's ExceptionListener:
connection.setExceptionListner(new ConnectionExceptionListener(connection));

Each time I create a subscriber or publisher, I add it to the ConnectionExceptionListener.

The code is an simplyfied extract to show the idea of what I would like to do.

What I like to do is recognizing when an error occurs. In that case, all clients and the connection should be closed.

My problem now is, that in some cases I cannot close the connection propperly.
After a while I can see that multipel Threads with the name "MultiplexConnection......" are running, but it should only 1 connection exist.


What am I doing wrong?
Thanks for your help!

Simon Bredel


	
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und 
kostenguenstig. Jetzt gleich testen! *http://f.web.de/?mc=021192* [http://f.web.de/?mc=021192]