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

com.kaka.notice.FacadeFactory Maven / Gradle / Ivy

package com.kaka.notice;

import com.kaka.util.ReflectUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * {@link Facade} 工厂
 *
 * @author zkpursuit
 */
public class FacadeFactory {

    private static Class facadeClass = Facade.class;
    private static final String DEFAULT = "default";
    static final Map instanceMap = new HashMap<>();

    /**
     * 必须先调用此方法进行配置 
* 一般在应用程序启动时调用,且仅调用一次 * * @param facadeClass 事件总线类 * @param 事件总线实现类泛型限定 * @return 事件总线类实例 */ public synchronized static T config(Class facadeClass) { FacadeFactory.facadeClass = facadeClass; return getFacade(); } public synchronized static T getFacade(String name) { Facade inst; if (instanceMap.get(name) == null) { try { inst = ReflectUtils.newInstance(facadeClass); inst.__name = name; instanceMap.put(name, inst); } catch (Exception e) { throw new RuntimeException(e); } } else { inst = instanceMap.get(name); } return (T) inst; } public synchronized static T getFacade() { return getFacade(DEFAULT); } public synchronized static boolean hasFacade(String name) { return instanceMap.containsKey(name); } public synchronized static void removeFacade(String name) { Facade inst = instanceMap.remove(name); if (inst != null) { inst.dispose(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy