package cn.freemud.fuyou.service.processor;


import com.google.common.collect.Maps;
import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.Map;

@Component
public class EventProcessorRegister extends ApplicationObjectSupport {
//Collections.emptyMap()

    private static Map<Integer, EventProcessor> processorMap = Maps.newHashMap();

    @PostConstruct
    private void init() {
        Map<String, EventProcessor> beans = getApplicationContext().getBeansOfType(EventProcessor.class);
        if (!CollectionUtils.isEmpty(beans)) {
            beans.values().stream().forEach((EventProcessor obj) ->
                    processorMap.put(obj.getEvent(), obj)

            );
        }
    }

    public EventProcessor getEventProcessor(Integer event) {
        return processorMap.get(event);
    }
}
