@Test public void testMatchTopics_single() { assertTrue(SubscriptionsStore.matchTopics("finance", "+")); assertTrue(SubscriptionsStore.matchTopics("finance/stock", "finance/+")); assertTrue(SubscriptionsStore.matchTopics("/finance", "/+")); assertFalse(SubscriptionsStore.matchTopics("/finance", "+")); assertTrue(SubscriptionsStore.matchTopics("/finance", "+/+")); assertTrue(SubscriptionsStore.matchTopics("/finance/stock/ibm", "/finance/+/ibm")); assertFalse(SubscriptionsStore.matchTopics("/finance/stock", "+")); }
public static boolean matchTopics(String msgTopic, String subscriptionTopic) { try { List<Token> msgTokens = SubscriptionsStore.splitTopic(msgTopic); List<Token> subscriptionTokens = SubscriptionsStore.splitTopic(subscriptionTopic); int i = 0; for (; i< subscriptionTokens.size(); i++) { Token subToken = subscriptionTokens.get(i); if (subToken != Token.MULTI && subToken != Token.SINGLE) { Token msgToken = msgTokens.get(i); if (!msgToken.equals(subToken)) { return false; } } else { if (subToken == Token.MULTI) { return true; } if (subToken == Token.SINGLE) { } } } return i == msgTokens.size(); } catch (ParseException ex) { LOG.error(null, ex); throw new RuntimeException(ex); } }
SubscriptionsStore { public static boolean matchTopics(String msgTopic, String subscriptionTopic) { try { List<Token> msgTokens = SubscriptionsStore.splitTopic(msgTopic); List<Token> subscriptionTokens = SubscriptionsStore.splitTopic(subscriptionTopic); int i = 0; for (; i< subscriptionTokens.size(); i++) { Token subToken = subscriptionTokens.get(i); if (subToken != Token.MULTI && subToken != Token.SINGLE) { Token msgToken = msgTokens.get(i); if (!msgToken.equals(subToken)) { return false; } } else { if (subToken == Token.MULTI) { return true; } if (subToken == Token.SINGLE) { } } } return i == msgTokens.size(); } catch (ParseException ex) { LOG.error(null, ex); throw new RuntimeException(ex); } } }
SubscriptionsStore { public static boolean matchTopics(String msgTopic, String subscriptionTopic) { try { List<Token> msgTokens = SubscriptionsStore.splitTopic(msgTopic); List<Token> subscriptionTokens = SubscriptionsStore.splitTopic(subscriptionTopic); int i = 0; for (; i< subscriptionTokens.size(); i++) { Token subToken = subscriptionTokens.get(i); if (subToken != Token.MULTI && subToken != Token.SINGLE) { Token msgToken = msgTokens.get(i); if (!msgToken.equals(subToken)) { return false; } } else { if (subToken == Token.MULTI) { return true; } if (subToken == Token.SINGLE) { } } } return i == msgTokens.size(); } catch (ParseException ex) { LOG.error(null, ex); throw new RuntimeException(ex); } }  }
SubscriptionsStore { public static boolean matchTopics(String msgTopic, String subscriptionTopic) { try { List<Token> msgTokens = SubscriptionsStore.splitTopic(msgTopic); List<Token> subscriptionTokens = SubscriptionsStore.splitTopic(subscriptionTopic); int i = 0; for (; i< subscriptionTokens.size(); i++) { Token subToken = subscriptionTokens.get(i); if (subToken != Token.MULTI && subToken != Token.SINGLE) { Token msgToken = msgTokens.get(i); if (!msgToken.equals(subToken)) { return false; } } else { if (subToken == Token.MULTI) { return true; } if (subToken == Token.SINGLE) { } } } return i == msgTokens.size(); } catch (ParseException ex) { LOG.error(null, ex); throw new RuntimeException(ex); } }  void init(IStorageService storageService); void add(Subscription newSubscription); void removeSubscription(String topic, String clientID); void clearAllSubscriptions(); void removeForClient(String clientID); void deactivate(String clientID); void activate(String clientID); List<Subscription> matches(String topic); boolean contains(Subscription sub); int size(); String dumpTree(); static boolean matchTopics(String msgTopic, String subscriptionTopic); }
SubscriptionsStore { public static boolean matchTopics(String msgTopic, String subscriptionTopic) { try { List<Token> msgTokens = SubscriptionsStore.splitTopic(msgTopic); List<Token> subscriptionTokens = SubscriptionsStore.splitTopic(subscriptionTopic); int i = 0; for (; i< subscriptionTokens.size(); i++) { Token subToken = subscriptionTokens.get(i); if (subToken != Token.MULTI && subToken != Token.SINGLE) { Token msgToken = msgTokens.get(i); if (!msgToken.equals(subToken)) { return false; } } else { if (subToken == Token.MULTI) { return true; } if (subToken == Token.SINGLE) { } } } return i == msgTokens.size(); } catch (ParseException ex) { LOG.error(null, ex); throw new RuntimeException(ex); } }  void init(IStorageService storageService); void add(Subscription newSubscription); void removeSubscription(String topic, String clientID); void clearAllSubscriptions(); void removeForClient(String clientID); void deactivate(String clientID); void activate(String clientID); List<Subscription> matches(String topic); boolean contains(Subscription sub); int size(); String dumpTree(); static boolean matchTopics(String msgTopic, String subscriptionTopic);  }