@Test public void testFilter() { int topicCount = 5000; int loopCount = 1000000, loop = 500; int maxTagCount = 20000; List<String> topics = randomStrings(topicCount, 256); Filter filter = lookup(Filter.class); Map<String, List<String>> pattern2Tags = new HashMap<>(); for (String pattern : m_patterns) { pattern2Tags.put(pattern, generateTags(pattern, m_rand.nextBoolean() ? m_rand.nextBoolean() ? m_rand.nextInt(maxTagCount) : m_rand.nextInt(500) : 1)); } List<Pair<String, Map<String, String>>> list = new ArrayList<>(); for (int i = 0; i < loopCount; i++) { list.add(generateSource(m_rand.nextInt(10) < 7, pattern2Tags)); } for (int i = 0; i < loop; i++) { long begin = System.currentTimeMillis(); for (int j = 0; j < loopCount; j++) { Pair<String, Map<String, String>> seed = list.get(m_rand.nextInt(list.size())); filter.isMatch(topics.get(m_rand.nextInt(topicCount)), seed.getKey(), seed.getValue()); } System.out.println("cost: " + (System.currentTimeMillis() - begin)); } }
@Override public boolean isMatch(String topicName, String filter, Map<String, String> source) { try { Map<String, String> conditions = m_filterConditionCache.get(filter); for (Entry<String, String> entry : conditions.entrySet()) { String sourceValue = source.get(entry.getKey()); if (StringUtils.isBlank(sourceValue) || !matches(topicName, sourceValue, entry.getValue())) { return false; } } } catch (ExecutionException e) { log.error("Can not find matchedCache for topic: {]", topicName, e); return false; } return true; }
DefaultFilter implements Filter, Initializable { @Override public boolean isMatch(String topicName, String filter, Map<String, String> source) { try { Map<String, String> conditions = m_filterConditionCache.get(filter); for (Entry<String, String> entry : conditions.entrySet()) { String sourceValue = source.get(entry.getKey()); if (StringUtils.isBlank(sourceValue) || !matches(topicName, sourceValue, entry.getValue())) { return false; } } } catch (ExecutionException e) { log.error("Can not find matchedCache for topic: {]", topicName, e); return false; } return true; } }
DefaultFilter implements Filter, Initializable { @Override public boolean isMatch(String topicName, String filter, Map<String, String> source) { try { Map<String, String> conditions = m_filterConditionCache.get(filter); for (Entry<String, String> entry : conditions.entrySet()) { String sourceValue = source.get(entry.getKey()); if (StringUtils.isBlank(sourceValue) || !matches(topicName, sourceValue, entry.getValue())) { return false; } } } catch (ExecutionException e) { log.error("Can not find matchedCache for topic: {]", topicName, e); return false; } return true; }  }
DefaultFilter implements Filter, Initializable { @Override public boolean isMatch(String topicName, String filter, Map<String, String> source) { try { Map<String, String> conditions = m_filterConditionCache.get(filter); for (Entry<String, String> entry : conditions.entrySet()) { String sourceValue = source.get(entry.getKey()); if (StringUtils.isBlank(sourceValue) || !matches(topicName, sourceValue, entry.getValue())) { return false; } } } catch (ExecutionException e) { log.error("Can not find matchedCache for topic: {]", topicName, e); return false; } return true; }  @Override boolean isMatch(String topicName, String filter, Map<String, String> source); @Override void initialize(); }
DefaultFilter implements Filter, Initializable { @Override public boolean isMatch(String topicName, String filter, Map<String, String> source) { try { Map<String, String> conditions = m_filterConditionCache.get(filter); for (Entry<String, String> entry : conditions.entrySet()) { String sourceValue = source.get(entry.getKey()); if (StringUtils.isBlank(sourceValue) || !matches(topicName, sourceValue, entry.getValue())) { return false; } } } catch (ExecutionException e) { log.error("Can not find matchedCache for topic: {]", topicName, e); return false; } return true; }  @Override boolean isMatch(String topicName, String filter, Map<String, String> source); @Override void initialize();  }