Improve log traces of the subscriptions store. Make sure that no "raw" RuntimeExceptions are thrown, and include proper log traces before any exception is raised.

This commit is contained in:
Luis Barrios
2017-01-11 10:42:43 +01:00
parent 8481fada93
commit 63d106e414
@@ -52,7 +52,8 @@ public class SubscriptionsStore {
parseTopic(topicFilter); parseTopic(topicFilter);
return true; return true;
} catch (ParseException pex) { } catch (ParseException pex) {
LOG.info("Bad matching topic filter <{}>", topicFilter); LOG.warn("The topic filter is malformed. TopicFilter = {}, cause = {}, errorMessage = {}.", topicFilter,
pex.getCause(), pex.getMessage());
return false; return false;
} }
} }
@@ -103,24 +104,27 @@ public class SubscriptionsStore {
* @param sessionsStore to be used as backing store from the subscription store. * @param sessionsStore to be used as backing store from the subscription store.
*/ */
public void init(ISessionsStore sessionsStore) { public void init(ISessionsStore sessionsStore) {
LOG.debug("init invoked"); LOG.info("Initializing subscriptions store...");
m_sessionsStore = sessionsStore; m_sessionsStore = sessionsStore;
List<ClientTopicCouple> subscriptions = sessionsStore.listAllSubscriptions(); List<ClientTopicCouple> subscriptions = sessionsStore.listAllSubscriptions();
//reload any subscriptions persisted //reload any subscriptions persisted
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Reloading all stored subscriptions...subscription tree before {}", dumpTree()); LOG.debug("Reloading all stored subscriptions. SubscriptionTree = {}.", dumpTree());
} }
for (ClientTopicCouple clientTopic : subscriptions) { for (ClientTopicCouple clientTopic : subscriptions) {
LOG.debug("Re-subscribing {} to topic {}", clientTopic.clientID, clientTopic.topicFilter); LOG.info("Re-subscribing client to topic. ClientId = {}, topicFilter = {}.", clientTopic.clientID, clientTopic.topicFilter);
add(clientTopic); add(clientTopic);
} }
if (LOG.isTraceEnabled()) { if (LOG.isDebugEnabled()) {
LOG.trace("Finished loading. Subscription tree after {}", dumpTree()); LOG.debug("The stored subscriptions have been reloaded. SubscriptionTree = {}.", dumpTree());
} }
} }
public void add(ClientTopicCouple newSubscription) { public void add(ClientTopicCouple newSubscription) {
/*
* The topic filters have already been validated at the ProtocolProcessor. We can assume they are valid.
*/
TreeNode oldRoot; TreeNode oldRoot;
NodeCouple couple; NodeCouple couple;
do { do {
@@ -129,7 +133,9 @@ public class SubscriptionsStore {
couple.createdNode.addSubscription(newSubscription); //createdNode could be null? couple.createdNode.addSubscription(newSubscription); //createdNode could be null?
//spin lock repeating till we can, swap root, if can't swap just re-do the operation //spin lock repeating till we can, swap root, if can't swap just re-do the operation
} while(!subscriptions.compareAndSet(oldRoot, couple.root)); } while(!subscriptions.compareAndSet(oldRoot, couple.root));
LOG.debug("root ref {}, original root was {}", couple.root, oldRoot); if (LOG.isDebugEnabled()) {
LOG.debug("A subscription has been added. Root = {}, oldRoot = {}.", couple.root, oldRoot);
}
} }
@@ -139,7 +145,9 @@ public class SubscriptionsStore {
tokens = parseTopic(topic); tokens = parseTopic(topic);
} catch (ParseException ex) { } catch (ParseException ex) {
//TODO handle the parse exception //TODO handle the parse exception
LOG.error(null, ex); LOG.error("The topic is malformed. Topic = {}, cause = {}, errorMessage = {}.", topic, ex.getCause(),
ex.getMessage());
throw new IllegalArgumentException(ex.getMessage());
} }
final TreeNode newRoot = oldRoot.copy(); final TreeNode newRoot = oldRoot.copy();
@@ -167,6 +175,9 @@ public class SubscriptionsStore {
} }
public void removeSubscription(String topic, String clientID) { public void removeSubscription(String topic, String clientID) {
/*
* The topic filters have already been validated at the ProtocolProcessor. We can assume they are valid.
*/
TreeNode oldRoot; TreeNode oldRoot;
NodeCouple couple; NodeCouple couple;
do { do {
@@ -208,7 +219,7 @@ public class SubscriptionsStore {
tokens = parseTopic(topic); tokens = parseTopic(topic);
} catch (ParseException ex) { } catch (ParseException ex) {
//TODO handle the parse exception //TODO handle the parse exception
LOG.error(null, ex); LOG.warn("The topic is malformed. Topic = {}, cause = {}, errorMessage = {}.", topic, ex.getCause(), ex.getMessage());
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -294,8 +305,10 @@ public class SubscriptionsStore {
// } // }
return i == msgTokens.size(); return i == msgTokens.size();
} catch (ParseException ex) { } catch (ParseException ex) {
LOG.error(null, ex); LOG.error(
throw new RuntimeException(ex); "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());
} }
} }