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

org.jboss.pnc.environmentdriver.ActiveMonitors Maven / Gradle / Ivy

package org.jboss.pnc.environmentdriver;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

import javax.enterprise.context.ApplicationScoped;

/**
 * Keep a set of active monitors per key (pod name)
 *
 * @author Matej Lazar
 */
@ApplicationScoped
public class ActiveMonitors {

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

    public void add(String key, CompletableFuture future) {
        Set futures = monitors.computeIfAbsent(key, (k) -> new HashSet<>());
        futures.add(future);
    }

    public Set get(String key) {
        return monitors.get(key);
    }

    public void remove(String key) {
        monitors.remove(key);
    }

    public void cancel(String key) {
        Set futures = monitors.remove(key);
        if (futures != null) {
            futures.forEach(f -> f.cancel(false));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy