private void addToPatternEntryList(final String pattern) { if (pattern.length() == 0) { // ignore empty lines return; } try { switch (pattern.charAt(0)) { case '+': this.patterns.add(new PatternEntry(pattern.substring(1).trim(), true)); break; case '-': this.patterns.add(new PatternEntry(pattern.substring(1).trim(), false)); break; case '#': // ignore comment break; default: LOGGER.warn("Each line should either start with '+', '-', or '#'. Ignoring: {}", pattern); break; } } catch (final InvalidPatternException ex) { LOGGER.error("'{}' is not a valid pattern.", pattern.substring(1), ex); } }
/** * This method tests if the given signature matches a pattern and completes accordingly the signatureCache map. * * @param signature * The signature to match. */ private boolean matchesPattern(final String signature) { synchronized (this) { final ListIterator<PatternEntry> patternListIterator = this.patternList.listIterator(this.patternList.size()); while (patternListIterator.hasPrevious()) { final PatternEntry patternEntry = patternListIterator.previous(); if (patternEntry.getPattern().matcher(signature).matches()) { final boolean value = patternEntry.isActivated(); this.signatureCache.put(signature, value); return value; } } } // Do not forget to remember this default value this.signatureCache.put(signature, true); return true; // if nothing matches, the default is true! }
/** * {@inheritDoc} */ @Override public List<String> getProbePatternList() { if (!this.enabled) { LOGGER.warn("Adapative Monitoring is disabled!"); return new ArrayList<>(0); } synchronized (this) { final List<String> currentPatterns = new ArrayList<>(this.patterns.size()); for (final PatternEntry entry : this.patterns) { final String strPattern; if (entry.isActivated()) { strPattern = '+' + entry.getStrPattern(); } else { strPattern = '-' + entry.getStrPattern(); } currentPatterns.add(strPattern); } return currentPatterns; } }
/** * This method tests if the given signature matches a pattern and completes * accordingly the signatureCache map. * * @param signature * The signature to match. */ private boolean matchesPattern(final String signature) { synchronized (this) { final ListIterator<PatternEntry> patternListIterator = this.patterns .listIterator(this.patterns.size()); while (patternListIterator.hasPrevious()) { final PatternEntry patternEntry = patternListIterator.previous(); if (patternEntry.getPattern().matcher(signature).matches()) { final boolean value = patternEntry.isActivated(); this.signatureCache.put(signature, value); return value; } } } // Do not forget to remember this default value this.signatureCache.put(signature, true); return true; // if nothing matches, the default is true! }
/** * {@inheritDoc} */ @Override public List<String> getProbePatternList() { if (!this.enabled) { LOG.warn("Adapative Monitoring is disabled!"); return new ArrayList<String>(0); } synchronized (this) { final List<String> list = new ArrayList<String>(this.patternList.size()); for (final PatternEntry entry : this.patternList) { final String strPattern; if (entry.isActivated()) { strPattern = '+' + entry.getStrPattern(); } else { strPattern = '-' + entry.getStrPattern(); } list.add(strPattern); } return list; } }
private boolean addPattern(final String strPattern, final boolean activated) { if (!this.enabled) { LOGGER.warn("Adapative Monitoring is disabled!"); return false; } synchronized (this) { // we must always clear the cache! this.signatureCache.clear(); final Pattern pattern; try { pattern = PatternParser.parseToPattern(strPattern); } catch (final InvalidPatternException ex) { LOGGER.error("'{}' is not a valid pattern.", strPattern, ex); return false; } this.patterns.add(new PatternEntry(strPattern, pattern, activated)); if (this.configFileUpdate) { this.updatePatternFile(); } } return true; }
private void addToPatternEntryList(final String pattern) { if (pattern.length() == 0) { // ignore empty lines return; } try { switch (pattern.charAt(0)) { case '+': this.patternList.add(new PatternEntry(pattern.substring(1).trim(), true)); break; case '-': this.patternList.add(new PatternEntry(pattern.substring(1).trim(), false)); break; case '#': // ignore comment break; default: if (LOG.isWarnEnabled()) { LOG.warn("Each line should either start with '+', '-', or '#'. Ignoring: " + pattern); } break; } } catch (final InvalidPatternException ex) { LOG.error("'" + pattern.substring(1) + "' is not a valid pattern.", ex); } }
private boolean addPattern(final String strPattern, final boolean activated) { if (!this.enabled) { LOG.warn("Adapative Monitoring is disabled!"); return false; } synchronized (this) { // we must always clear the cache! this.signatureCache.clear(); final Pattern pattern; try { pattern = PatternParser.parseToPattern(strPattern); } catch (final InvalidPatternException ex) { LOG.error("'" + strPattern + "' is not a valid pattern.", ex); return false; } this.patternList.add(new PatternEntry(strPattern, pattern, activated)); if (this.configFileUpdate) { this.updatePatternFile(); } } return true; }