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

pl.allegro.tech.hermes.consumers.health.ConsumerMonitor Maven / Gradle / Ivy

There is a newer version: 2.8.0
Show newest version
package pl.allegro.tech.hermes.consumers.health;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class ConsumerMonitor {

    private Map> checks = new ConcurrentHashMap<>();

    public void register(String key, Supplier check) {
        checks.putIfAbsent(key, check);
    }

    public Object check(String key) {
        try {
            return checks.getOrDefault(key, () -> "Unavailable").get();
        } catch (Exception ex) {
            return "Failed to evaluate check, " + ex.getMessage();
        }
    }
}