broker/SubscriptionsStore: code formatter used
This commit is contained in:
@@ -13,13 +13,13 @@
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
|
||||
package io.moquette.spi.impl.subscriptions;
|
||||
|
||||
import io.moquette.spi.ISessionsStore;
|
||||
import io.moquette.spi.ISessionsStore.ClientTopicCouple;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
@@ -33,6 +33,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
public class SubscriptionsStore {
|
||||
|
||||
public static class NodeCouple {
|
||||
|
||||
final TreeNode root;
|
||||
final TreeNode createdNode;
|
||||
|
||||
@@ -44,21 +45,27 @@ public class SubscriptionsStore {
|
||||
|
||||
/**
|
||||
* Check if the topic filter of the subscription is well formed
|
||||
* @param topicFilter the filter to validate
|
||||
*
|
||||
* @param topicFilter
|
||||
* the filter to validate
|
||||
* @return true if it's correct.
|
||||
* */
|
||||
*/
|
||||
public static boolean validate(String topicFilter) {
|
||||
try {
|
||||
parseTopic(topicFilter);
|
||||
return true;
|
||||
} catch (ParseException pex) {
|
||||
LOG.warn("The topic filter is malformed. TopicFilter = {}, cause = {}, errorMessage = {}.", topicFilter,
|
||||
pex.getCause(), pex.getMessage());
|
||||
LOG.warn(
|
||||
"The topic filter is malformed. TopicFilter = {}, cause = {}, errorMessage = {}.",
|
||||
topicFilter,
|
||||
pex.getCause(),
|
||||
pex.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IVisitor<T> {
|
||||
|
||||
void visit(TreeNode node, int deep);
|
||||
|
||||
T getResult();
|
||||
@@ -76,7 +83,8 @@ public class SubscriptionsStore {
|
||||
subScriptionsStr += indentTabs + couple.toString() + "\n";
|
||||
}
|
||||
s += node.getToken() == null ? "" : node.getToken().toString();
|
||||
s += "\n" + (node.m_subscriptions.isEmpty() ? indentTabs : "") + subScriptionsStr /*+ "\n"*/;
|
||||
s += "\n" + (node.m_subscriptions.isEmpty() ? indentTabs : "")
|
||||
+ subScriptionsStr /* + "\n" */;
|
||||
}
|
||||
|
||||
private String indentTabs(int deep) {
|
||||
@@ -99,9 +107,11 @@ public class SubscriptionsStore {
|
||||
private volatile ISessionsStore m_sessionsStore;
|
||||
|
||||
/**
|
||||
* Initialize the subscription tree with the list of subscriptions.
|
||||
* Maintained for compatibility reasons.
|
||||
* @param sessionsStore to be used as backing store from the subscription store.
|
||||
* Initialize the subscription tree with the list of subscriptions. Maintained for compatibility
|
||||
* reasons.
|
||||
*
|
||||
* @param sessionsStore
|
||||
* to be used as backing store from the subscription store.
|
||||
*/
|
||||
public void init(ISessionsStore sessionsStore) {
|
||||
LOG.info("Initializing subscriptions store...");
|
||||
@@ -113,7 +123,10 @@ public class SubscriptionsStore {
|
||||
}
|
||||
|
||||
for (ClientTopicCouple clientTopic : subscriptions) {
|
||||
LOG.info("Re-subscribing client to topic. ClientId = {}, topicFilter = {}.", clientTopic.clientID, clientTopic.topicFilter);
|
||||
LOG.info(
|
||||
"Re-subscribing client to topic. ClientId = {}, topicFilter = {}.",
|
||||
clientTopic.clientID,
|
||||
clientTopic.topicFilter);
|
||||
add(clientTopic);
|
||||
}
|
||||
if (LOG.isTraceEnabled()) {
|
||||
@@ -123,7 +136,8 @@ public class SubscriptionsStore {
|
||||
|
||||
public void add(ClientTopicCouple newSubscription) {
|
||||
/*
|
||||
* The topic filters have already been validated at the ProtocolProcessor. We can assume they are valid.
|
||||
* The topic filters have already been validated at the ProtocolProcessor. We can assume
|
||||
* they are valid.
|
||||
*/
|
||||
TreeNode oldRoot;
|
||||
NodeCouple couple;
|
||||
@@ -136,14 +150,16 @@ public class SubscriptionsStore {
|
||||
LOG.debug("A subscription has been added. Root = {}, oldRoot = {}.", couple.root, oldRoot);
|
||||
}
|
||||
|
||||
|
||||
protected NodeCouple recreatePath(String topic, final TreeNode oldRoot) {
|
||||
List<Token> tokens;
|
||||
try {
|
||||
tokens = parseTopic(topic);
|
||||
} catch (ParseException ex) {
|
||||
// TODO handle the parse exception
|
||||
LOG.error("The topic is malformed. Topic = {}, cause = {}, errorMessage = {}.", topic, ex.getCause(),
|
||||
LOG.error(
|
||||
"The topic is malformed. Topic = {}, cause = {}, errorMessage = {}.",
|
||||
topic,
|
||||
ex.getCause(),
|
||||
ex.getMessage());
|
||||
throw new IllegalArgumentException(ex.getMessage());
|
||||
}
|
||||
@@ -174,7 +190,8 @@ public class SubscriptionsStore {
|
||||
|
||||
public void removeSubscription(String topic, String clientID) {
|
||||
/*
|
||||
* The topic filters have already been validated at the ProtocolProcessor. We can assume they are valid.
|
||||
* The topic filters have already been validated at the ProtocolProcessor. We can assume
|
||||
* they are valid.
|
||||
*/
|
||||
TreeNode oldRoot;
|
||||
NodeCouple couple;
|
||||
@@ -188,9 +205,11 @@ public class SubscriptionsStore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit the topics tree to remove matching subscriptions with clientID.
|
||||
* It's a mutating structure operation so create a new subscription tree (partial or total).
|
||||
* @param clientID the client ID to remove.
|
||||
* Visit the topics tree to remove matching subscriptions with clientID. It's a mutating
|
||||
* structure operation so create a new subscription tree (partial or total).
|
||||
*
|
||||
* @param clientID
|
||||
* the client ID to remove.
|
||||
*/
|
||||
public void removeForClient(String clientID) {
|
||||
TreeNode oldRoot;
|
||||
@@ -202,13 +221,13 @@ public class SubscriptionsStore {
|
||||
} while (!subscriptions.compareAndSet(oldRoot, newRoot));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given a topic string return the clients subscriptions that matches it.
|
||||
* Topic string can't contain character # and + because they are reserved to
|
||||
* listeners subscriptions, and not topic publishing.
|
||||
* Given a topic string return the clients subscriptions that matches it. Topic string can't
|
||||
* contain character # and + because they are reserved to listeners subscriptions, and not topic
|
||||
* publishing.
|
||||
*
|
||||
* @param topic to use fo searching matching subscriptions.
|
||||
* @param topic
|
||||
* to use fo searching matching subscriptions.
|
||||
* @return the list of matching subscriptions, or empty if not matching.
|
||||
*/
|
||||
public List<Subscription> matches(String topic) {
|
||||
@@ -217,7 +236,11 @@ public class SubscriptionsStore {
|
||||
tokens = parseTopic(topic);
|
||||
} catch (ParseException ex) {
|
||||
// TODO handle the parse exception
|
||||
LOG.warn("The topic is malformed. Topic = {}, cause = {}, errorMessage = {}.", topic, ex.getCause(), ex.getMessage());
|
||||
LOG.warn(
|
||||
"The topic is malformed. Topic = {}, cause = {}, errorMessage = {}.",
|
||||
topic,
|
||||
ex.getCause(),
|
||||
ex.getMessage());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -268,8 +291,11 @@ public class SubscriptionsStore {
|
||||
|
||||
/**
|
||||
* Verify if the 2 topics matching respecting the rules of MQTT Appendix A
|
||||
* @param msgTopic the topic to match from the message
|
||||
* @param subscriptionTopic the topic filter of the subscription
|
||||
*
|
||||
* @param msgTopic
|
||||
* the topic to match from the message
|
||||
* @param subscriptionTopic
|
||||
* the topic filter of the subscription
|
||||
* @return true if the two topics match.
|
||||
*/
|
||||
// TODO reimplement with iterators or with queues
|
||||
@@ -304,8 +330,12 @@ public class SubscriptionsStore {
|
||||
return i == msgTokens.size();
|
||||
} catch (ParseException ex) {
|
||||
LOG.error(
|
||||
"The message topic, the subscription topic or both are malformed. MsgTopic = {}, subscriptionTopic = {}, cause = {}, errorMessage = {}.",
|
||||
msgTopic, subscriptionTopic, ex.getCause(), ex.getMessage());
|
||||
"The message topic, the subscription topic or both are malformed. "
|
||||
+ "MsgTopic = {}, subscriptionTopic = {}, cause = {}, errorMessage = {}.",
|
||||
msgTopic,
|
||||
subscriptionTopic,
|
||||
ex.getCause(),
|
||||
ex.getMessage());
|
||||
throw new IllegalStateException(ex.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -330,13 +360,16 @@ public class SubscriptionsStore {
|
||||
String s = splitted[i];
|
||||
if (s.isEmpty()) {
|
||||
// if (i != 0) {
|
||||
// throw new ParseException("Bad format of topic, expetec topic name between separators", i);
|
||||
// throw new ParseException("Bad format of topic, expetec topic name between
|
||||
// separators", i);
|
||||
// }
|
||||
res.add(Token.EMPTY);
|
||||
} else if (s.equals("#")) {
|
||||
// check that multi is the last symbol
|
||||
if (i != splitted.length - 1) {
|
||||
throw new ParseException("Bad format of topic, the multi symbol (#) has to be the last one after a separator", i);
|
||||
throw new ParseException(
|
||||
"Bad format of topic, the multi symbol (#) has to be the last one after a separator",
|
||||
i);
|
||||
}
|
||||
res.add(Token.MULTI);
|
||||
} else if (s.contains("#")) {
|
||||
|
||||
Reference in New Issue
Block a user