You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2012/09/05 15:51:39 UTC

git commit: Use the correct stream id for error message

Updated Branches:
  refs/heads/trunk 1e289fa0e -> a9d4e649f


Use the correct stream id for error message


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/a9d4e649
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a9d4e649
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a9d4e649

Branch: refs/heads/trunk
Commit: a9d4e649ffee05d8ce50685bdbc08a6572657194
Parents: 1e289fa
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Wed Sep 5 15:51:32 2012 +0200
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Wed Sep 5 15:51:32 2012 +0200

----------------------------------------------------------------------
 .../org/apache/cassandra/transport/Message.java    |   30 ++++++++++-----
 1 files changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/a9d4e649/src/java/org/apache/cassandra/transport/Message.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/Message.java b/src/java/org/apache/cassandra/transport/Message.java
index 0a51ad2..85de3e4 100644
--- a/src/java/org/apache/cassandra/transport/Message.java
+++ b/src/java/org/apache/cassandra/transport/Message.java
@@ -124,9 +124,10 @@ public abstract class Message
         return connection;
     }
 
-    public void setStreamId(int streamId)
+    public Message setStreamId(int streamId)
     {
         this.streamId = streamId;
+        return this;
     }
 
     public int getStreamId()
@@ -197,19 +198,28 @@ public abstract class Message
                 throw new ProtocolException("Invalid response message received, expecting requests");
 
             Request request = (Request)e.getMessage();
-            Connection connection = request.connection();
-            connection.validateNewMessage(request.type);
 
-            logger.debug("Received: " + request);
+            try
+            {
+                Connection connection = request.connection();
+                connection.validateNewMessage(request.type);
+
+                logger.debug("Received: " + request);
 
-            Response response = request.execute();
-            response.setStreamId(request.getStreamId());
-            response.attach(connection);
-            response.connection().applyStateTransition(request.type, response.type);
+                Response response = request.execute();
+                response.setStreamId(request.getStreamId());
+                response.attach(connection);
+                response.connection().applyStateTransition(request.type, response.type);
 
-            logger.debug("Responding: " + response);
+                logger.debug("Responding: " + response);
 
-            e.getChannel().write(response);
+                e.getChannel().write(response);
+            }
+            catch (Exception ex)
+            {
+                // Don't let the exception propagate to exceptionCaught() if we can help it so that we can assign the right streamID.
+                e.getChannel().write(ErrorMessage.fromException(ex).setStreamId(request.getStreamId()));
+            }
         }
 
         @Override