You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cs...@apache.org on 2016/02/01 14:05:35 UTC

[1/3] activemq git commit: Fix Impossible Cast issues in MemoryTopicSub: - recoverSubscription() -- map is defined as LinkedHashMap -- msg is defined as entry.getValue() so must be a Message -- condition if (msg.getClass() == Me

Repository: activemq
Updated Branches:
  refs/heads/master 5af5b59d3 -> 161730fda


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


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

Branch: refs/heads/master
Commit: 4a937def7db8d5f8229c95c05843f98de1803068
Parents: 5af5b59
Author: Marc Breslow <ma...@devfactory.com>
Authored: Thu Jan 28 16:39:29 2016 -0500
Committer: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Committed: Mon Feb 1 12:57:50 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/4a937def/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/4a937def/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/4a937def/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(


[2/3] activemq git commit: https://issues.apache.org/jira/browse/AMQ-6150

Posted by cs...@apache.org.
https://issues.apache.org/jira/browse/AMQ-6150

merging patch to fix casting issues

Thanks for Marc Breslow for the patch

This closes #166


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

Branch: refs/heads/master
Commit: 9361bc6a0f7219bfb8ba963bac8ec413fd1ebb58
Parents: 5af5b59 4a937de
Author: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Authored: Mon Feb 1 12:58:17 2016 +0000
Committer: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Committed: Mon Feb 1 13:03:01 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(-)
----------------------------------------------------------------------



[3/3] activemq git commit: https://issues.apache.org/jira/browse/AMQ-6150

Posted by cs...@apache.org.
https://issues.apache.org/jira/browse/AMQ-6150

code cleanup


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

Branch: refs/heads/master
Commit: 161730fda2a15c41a3f620a476ba49f841b87545
Parents: 9361bc6
Author: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Authored: Mon Feb 1 13:04:07 2016 +0000
Committer: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Committed: Mon Feb 1 13:04:07 2016 +0000

----------------------------------------------------------------------
 .../org/apache/activemq/ra/ServerSessionPoolImpl.java  | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/161730fd/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 9db6df5..94bca0c 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
@@ -31,9 +31,7 @@ import javax.resource.spi.UnavailableException;
 import javax.resource.spi.endpoint.MessageEndpoint;
 
 import org.apache.activemq.ActiveMQConnection;
-import org.apache.activemq.ActiveMQQueueSession;
 import org.apache.activemq.ActiveMQSession;
-import org.apache.activemq.ActiveMQTopicSession;
 import org.apache.activemq.command.MessageDispatch;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -76,11 +74,11 @@ public class ServerSessionPoolImpl implements ServerSessionPool {
             if (activationSpec.isUseRAManagedTransactionEnabled()) {
                 // The RA will manage the transaction commit.
                 endpoint = createEndpoint(null);
-                return new ServerSessionImpl(this, (ActiveMQSession)session, activeMQAsfEndpointWorker.workManager, endpoint, true, batchSize);
+                return new ServerSessionImpl(this, session, activeMQAsfEndpointWorker.workManager, endpoint, true, batchSize);
             } else {
                 // Give the container an object to manage to transaction with.
                 endpoint = createEndpoint(new LocalAndXATransaction(session.getTransactionContext()));
-                return new ServerSessionImpl(this, (ActiveMQSession)session, activeMQAsfEndpointWorker.workManager, endpoint, false, batchSize);
+                return new ServerSessionImpl(this, session, activeMQAsfEndpointWorker.workManager, endpoint, false, batchSize);
             }
         } catch (UnavailableException e) {
             // The container could be limiting us on the number of endpoints
@@ -102,6 +100,7 @@ public class ServerSessionPoolImpl implements ServerSessionPool {
 
     /**
      */
+    @Override
     public ServerSession getServerSession() throws JMSException {
         if (LOG.isDebugEnabled()) {
             LOG.debug("ServerSession requested.");
@@ -226,12 +225,12 @@ public class ServerSessionPoolImpl implements ServerSessionPool {
         }
         try {
             ActiveMQSession session = (ActiveMQSession)ss.getSession();
-            List l = session.getUnconsumedMessages();
+            List<MessageDispatch> l = session.getUnconsumedMessages();
             if (!l.isEmpty()) {
                 ActiveMQConnection connection = activeMQAsfEndpointWorker.getConnection();
                 if (connection != null) {
-                    for (Iterator i = l.iterator(); i.hasNext();) {
-                        MessageDispatch md = (MessageDispatch)i.next();
+                    for (Iterator<MessageDispatch> i = l.iterator(); i.hasNext();) {
+                        MessageDispatch md = i.next();
                         if (connection.hasDispatcher(md.getConsumerId())) {
                             dispatchToSession(md);
                             LOG.trace("on remove of {} redispatch of {}", session, md);