qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject svn commit: r1099288 - in /qpid/trunk/qpid/java: client/src/main/java/org/apache/qpid/client/ client/src/test/java/org/apache/qpid/test/unit/message/ common/src/main/java/org/apache/qpid/transport/
Date Tue, 03 May 2011 22:46:16 GMT
Author: rajith
Date: Tue May  3 22:46:16 2011
New Revision: 1099288

URL: http://svn.apache.org/viewvc?rev=1099288&view=rev
Log:
QPID-3233
If the underlying AMQP session gets closed, the JMS session is now notified along with details
that caused the session closure.
The JMS Session will throw an exception (with an error code and details) when a user accesses
the closed session.

Modified:
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java
    qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java
    qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java?rev=1099288&r1=1099287&r2=1099288&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java Tue May
 3 22:46:16 2011
@@ -567,6 +567,8 @@ public abstract class AMQSession<C exten
         close(-1);
     }
 
+    public abstract AMQException getLastException();
+    
     public void checkNotClosed() throws JMSException
     {
         try
@@ -575,16 +577,20 @@ public abstract class AMQSession<C exten
         }
         catch (IllegalStateException ise)
         {
-            // if the Connection has closed then we should throw any exception that has occurred
that we were not waiting for
-            AMQStateManager manager = _connection.getProtocolHandler().getStateManager();
+            AMQException ex = getLastException();
+            if (ex != null)
+            {
+                IllegalStateException ssnClosed = new IllegalStateException(
+                        "Session has been closed", ex.getErrorCode().toString());
 
-            if (manager.getCurrentState().equals(AMQState.CONNECTION_CLOSED) && manager.getLastException()
!= null)
+                ssnClosed.setLinkedException(ex);
+                ssnClosed.initCause(ex);
+                throw ssnClosed;
+            } 
+            else
             {
-                ise.setLinkedException(manager.getLastException());
-                ise.initCause(ise.getLinkedException());
+                throw ise;
             }
-
-            throw ise;
         }
     }
 

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java?rev=1099288&r1=1099287&r2=1099288&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java
(original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java
Tue May  3 22:46:16 2011
@@ -913,7 +913,21 @@ public class AMQSession_0_10 extends AMQ
         setCurrentException(exc);
     }
 
-    public void closed(Session ssn) {}
+    public void closed(Session ssn)
+    {
+        try
+        {
+            super.closed(null);
+        } catch (Exception e)
+        {
+            _logger.error("Error closing JMS session", e);
+        }
+    }
+
+    public AMQException getLastException()
+    {
+        return getCurrentException();
+    }
 
     protected AMQShortString declareQueue(final AMQDestination amqd, final AMQProtocolHandler
protocolHandler,
                                           final boolean noLocal, final boolean nowait)

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java?rev=1099288&r1=1099287&r2=1099288&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java Tue
May  3 22:46:16 2011
@@ -38,6 +38,7 @@ import org.apache.qpid.client.message.Re
 import org.apache.qpid.client.message.UnprocessedMessage;
 import org.apache.qpid.client.protocol.AMQProtocolHandler;
 import org.apache.qpid.client.state.AMQState;
+import org.apache.qpid.client.state.AMQStateManager;
 import org.apache.qpid.client.state.listener.SpecificMethodFrameListener;
 import org.apache.qpid.common.AMQPFilterTypes;
 import org.apache.qpid.framing.AMQFrame;
@@ -584,4 +585,35 @@ public final class AMQSession_0_8 extend
                             queueName == null ? null : new AMQShortString(queueName),
                             bindingKey == null ? null : new AMQShortString(bindingKey));
     }
+  
+
+    public AMQException getLastException()
+    {
+        // if the Connection has closed then we should throw any exception that
+        // has occurred that we were not waiting for
+        AMQStateManager manager = _connection.getProtocolHandler()
+                .getStateManager();
+        
+        Exception e = manager.getLastException();
+        if (manager.getCurrentState().equals(AMQState.CONNECTION_CLOSED)
+                && e != null)
+        {
+            if (e instanceof AMQException)
+            {
+                return (AMQException) e;
+            } 
+            else
+            {
+                AMQException amqe = new AMQException(AMQConstant
+                        .getConstant(AMQConstant.INTERNAL_ERROR.getCode()), 
+                        e.getMessage(), e.getCause());
+                return amqe;
+            }
+        } 
+        else
+        {
+            return null;
+        }
+    }
+
 }

Modified: qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java?rev=1099288&r1=1099287&r2=1099288&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java
(original)
+++ qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java
Tue May  3 22:46:16 2011
@@ -195,4 +195,10 @@ public class TestAMQSession extends AMQS
     {
         return false;
     }
+
+    @Override
+    public AMQException getLastException()
+    {
+        return null;
+    }
 }

Modified: qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java?rev=1099288&r1=1099287&r2=1099288&view=diff
==============================================================================
--- qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java (original)
+++ qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java Tue May
 3 22:46:16 2011
@@ -1031,7 +1031,8 @@ public class Session extends SessionInvo
 
         if(state == CLOSED)
         {
-            connection.removeSession(this);            
+            connection.removeSession(this);   
+            listener.closed(this);
         }
     }
 



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message