Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #19] fix '#' check in topicFilter #25

Merged
merged 3 commits into from
Mar 15, 2022

Conversation

ferrirW
Copy link
Contributor

@ferrirW ferrirW commented Mar 11, 2022

link #19, some code can be optimized:

  1. ADDFLAG & JINFLAG should be replaced with PLUS_SIGN & NUMBER_SIGN refer to unicode

  2. Some redundant containsKey before putIfAbsent()

  3. buildIntanceName -> buildInstanceName

  4. TopicUtils.isMatch("t/t1/t2/", "t/#/t2/") should be false but return true now.(I know some client will do this check like poho, however, it is better for the server to do a validation as well)

@tianliuliu
Copy link
Contributor

please make sure the ci pass

topicFilter = "t/t1/#/t3/";
Assert.assertFalse(TopicUtils.isMatch(topic, topicFilter));

topicFilter = "t/t1#/";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will "t/t1#/" appear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will "t/t1#/" appear?

Maybe misuse. Clients probably reject this type, but it's better for the server to check it itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -99,9 +99,7 @@ private void refreshWildcards(String firstTopic) {
queueNames.add(pubTopic);
Set<String> wildcards = matchWildcards(pubTopic);
if (wildcards != null && !wildcards.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 101 the return wildcards may never be null and the if judgment can be removed or not ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to removed. It's not expensive and could avoid problems that may arise from a change of matchWildcards() in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree that

Copy link
Member

@ShannonDing ShannonDing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ShannonDing ShannonDing linked an issue Mar 14, 2022 that may be closed by this pull request
@@ -61,9 +61,7 @@ public void cleanResource(String clientId,String channelId) {

public void put(CacheType cacheType, String channelId, int mqttMsgId) {
ConcurrentMap<String, Set<Integer>> cache = whichCache(cacheType);
if (!cache.containsKey(channelId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding judgment is mainly to avoid unnecessary temporary object generation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's my mistake. I just replaced them all, and don't notice this cache operation will be frequent.

@@ -61,9 +61,7 @@ public void cleanResource(String clientId,String channelId) {

public void put(CacheType cacheType, String channelId, int mqttMsgId) {
ConcurrentMap<String, Set<Integer>> cache = whichCache(cacheType);
if (!cache.containsKey(channelId)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's my mistake. I just replaced them all, and don't notice this cache operation will be frequent.

@@ -120,9 +120,7 @@ public void addSubscription(Session session, Set<Subscription> subscriptions) {
}

synchronized (topicCache) {
if (!topicCache.containsKey(topicFilter)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This place is for subscribe request, that will not be frequent, can I keep it? @pingww

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing why append '/' to the end of topic name?
4 participants