JobProcessorHolder.java 1.07 KB
package com.yoho.quartz.job;

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

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

/**
 * Author:yanzhang.fu
 * Date:2017/12/14
 * Description:
 * Modified By:
 **/
public class  JobProcessorHolder {
    private static final Logger logger = LoggerFactory.getLogger(JobProcessorHolder.class);
    private static final Map<String,YhJob> holder = new ConcurrentHashMap<String,YhJob>();

    public static void putPorcessor(YhJob jobProcessor){
        holder.put(jobProcessor.getClass().getCanonicalName(),jobProcessor);
    }

    public static void putAllProcessor(Map<String, YhJob> processors){
        for (YhJob processor : processors.values()){
            putPorcessor(processor);
        }
    }

    public static YhJob getProcessor(String clazzName){
        return holder.get(clazzName);
    }

    public static void printHolder(){
        for (Map.Entry<String, YhJob> entry :  holder.entrySet()) {
            logger.info("holder info: key:{}, value:{}", entry.getKey(), entry.getValue());
        }
    }
}