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

com.codahale.metrics.health.SharedHealthCheckRegistries Maven / Gradle / Ivy

Go to download

An addition to Metrics which provides the ability to run application-specific health checks, allowing you to check your application's heath in production.

There is a newer version: 4.2.30
Show newest version
package com.codahale.metrics.health;

import com.codahale.metrics.MetricRegistry;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * A map of shared, named health registries.
 */
public class SharedHealthCheckRegistries {
    private static final ConcurrentMap REGISTRIES =
            new ConcurrentHashMap();

    private SharedHealthCheckRegistries() { /* singleton */ }

    public static void clear() {
        REGISTRIES.clear();
    }

    public static Set names() {
        return REGISTRIES.keySet();
    }

    public static void remove(String key) {
        REGISTRIES.remove(key);
    }

    public static HealthCheckRegistry add(String name, HealthCheckRegistry registry) {
        return REGISTRIES.putIfAbsent(name, registry);
    }

    public static HealthCheckRegistry getOrCreate(String name) {
        final HealthCheckRegistry existing = REGISTRIES.get(name);
        if (existing == null) {
            final HealthCheckRegistry created = new HealthCheckRegistry();
            final HealthCheckRegistry raced = add(name, created);
            if (raced == null) {
                return created;
            }
            return raced;
        }
        return existing;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy