You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2009/09/28 16:48:03 UTC

svn commit: r819567 - /incubator/uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java

Author: cwiklik
Date: Mon Sep 28 14:48:03 2009
New Revision: 819567

URL: http://svn.apache.org/viewvc?rev=819567&view=rev
Log:
UIMA-1433 Improved detection of bad connection. In addition to detecting closed connection also tests connection state. This should detect 'Inactive connection' problems

Modified:
    incubator/uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java

Modified: incubator/uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java?rev=819567&r1=819566&r2=819567&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java Mon Sep 28 14:48:03 2009
@@ -291,13 +291,32 @@
       ((TextMessage) msg).setText("");
     }
   }
-
+  private boolean connectionClosedOrInvalid() {
+    if ( sharedConnection == null ||
+         sharedConnection.getConnection() == null ||
+         ((ActiveMQConnection)sharedConnection.getConnection()).isClosed() ||
+         ((ActiveMQConnection)sharedConnection.getConnection()).isClosing() ||
+         ((ActiveMQConnection)sharedConnection.getConnection()).isTransportFailed()) {
+      return true;
+    }
+    return false;
+  }
   protected void setupConnection(String aBrokerURI) throws Exception {
     try {
       // Acquire global static semaphore
       sharedConnectionSemaphore.acquire();
-      if (sharedConnection == null) {
+      //  check the state of a connection
+      if ( connectionClosedOrInvalid() ) { // sharedConnection == null || sharedConnection.getConnection() == null || !) {
         ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(aBrokerURI);
+        if ( sharedConnection != null && sharedConnection.getConnection() != null ) {
+          try {
+            //  Cleanup so that we dont leak connections in a broker
+            sharedConnection.getConnection().close();
+          } catch( Exception ex) {
+            //  Ignore exception while closing a bad connection
+          }
+          
+        }
         Connection connection = factory.createConnection();
         // This only effects Consumer
         addPrefetch((ActiveMQConnection) connection);