package com.elab.redis.componts.config.scope;

import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 描述: 这里主要是管理符合
 *
 * @author liukx
 * @date 2021/9/1 14:02
 */
public class RefreshConfigScope implements Scope {

    private final ConcurrentHashMap<String, Object> caches = new ConcurrentHashMap<>();

    @Override
    public Object get(String bean, ObjectFactory<?> objectFactory) {
        if (caches.containsKey(bean)) {
            return caches.get(bean);
        }
        Object object = objectFactory.getObject();
        caches.put(bean, object);
        return object;
    }

    @Override
    public Object remove(String s) {
        return caches.remove(s);
    }

    @Override
    public void registerDestructionCallback(String s, Runnable runnable) {

    }

    @Override
    public Object resolveContextualObject(String s) {
        return null;
    }

    @Override
    public String getConversationId() {
        return null;
    }
}
