synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u...@apache.org
Subject svn commit: r603847 - in /webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms: JMSConnectionFactory.java JMSConstants.java JMSUtils.java
Date Thu, 13 Dec 2007 07:37:25 GMT
Author: upul
Date: Wed Dec 12 23:37:24 2007
New Revision: 603847

URL: http://svn.apache.org/viewvc?rev=603847&view=rev
Log:
added jms connection reconnect function when error

Modified:
    webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSConnectionFactory.java
    webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSConstants.java
    webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSUtils.java

Modified: webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSConnectionFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSConnectionFactory.java?rev=603847&r1=603846&r2=603847&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSConnectionFactory.java
(original)
+++ webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSConnectionFactory.java
Wed Dec 12 23:37:24 2007
@@ -72,7 +72,7 @@
  * </parameter>
  * </transportReceiver>
  */
-public class JMSConnectionFactory {
+public class JMSConnectionFactory implements ExceptionListener {
 
     private static final Log log = LogFactory.getLog(JMSConnectionFactory.class);
 
@@ -102,6 +102,8 @@
     private JMSMessageReceiver jmsMessageReceiver = null;
     /** The axis2 configuration context */
     private ConfigurationContext cfgCtx = null;
+    /** if connection dropped, reconnect timeout in milliseconds; default 30 seconds */
+    private long reconnectTimeout = 30000;
 
     /**
      * Create a JMSConnectionFactory for the given [axis2] name the
@@ -248,6 +250,8 @@
                     connection = conFac.createConnection();
                 }
             }
+            
+            connection.setExceptionListener(this);
 
         } catch (JMSException e) {
             handleException("Error connecting to Connection Factory : " + connFactoryJNDIName,
e);
@@ -587,5 +591,40 @@
 
     public void setConnectionFactoryType(String connectionFactoryType) {
       this.connectionFactoryType = connectionFactoryType;
+    }
+    
+    public long getReconnectTimeout() {
+      return reconnectTimeout;
+    }
+
+    public void setReconnectTimeout(long reconnectTimeout) {
+      this.reconnectTimeout = reconnectTimeout;
+    }
+
+    public void onException(JMSException e) {
+      log.error("jms error ", e);
+      boolean wasError = true;
+      
+      // try to connect
+      // if error occurs wait and try again
+      while(wasError == true) {
+        
+        try {
+          connectAndListen();
+          wasError = false;
+          
+        } catch (Exception e1) {
+          log.error("jms reconnect error ", e);
+        } 
+        
+        if(wasError == true) {
+          try {
+            Thread.sleep(getReconnectTimeout());
+          } catch (InterruptedException e2) {
+            e2.printStackTrace();
+          }
+        }
+      } // wasError
+      
     }
 }

Modified: webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSConstants.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSConstants.java?rev=603847&r1=603846&r2=603847&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSConstants.java
(original)
+++ webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSConstants.java
Wed Dec 12 23:37:24 2007
@@ -73,6 +73,10 @@
      */
     public static final String CONFAC_PARAM = "transport.jms.ConnectionFactory";
     /**
+     * If reconnect timeout if connection error occurs in seconds
+     */
+    public static final String RECONNECT_TIMEOUT = "transport.jms.ReconnectTimeout";
+    /**
      * Connection factory type if using JMS 1.0, either DESTINATION_TYPE_QUEUE or DESTINATION_TYPE_TOPIC
      */
     public static final String CONFAC_TYPE = "transport.jms.ConnectionFactoryType";

Modified: webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSUtils.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSUtils.java?rev=603847&r1=603846&r2=603847&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSUtils.java
(original)
+++ webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSUtils.java
Wed Dec 12 23:37:24 2007
@@ -273,6 +273,13 @@
             if (JMSConstants.CONFAC_TYPE.equals(p.getName())) {
                 String connectionFactoryType = (String) p.getValue();
                 jmsConFactory.setConnectionFactoryType(connectionFactoryType);
+            
+            } else if (JMSConstants.RECONNECT_TIMEOUT.equals(p.getName())) {
+              String strTimeout = (String) p.getValue();
+              int reconnectTimeoutSeconds = Integer.parseInt(strTimeout);
+              long reconnectTimeoutMillis = reconnectTimeoutSeconds * 1000;
+              jmsConFactory.setReconnectTimeout(reconnectTimeoutMillis);
+              
             } else if (Context.INITIAL_CONTEXT_FACTORY.equals(p.getName())) {
                 jmsConFactory.addJNDIContextProperty(
                     Context.INITIAL_CONTEXT_FACTORY, (String) p.getValue());



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message