activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From martyntay...@apache.org
Subject [1/3] activemq-artemis git commit: ARTEMIS-1175 Fixing Memory Leak
Date Fri, 26 May 2017 10:17:10 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 28a60bcdf -> de9cc2e70


ARTEMIS-1175 Fixing Memory Leak


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

Branch: refs/heads/master
Commit: f63ffc7af5d96fd1a6785a12d5ce3ae504831269
Parents: b136fed
Author: Clebert Suconic <clebertsuconic@apache.org>
Authored: Thu May 25 10:33:19 2017 -0400
Committer: Martyn Taylor <mtaylor@redhat.com>
Committed: Fri May 26 11:16:41 2017 +0100

----------------------------------------------------------------------
 .../core/protocol/mqtt/MQTTSessionState.java    | 23 ++++++++++++--------
 1 file changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f63ffc7a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSessionState.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSessionState.java
b/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSessionState.java
index 74bc101..4b5c648 100644
--- a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSessionState.java
+++ b/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSessionState.java
@@ -41,7 +41,7 @@ public class MQTTSessionState {
 
    private final ConcurrentMap<String, Map<Long, Integer>> addressMessageMap
= new ConcurrentHashMap<>();
 
-   private final Set<Integer>  pubRec = new HashSet<>();
+   private final Set<Integer> pubRec = new HashSet<>();
 
    private boolean attached = false;
 
@@ -128,7 +128,7 @@ public class MQTTSessionState {
 
    public class OutboundStore {
 
-      private HashMap<String, Integer> artemisToMqttMessageMap = new HashMap<>();
+      private HashMap<Pair<Long, Long>, Integer> artemisToMqttMessageMap = new
HashMap<>();
 
       private HashMap<Integer, Pair<Long, Long>> mqttToServerIds = new HashMap<>();
 
@@ -136,9 +136,13 @@ public class MQTTSessionState {
 
       private final AtomicInteger ids = new AtomicInteger(0);
 
-      public int generateMqttId(long serverId, long consumerId) {
+      private Pair<Long, Long> generateKey(long messageId, long consumerID) {
+         return new Pair<>(messageId, consumerID);
+      }
+
+      public int generateMqttId(long messageId, long consumerId) {
          synchronized (dataStoreLock) {
-            Integer id = artemisToMqttMessageMap.get(consumerId + ":" + serverId);
+            Integer id = artemisToMqttMessageMap.get(generateKey(messageId, consumerId));
             if (id == null) {
                ids.compareAndSet(Short.MAX_VALUE, 1);
                id = ids.addAndGet(1);
@@ -147,19 +151,20 @@ public class MQTTSessionState {
          }
       }
 
-      public void publish(int mqtt, long serverId, long consumerId) {
+      public void publish(int mqtt, long messageId, long consumerId) {
          synchronized (dataStoreLock) {
-            artemisToMqttMessageMap.put(consumerId + ":" + serverId, mqtt);
-            mqttToServerIds.put(mqtt, new Pair(serverId, consumerId));
+            Pair<Long, Long> key = generateKey(messageId, consumerId);
+            artemisToMqttMessageMap.put(key, mqtt);
+            mqttToServerIds.put(mqtt, key);
          }
       }
 
       public Pair<Long, Long> publishAckd(int mqtt) {
          synchronized (dataStoreLock) {
-            Pair p =  mqttToServerIds.remove(mqtt);
+            Pair p = mqttToServerIds.remove(mqtt);
             if (p != null) {
                mqttToServerIds.remove(p.getA());
-               artemisToMqttMessageMap.remove(p.getB() + ":" + p.getA());
+               artemisToMqttMessageMap.remove(p);
             }
             return p;
          }


Mime
View raw message