activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject [1/2] activemq git commit: Fix Impossible Cast issues in MemoryTopicSub: - recoverSubscription() -- map is defined as LinkedHashMap<MessageId, Message> -- msg is defined as <map> entry.getValue() so must be a Message -- condition if (msg.getClass() == Me
Date Mon, 01 Feb 2016 13:08:17 GMT
Repository: activemq
Updated Branches:
  refs/heads/activemq-5.13.x 648d08391 -> f514b1571


Fix Impossible Cast issues in MemoryTopicSub:
- recoverSubscription()
-- map is defined as LinkedHashMap<MessageId, Message>
-- msg is defined as <map> entry.getValue() so must be a Message
-- condition if (msg.getClass() == MessageId.class) could never be true
-- no need to cast at all when using generics

- recoverNextMessages()
-- basically same code copy/pasted so same fix

Removed 2 conditions from ServerSessionPoolImpl that would result in impossible casts. Conditions
removed were trying to cast ActiveMQQueueSession and ActiveMQTopicSession to ActiveMQSession
which is illegal.

Since it isn't obvious what to do if you get an ActiveMQQueueSession or ActiveMQTopicSession
from getServerSession() I make it fall back to the else condition which raises an async exception.
This is better than getting a ClassCastException at runtime.

Remove impossible cast in MemoryMessageStore

(cherry picked from commit 4a937def7db8d5f8229c95c05843f98de1803068)


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

Branch: refs/heads/activemq-5.13.x
Commit: 0b481903aa723bcef6d6d88c3f6b97320fde382c
Parents: 648d083
Author: Marc Breslow <marc.breslow@devfactory.com>
Authored: Thu Jan 28 16:39:29 2016 -0500
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Committed: Mon Feb 1 13:07:26 2016 +0000

----------------------------------------------------------------------
 .../activemq/store/memory/MemoryMessageStore.java |  8 ++------
 .../activemq/store/memory/MemoryTopicSub.java     | 18 +++++-------------
 .../apache/activemq/ra/ServerSessionPoolImpl.java |  4 ----
 3 files changed, 7 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/0b481903/activemq-broker/src/main/java/org/apache/activemq/store/memory/MemoryMessageStore.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/store/memory/MemoryMessageStore.java
b/activemq-broker/src/main/java/org/apache/activemq/store/memory/MemoryMessageStore.java
index 6fc7fbd..b32a811 100755
--- a/activemq-broker/src/main/java/org/apache/activemq/store/memory/MemoryMessageStore.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/store/memory/MemoryMessageStore.java
@@ -108,12 +108,8 @@ public class MemoryMessageStore extends AbstractMessageStore {
         // here
         synchronized (messageTable) {
             for (Iterator<Message> iter = messageTable.values().iterator(); iter.hasNext();)
{
-                Object msg = iter.next();
-                if (msg.getClass() == MessageId.class) {
-                    listener.recoverMessageReference((MessageId)msg);
-                } else {
-                    listener.recoverMessage((Message)msg);
-                }
+                Message msg = iter.next();
+                listener.recoverMessage(msg);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/activemq/blob/0b481903/activemq-broker/src/main/java/org/apache/activemq/store/memory/MemoryTopicSub.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/store/memory/MemoryTopicSub.java
b/activemq-broker/src/main/java/org/apache/activemq/store/memory/MemoryTopicSub.java
index fc986f2..3adf7b8 100755
--- a/activemq-broker/src/main/java/org/apache/activemq/store/memory/MemoryTopicSub.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/store/memory/MemoryTopicSub.java
@@ -72,12 +72,8 @@ class MemoryTopicSub {
     synchronized void recoverSubscription(MessageRecoveryListener listener) throws Exception
{
         for (Iterator<Entry<MessageId, Message>> iter = map.entrySet().iterator();
iter.hasNext();) {
             Entry<MessageId, Message> entry = iter.next();
-            Object msg = entry.getValue();
-            if (msg.getClass() == MessageId.class) {
-                listener.recoverMessageReference((MessageId)msg);
-            } else {
-                listener.recoverMessage((Message)msg);
-            }
+            Message msg = entry.getValue();
+            listener.recoverMessage(msg);
         }
     }
 
@@ -91,13 +87,9 @@ class MemoryTopicSub {
             Entry<MessageId, Message> entry = iter.next();
             if (pastLackBatch) {
                 count++;
-                Object msg = entry.getValue();
-                lastId = (MessageId)entry.getKey();
-                if (msg.getClass() == MessageId.class) {
-                    listener.recoverMessageReference((MessageId)msg);
-                } else {
-                    listener.recoverMessage((Message)msg);
-                }
+                Message msg = entry.getValue();
+                lastId = entry.getKey();
+                listener.recoverMessage(msg);
             } else {
                 pastLackBatch = entry.getKey().equals(lastBatch);
             }

http://git-wip-us.apache.org/repos/asf/activemq/blob/0b481903/activemq-ra/src/main/java/org/apache/activemq/ra/ServerSessionPoolImpl.java
----------------------------------------------------------------------
diff --git a/activemq-ra/src/main/java/org/apache/activemq/ra/ServerSessionPoolImpl.java b/activemq-ra/src/main/java/org/apache/activemq/ra/ServerSessionPoolImpl.java
index 393ed35..9db6df5 100755
--- a/activemq-ra/src/main/java/org/apache/activemq/ra/ServerSessionPoolImpl.java
+++ b/activemq-ra/src/main/java/org/apache/activemq/ra/ServerSessionPoolImpl.java
@@ -265,10 +265,6 @@ public class ServerSessionPoolImpl implements ServerSessionPool {
         ActiveMQSession session = null;
         if (s instanceof ActiveMQSession) {
             session = (ActiveMQSession) s;
-        } else if (s instanceof ActiveMQQueueSession) {
-            session = (ActiveMQSession) s;
-        } else if (s instanceof ActiveMQTopicSession) {
-            session = (ActiveMQSession) s;
         } else {
             activeMQAsfEndpointWorker.getConnection()
                     .onAsyncException(new JMSException(


Mime
View raw message