/** * set the default value to fallback to if none found * * @param defaultValue the value */ @Override public void setDefault(final T defaultValue) { clearCache(); defaultmatch = defaultValue; }
@Override public void clear() { lock.writeLock().lock(); try { clearCache(); listeners.clear(); matches.clear(); } finally { lock.writeLock().unlock(); } }
@Override public void swap(Set<Map.Entry<String, T>> entries) { lock.writeLock().lock(); try { clearCache(); immutables.clear(); matches.clear(); for (Map.Entry<String, T> entry : entries) { addMatch(entry.getKey(), entry.getValue(), true, false); } } finally { lock.writeLock().unlock(); } onChange(); }
/** * remove a match from the repository * * @param match the match to remove */ @Override public void removeMatch(final String match) { lock.writeLock().lock(); try { String modMatch = matchModifier.modify(match); boolean isImmutable = immutables.contains(modMatch); if (isImmutable) { logger.debug("Cannot remove match " + modMatch + " since it came from a main config"); } else { /** * clear the cache before removing the match. This will force any thread at * {@link #getMatch(String)} to get the lock to recompute. */ clearCache(); matches.remove(modMatch); onChange(); } } finally { lock.writeLock().unlock(); } }
private void addMatch(final String match, final T value, final boolean immutableMatch, boolean notifyListeners) { lock.writeLock().lock(); try { String modifiedMatch = matchModifier.modify(match); clearCache(); if (immutableMatch) { immutables.add(modifiedMatch); } Match.verify(modifiedMatch, wildcardConfiguration); Match<T> match1 = new Match<>(modifiedMatch, value, wildcardConfiguration); matches.put(modifiedMatch, match1); } finally { lock.writeLock().unlock(); } // Calling the onChange outside of the wrieLock as some listeners may be doing reads on the matches if (notifyListeners) { onChange(); } }