You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by me...@apache.org on 2007/03/20 22:56:58 UTC
svn commit: r520614 -
/incubator/tuscany/java/sca/contrib/discovery/jms/src/main/java/org/apache/tuscany/service/discovery/jms/JmsDiscoveryService.java
Author: meerajk
Date: Tue Mar 20 14:56:57 2007
New Revision: 520614
URL: http://svn.apache.org/viewvc?view=rev&rev=520614
Log:
Added retry on stale connections.
Modified:
incubator/tuscany/java/sca/contrib/discovery/jms/src/main/java/org/apache/tuscany/service/discovery/jms/JmsDiscoveryService.java
Modified: incubator/tuscany/java/sca/contrib/discovery/jms/src/main/java/org/apache/tuscany/service/discovery/jms/JmsDiscoveryService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/contrib/discovery/jms/src/main/java/org/apache/tuscany/service/discovery/jms/JmsDiscoveryService.java?view=diff&rev=520614&r1=520613&r2=520614
==============================================================================
--- incubator/tuscany/java/sca/contrib/discovery/jms/src/main/java/org/apache/tuscany/service/discovery/jms/JmsDiscoveryService.java (original)
+++ incubator/tuscany/java/sca/contrib/discovery/jms/src/main/java/org/apache/tuscany/service/discovery/jms/JmsDiscoveryService.java Tue Mar 20 14:56:57 2007
@@ -20,6 +20,7 @@
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
+import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
@@ -87,7 +88,7 @@
* Starts the service and sets up the message listener.
*/
@Override
- protected void onStart() throws DiscoveryException {
+ protected synchronized void onStart() throws DiscoveryException {
String runtimeId = getRuntimeInfo().getRuntimeId();
@@ -96,6 +97,21 @@
connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
connection = connectionFactory.createConnection();
+ connection.setExceptionListener(new ExceptionListener() {
+ public void onException(JMSException jmsException) {
+ // Try restarting: TODO this may need further refinement
+ try {
+ onStop();
+ } catch (DiscoveryException ex) {
+ ex.printStackTrace();
+ }
+ try {
+ onStart();
+ } catch (DiscoveryException ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
receiverSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
messageConsumer = receiverSession.createConsumer(topic);
@@ -113,21 +129,26 @@
* Closes the connection.
*/
@Override
- protected void onStop() throws DiscoveryException {
+ protected synchronized void onStop() throws DiscoveryException {
try {
-
receiverSession.close();
- connection.close();
} catch (JMSException ex) {
throw new DiscoveryException(ex);
+ } finally {
+ try {
+ connection.close();
+ } catch (JMSException ex) {
+ throw new DiscoveryException(ex);
+ }
}
+
}
/**
* Sends the message.
*/
- public int sendMessage(String runtimeId, XMLStreamReader reader) throws DiscoveryException {
+ public synchronized int sendMessage(String runtimeId, XMLStreamReader reader) throws DiscoveryException {
try {
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org