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

dev.jfr4jdbc.internal.ResourceMonitorManager Maven / Gradle / Ivy

There is a newer version: 2.0.0-M3
Show newest version
package dev.jfr4jdbc.internal;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public class ResourceMonitorManager {

    private static final Map instances = new ConcurrentHashMap<>(1);
    private final Map monitors = new ConcurrentHashMap<>();

    public static final ResourceMonitorManager getInstance(ResourceMonitorKind kind) {
        return instances.computeIfAbsent(kind, k -> new ResourceMonitorManager());
    }

    public ResourceMonitor getMonitor(String label) {
        return this.monitors.computeIfAbsent(label, id -> new ResourceMonitor(id));
    }

    public List getMonitors() {
        return this.monitors.entrySet().stream().map(e -> e.getValue()).collect(Collectors.toList());
    }

    public void addMonitor(ResourceMonitor monitor) {
        this.monitors.put(monitor.getLabel(), monitor);
    }

    public void removeMonitor(ResourceMonitor monitor) {
        this.monitors.remove(monitor.getLabel());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy