diff --git a/broker/src/main/java/io/moquette/spi/impl/subscriptions/SubscriptionsStore.java b/broker/src/main/java/io/moquette/spi/impl/subscriptions/SubscriptionsStore.java index c6f8e21e..914722bc 100644 --- a/broker/src/main/java/io/moquette/spi/impl/subscriptions/SubscriptionsStore.java +++ b/broker/src/main/java/io/moquette/spi/impl/subscriptions/SubscriptionsStore.java @@ -90,7 +90,7 @@ public class SubscriptionsStore { } } - private AtomicReference subscriptions = new AtomicReference<>(new TreeNode(null)); + private AtomicReference subscriptions = new AtomicReference<>(new TreeNode()); private static final Logger LOG = LoggerFactory.getLogger(SubscriptionsStore.class); /** @@ -109,8 +109,8 @@ public class SubscriptionsStore { LOG.debug("Re-subscribing {} to topic {}", subscription.getClientId(), subscription.getTopicFilter()); add(subscription); } - if (LOG.isDebugEnabled()) { - LOG.debug("Finished loading. Subscription tree after {}", dumpTree()); + if (LOG.isTraceEnabled()) { + LOG.trace("Finished loading. Subscription tree after {}", dumpTree()); } } @@ -146,13 +146,13 @@ public class SubscriptionsStore { if ((matchingChildren = current.childWithToken(token)) != null) { //copy the traversed node current = matchingChildren.copy(); - current.m_parent = parent; +// current.m_parent = parent; //update the child just added in the children list parent.updateChild(matchingChildren, current); parent = current; } else { //create a new node for the newly inserted token - matchingChildren = new TreeNode(current); + matchingChildren = new TreeNode(/*current*/); matchingChildren.setToken(token); current.addChild(matchingChildren); current = matchingChildren; diff --git a/broker/src/main/java/io/moquette/spi/impl/subscriptions/TreeNode.java b/broker/src/main/java/io/moquette/spi/impl/subscriptions/TreeNode.java index 50a20e40..657d7b02 100644 --- a/broker/src/main/java/io/moquette/spi/impl/subscriptions/TreeNode.java +++ b/broker/src/main/java/io/moquette/spi/impl/subscriptions/TreeNode.java @@ -28,13 +28,11 @@ class TreeNode { } - TreeNode m_parent; Token m_token; List m_children = new ArrayList<>(); List m_subscriptions = new ArrayList<>(); - TreeNode(TreeNode parent) { - this.m_parent = parent; + TreeNode() { } Token getToken() { @@ -70,13 +68,9 @@ class TreeNode { * Copy the token and the children. * */ TreeNode copy() { - final TreeNode copy = new TreeNode(this); - copy.m_parent = m_parent; + final TreeNode copy = new TreeNode(); copy.m_children = new ArrayList<>(m_children); - copy.m_subscriptions = new ArrayList<>(m_subscriptions.size()); - for (Subscription sub : m_subscriptions) { - copy.m_subscriptions.add(new Subscription(sub)); - } + copy.m_subscriptions = new ArrayList<>(m_subscriptions); copy.m_token = m_token; return copy; } diff --git a/broker/src/test/java/io/moquette/spi/impl/subscriptions/SubscriptionsStoreTest.java b/broker/src/test/java/io/moquette/spi/impl/subscriptions/SubscriptionsStoreTest.java index 970aee62..a9f9518c 100644 --- a/broker/src/test/java/io/moquette/spi/impl/subscriptions/SubscriptionsStoreTest.java +++ b/broker/src/test/java/io/moquette/spi/impl/subscriptions/SubscriptionsStoreTest.java @@ -404,7 +404,7 @@ public class SubscriptionsStoreTest { @Test public void testRecreatePath_emptyRoot() { - TreeNode oldRoot = new TreeNode(null); + TreeNode oldRoot = new TreeNode(); final SubscriptionsStore.NodeCouple resp = store.recreatePath("/finance", oldRoot); //Verify @@ -416,7 +416,7 @@ public class SubscriptionsStoreTest { @Test public void testRecreatePath_1layer_tree() { - TreeNode oldRoot = new TreeNode(null); + TreeNode oldRoot = new TreeNode(); final SubscriptionsStore.NodeCouple respFinance = store.recreatePath("/finance", oldRoot); final SubscriptionsStore.NodeCouple respPlus = store.recreatePath("/+", respFinance.root); diff --git a/broker/src/test/java/io/moquette/spi/impl/subscriptions/TreeNodeTest.java b/broker/src/test/java/io/moquette/spi/impl/subscriptions/TreeNodeTest.java index 89bff7b7..d733c04e 100644 --- a/broker/src/test/java/io/moquette/spi/impl/subscriptions/TreeNodeTest.java +++ b/broker/src/test/java/io/moquette/spi/impl/subscriptions/TreeNodeTest.java @@ -13,7 +13,7 @@ public class TreeNodeTest { @Test public void testAddSubscriptionOverwriteAnExistingWithDifferentCleanSessionFlag() throws Exception { - TreeNode root = new TreeNode(null); + TreeNode root = new TreeNode(); Subscription existingSub = new Subscription(CLIENT_ID, "/topic", LEAST_ONE, false); root.addSubscription(existingSub); Set subs = root.findAllByClientID(CLIENT_ID);