-
1. Re: PLSSSS HELP, ITS URGENT
adrian.brock Oct 28, 2002 2:26 PM (in response to suvankar17)MyExceptionListener l = new MyExceptionListener();
connection.setExceptionListener(l);
public class MyExceptionListener
implements javax.jms.ExceptionListener
{
public void onException(JMSException e)
{
// Handle the problem here
}
}
Regards,
Adrian -
2. Re: PLSSSS HELP, ITS URGENT
suvankar17 Oct 29, 2002 6:04 AM (in response to suvankar17)Thank you so much adrian, I hope your approach will definitely work, thank you so much for your kind help.
Regards,
Suv -
3. Re: PLSSSS HELP, ITS URGENT
suvankar17 Oct 30, 2002 6:07 AM (in response to suvankar17)Hi,
I tried the aprroach mentioned and accordingly when the server goes down, the onException method gets called and so the client knows about the server is down, but now the problem is that when the server goes up, the client cannot reconnect to the JMS provided, it still shows the exception that server is unreachable, so how can i recconnect my client to the server , so that normal communication is resumed again.
My test code is shown below:-
-------------------------------
import javax.jms.*;
import java.util.*;
import javax.naming.*;
public class jmsTest implements MessageListener
{
TopicConnectionFactory topicConnectionFactory = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
Topic topic = null;
TopicSubscriber topicSubscriber = null;
public jmsTest(){
setupJMS();
}
public static void main(String[] args)
{
jmsTest jms = new jmsTest();
}
public void onMessage(Message aMessage){
System.out.println("On Message is called");
}
public void setupJMS(){
try{
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
prop.put(Context.PROVIDER_URL,"localhost:1099");
prop.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
InitialContext ctx = new InitialContext(prop);
topicConnectionFactory = null;
topicConnection = null;
topicSession = null;
topic = null;
topicSubscriber = null;
topicConnectionFactory = (TopicConnectionFactory)ctx.lookup("ConnectionFactory");
topic = (Topic)ctx.lookup("topic/aTopic");
topicConnection = topicConnectionFactory.createTopicConnection();
topicSession = topicConnection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
topicSubscriber = topicSession.createSubscriber(topic);
topicSubscriber.setMessageListener(this);
MyExceptionListener l = new MyExceptionListener();
topicConnection.setExceptionListener(l);
topicConnection.start();
System.out.println("Connected with the server");
}catch(Exception a){ System.out.println("Could not establish JMS with server: " + a.toString());}
}
private class MyExceptionListener implements javax.jms.ExceptionListener{
public void onException(JMSException e){
try{
System.out.println("Error:" + e.toString());
System.out.println("Checking server for live..");
topicConnection.start();
System.out.println("Connected again with the server..");
}catch(Exception a){System.out.println("Server is out of reach...");}
}
}
}
Please help...
Thanks,
Suv -
4. Re: PLSSSS HELP, ITS URGENT
trosenbaum Oct 30, 2002 12:31 PM (in response to suvankar17)I'm not sure if the Topic object will
remain valid across server reboot. You'll
have to discover that for yourself. I fairly sure
that the TopiConnection, TopicSession,
and TopicSubscriber will all be invalid
after the server goes down.
Thus, after detecting the server failure
in your exception listener, you probably need
to do:
1) close the TopicSubscriber
2) close the TopicSession
3) close the TopicConnection
4) recreate the TopicConnection
5) start the topic connection
6) recreate the TopicSession
7) recreate the TopicSubscriber
At step 4) and 5), keep trying while errors occur
until successful before proceeding to step 6).