Removed TreeNode's parent reference to avoid maintaning a reference that could keep live big trees (solves #119 and #126)
This commit is contained in:
@@ -90,7 +90,7 @@ public class SubscriptionsStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private AtomicReference<TreeNode> subscriptions = new AtomicReference<>(new TreeNode(null));
|
private AtomicReference<TreeNode> subscriptions = new AtomicReference<>(new TreeNode());
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(SubscriptionsStore.class);
|
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());
|
LOG.debug("Re-subscribing {} to topic {}", subscription.getClientId(), subscription.getTopicFilter());
|
||||||
add(subscription);
|
add(subscription);
|
||||||
}
|
}
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isTraceEnabled()) {
|
||||||
LOG.debug("Finished loading. Subscription tree after {}", dumpTree());
|
LOG.trace("Finished loading. Subscription tree after {}", dumpTree());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,13 +146,13 @@ public class SubscriptionsStore {
|
|||||||
if ((matchingChildren = current.childWithToken(token)) != null) {
|
if ((matchingChildren = current.childWithToken(token)) != null) {
|
||||||
//copy the traversed node
|
//copy the traversed node
|
||||||
current = matchingChildren.copy();
|
current = matchingChildren.copy();
|
||||||
current.m_parent = parent;
|
// current.m_parent = parent;
|
||||||
//update the child just added in the children list
|
//update the child just added in the children list
|
||||||
parent.updateChild(matchingChildren, current);
|
parent.updateChild(matchingChildren, current);
|
||||||
parent = current;
|
parent = current;
|
||||||
} else {
|
} else {
|
||||||
//create a new node for the newly inserted token
|
//create a new node for the newly inserted token
|
||||||
matchingChildren = new TreeNode(current);
|
matchingChildren = new TreeNode(/*current*/);
|
||||||
matchingChildren.setToken(token);
|
matchingChildren.setToken(token);
|
||||||
current.addChild(matchingChildren);
|
current.addChild(matchingChildren);
|
||||||
current = matchingChildren;
|
current = matchingChildren;
|
||||||
|
|||||||
@@ -28,13 +28,11 @@ class TreeNode {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeNode m_parent;
|
|
||||||
Token m_token;
|
Token m_token;
|
||||||
List<TreeNode> m_children = new ArrayList<>();
|
List<TreeNode> m_children = new ArrayList<>();
|
||||||
List<Subscription> m_subscriptions = new ArrayList<>();
|
List<Subscription> m_subscriptions = new ArrayList<>();
|
||||||
|
|
||||||
TreeNode(TreeNode parent) {
|
TreeNode() {
|
||||||
this.m_parent = parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Token getToken() {
|
Token getToken() {
|
||||||
@@ -70,13 +68,9 @@ class TreeNode {
|
|||||||
* Copy the token and the children.
|
* Copy the token and the children.
|
||||||
* */
|
* */
|
||||||
TreeNode copy() {
|
TreeNode copy() {
|
||||||
final TreeNode copy = new TreeNode(this);
|
final TreeNode copy = new TreeNode();
|
||||||
copy.m_parent = m_parent;
|
|
||||||
copy.m_children = new ArrayList<>(m_children);
|
copy.m_children = new ArrayList<>(m_children);
|
||||||
copy.m_subscriptions = new ArrayList<>(m_subscriptions.size());
|
copy.m_subscriptions = new ArrayList<>(m_subscriptions);
|
||||||
for (Subscription sub : m_subscriptions) {
|
|
||||||
copy.m_subscriptions.add(new Subscription(sub));
|
|
||||||
}
|
|
||||||
copy.m_token = m_token;
|
copy.m_token = m_token;
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ public class SubscriptionsStoreTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecreatePath_emptyRoot() {
|
public void testRecreatePath_emptyRoot() {
|
||||||
TreeNode oldRoot = new TreeNode(null);
|
TreeNode oldRoot = new TreeNode();
|
||||||
final SubscriptionsStore.NodeCouple resp = store.recreatePath("/finance", oldRoot);
|
final SubscriptionsStore.NodeCouple resp = store.recreatePath("/finance", oldRoot);
|
||||||
|
|
||||||
//Verify
|
//Verify
|
||||||
@@ -416,7 +416,7 @@ public class SubscriptionsStoreTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecreatePath_1layer_tree() {
|
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 respFinance = store.recreatePath("/finance", oldRoot);
|
||||||
final SubscriptionsStore.NodeCouple respPlus = store.recreatePath("/+", respFinance.root);
|
final SubscriptionsStore.NodeCouple respPlus = store.recreatePath("/+", respFinance.root);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class TreeNodeTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddSubscriptionOverwriteAnExistingWithDifferentCleanSessionFlag() throws Exception {
|
public void testAddSubscriptionOverwriteAnExistingWithDifferentCleanSessionFlag() throws Exception {
|
||||||
TreeNode root = new TreeNode(null);
|
TreeNode root = new TreeNode();
|
||||||
Subscription existingSub = new Subscription(CLIENT_ID, "/topic", LEAST_ONE, false);
|
Subscription existingSub = new Subscription(CLIENT_ID, "/topic", LEAST_ONE, false);
|
||||||
root.addSubscription(existingSub);
|
root.addSubscription(existingSub);
|
||||||
Set<Subscription> subs = root.findAllByClientID(CLIENT_ID);
|
Set<Subscription> subs = root.findAllByClientID(CLIENT_ID);
|
||||||
|
|||||||
Reference in New Issue
Block a user