package com.ms.biz.quque;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public class InstanceHolder {
    private static final Logger log = LoggerFactory.getLogger(InstanceHolder.class);
    private static final Map<String, Object> MAP = new ConcurrentHashMap<>();

    private InstanceHolder() {
    }

    public static Object getIns(String key) {
        return MAP.get(key);
    }

    public static void setIns(String key, Object ins) {
        Object previous = MAP.put(key, ins);
        if (!Objects.isNull(previous)) {
            throw new IllegalStateException("Create instances repeatedly!");
        }
    }
}
