package cd.casic.plugin;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

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

/**
 * @Author：mianbin
 * @Package：cd.casic.plugin
 * @Project：ops
 * @name：PluginApplicationContextHolder
 * @Date：2024/03/18 10:04
 * @Filename：PluginApplicationContextHolder
 * @description：插件的上下文管理器
 */
public class PluginApplicationContextManager {

    private final static Map<String, AnnotationConfigApplicationContext> pluginApplicationMap = new ConcurrentHashMap<>();

    public static void addPluginApplicationContext(String pluginId, AnnotationConfigApplicationContext applicationContext) {
        pluginApplicationMap.put(pluginId, applicationContext);
    }

    public static void removePluginApplicationContext(String pluginId) {
        pluginApplicationMap.remove(pluginId);
    }

    public static AnnotationConfigApplicationContext getApplicationContext(String pluginId) {
        return pluginApplicationMap.get(pluginId);
    }
}
