1- package javasabr .mqtt .model .topic .tree ;
1+ package javasabr .mqtt .model .subscriber .tree ;
22
33import java .util .function .Supplier ;
44import javasabr .mqtt .base .util .DebugUtils ;
2222@ Getter (AccessLevel .PACKAGE )
2323@ Accessors (fluent = true , chain = false )
2424@ FieldDefaults (level = AccessLevel .PRIVATE )
25- class TopicNode extends TopicTreeBase {
25+ class SubscriberNode extends SubscriberTreeBase {
2626
27- private final static Supplier <TopicNode > TOPIC_NODE_FACTORY = TopicNode ::new ;
27+ private final static Supplier <SubscriberNode > SUBSCRIBER_NODE_FACTORY = SubscriberNode ::new ;
2828
2929 static {
3030 DebugUtils .registerIncludedFields ("childNodes" , "subscribers" );
3131 }
3232
3333 @ Nullable
34- volatile LockableRefToRefDictionary <String , TopicNode > childNodes ;
34+ volatile LockableRefToRefDictionary <String , SubscriberNode > childNodes ;
3535 @ Nullable
3636 volatile LockableArray <Subscriber > subscribers ;
3737
@@ -43,15 +43,15 @@ public SingleSubscriber subscribe(int level, SubscriptionOwner owner, Subscripti
4343 if (level == topicFilter .levelsCount ()) {
4444 return addSubscriber (getOrCreateSubscribers (), owner , subscription , topicFilter );
4545 }
46- TopicNode childNode = getOrCreateChildNode (topicFilter .segment (level ));
46+ SubscriberNode childNode = getOrCreateChildNode (topicFilter .segment (level ));
4747 return childNode .subscribe (level + 1 , owner , subscription , topicFilter );
4848 }
4949
5050 public boolean unsubscribe (int level , SubscriptionOwner owner , TopicFilter topicFilter ) {
5151 if (level == topicFilter .levelsCount ()) {
5252 return removeSubscriber (subscribers (), owner , topicFilter );
5353 }
54- TopicNode childNode = getOrCreateChildNode (topicFilter .segment (level ));
54+ SubscriberNode childNode = getOrCreateChildNode (topicFilter .segment (level ));
5555 return childNode .unsubscribe (level + 1 , owner , topicFilter );
5656 }
5757
@@ -67,14 +67,14 @@ private void exactlyTopicMatch(
6767 int lastLevel ,
6868 MutableArray <SingleSubscriber > result ) {
6969 String segment = topicName .segment (level );
70- TopicNode topicNode = childNode (segment );
71- if (topicNode == null ) {
70+ SubscriberNode subscriberNode = childNode (segment );
71+ if (subscriberNode == null ) {
7272 return ;
7373 }
7474 if (level == lastLevel ) {
75- appendSubscribersTo (result , topicNode );
75+ appendSubscribersTo (result , subscriberNode );
7676 } else if (level < lastLevel ) {
77- topicNode .matchesTo (level + 1 , topicName , lastLevel , result );
77+ subscriberNode .matchesTo (level + 1 , topicName , lastLevel , result );
7878 }
7979 }
8080
@@ -83,47 +83,47 @@ private void singleWildcardTopicMatch(
8383 TopicName topicName ,
8484 int lastLevel ,
8585 MutableArray <SingleSubscriber > result ) {
86- TopicNode topicNode = childNode (TopicFilter .SINGLE_LEVEL_WILDCARD );
87- if (topicNode == null ) {
86+ SubscriberNode subscriberNode = childNode (TopicFilter .SINGLE_LEVEL_WILDCARD );
87+ if (subscriberNode == null ) {
8888 return ;
8989 }
9090 if (level == lastLevel ) {
91- appendSubscribersTo (result , topicNode );
91+ appendSubscribersTo (result , subscriberNode );
9292 } else if (level < lastLevel ) {
93- topicNode .matchesTo (level + 1 , topicName , lastLevel , result );
93+ subscriberNode .matchesTo (level + 1 , topicName , lastLevel , result );
9494 }
9595 }
9696
9797 private void multiWildcardTopicMatch (MutableArray <SingleSubscriber > result ) {
98- TopicNode topicNode = childNode (TopicFilter .MULTI_LEVEL_WILDCARD );
99- if (topicNode != null ) {
100- appendSubscribersTo (result , topicNode );
98+ SubscriberNode subscriberNode = childNode (TopicFilter .MULTI_LEVEL_WILDCARD );
99+ if (subscriberNode != null ) {
100+ appendSubscribersTo (result , subscriberNode );
101101 }
102102 }
103103
104- private TopicNode getOrCreateChildNode (String segment ) {
105- LockableRefToRefDictionary <String , TopicNode > childNodes = getOrCreateChildNodes ();
104+ private SubscriberNode getOrCreateChildNode (String segment ) {
105+ LockableRefToRefDictionary <String , SubscriberNode > childNodes = getOrCreateChildNodes ();
106106 long stamp = childNodes .readLock ();
107107 try {
108- TopicNode topicNode = childNodes .get (segment );
109- if (topicNode != null ) {
110- return topicNode ;
108+ SubscriberNode subscriberNode = childNodes .get (segment );
109+ if (subscriberNode != null ) {
110+ return subscriberNode ;
111111 }
112112 } finally {
113113 childNodes .readUnlock (stamp );
114114 }
115115 stamp = childNodes .writeLock ();
116116 try {
117117 //noinspection DataFlowIssue
118- return childNodes .getOrCompute (segment , TOPIC_NODE_FACTORY );
118+ return childNodes .getOrCompute (segment , SUBSCRIBER_NODE_FACTORY );
119119 } finally {
120120 childNodes .writeUnlock (stamp );
121121 }
122122 }
123123
124124 @ Nullable
125- private TopicNode childNode (String segment ) {
126- LockableRefToRefDictionary <String , TopicNode > childNodes = childNodes ();
125+ private SubscriberNode childNode (String segment ) {
126+ LockableRefToRefDictionary <String , SubscriberNode > childNodes = childNodes ();
127127 if (childNodes == null ) {
128128 return null ;
129129 }
@@ -135,7 +135,7 @@ private TopicNode childNode(String segment) {
135135 }
136136 }
137137
138- private LockableRefToRefDictionary <String , TopicNode > getOrCreateChildNodes () {
138+ private LockableRefToRefDictionary <String , SubscriberNode > getOrCreateChildNodes () {
139139 if (childNodes == null ) {
140140 synchronized (this ) {
141141 if (childNodes == null ) {
0 commit comments