package vip.xiaonuo.coldchain.core.service.dataprocess.handler;

import vip.xiaonuo.coldchain.core.service.dataprocess.model.ColdChainMessageData;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @author jackzhou
 * @version 1.0
 * @project jfcloud-coldchain
 * @description
 * @date 2024/11/12 13:15:10
 */
public class ColdChainHandlerRegistry {

    // 使用线程安全的 ConcurrentHashMap 来存储处理器
    private static final ConcurrentMap<Class<? extends ColdChainMessageData>, ColdChainDataHandler> handlerMap = new ConcurrentHashMap<>();

    // 注册处理器
    public static void registerHandler(Class<? extends ColdChainMessageData> dataClass, ColdChainDataHandler handler) {
        handlerMap.put(dataClass, handler);
    }

    // 获取处理器
    public static ColdChainDataHandler getHandler(Class<? extends ColdChainMessageData> dataClass) {
        return handlerMap.get(dataClass);
    }

    // 检查处理器是否已经注册
    public static boolean isHandlerRegistered(Class<?> dataClass) {
        return handlerMap.containsKey(dataClass);
    }
}
