All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.metrics.common.RegexStringMatchingStrategy Maven / Gradle / Ivy

There is a newer version: 5.0.0-rc.3
Show newest version
package io.dropwizard.metrics.common;

import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;

import java.time.Duration;
import java.util.Set;
import java.util.regex.Pattern;

class RegexStringMatchingStrategy implements StringMatchingStrategy {
    private final LoadingCache patternCache;

    RegexStringMatchingStrategy() {
        patternCache = Caffeine.newBuilder()
            .expireAfterWrite(Duration.ofHours(1))
            .build(Pattern::compile);
    }

    @Override
    public boolean containsMatch(Set matchExpressions, String metricName) {
        for (String regexExpression : matchExpressions) {
            final Pattern pattern = patternCache.get(regexExpression);
            if (pattern != null && pattern.matcher(metricName).matches()) {
                // just need to match on a single value - return as soon as we do
                return true;
            }
        }
        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy