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

top.jiaojinxin.jln.event.DefaultEventPublisher Maven / Gradle / Ivy

There is a newer version: 0.1.7
Show newest version
package top.jiaojinxin.jln.event;

import com.lmax.disruptor.SleepingWaitStrategy;
import top.jiaojinxin.jln.properties.JlnEventProperties;
import top.jiaojinxin.jln.util.EventManager;

/**
 * 默认事件处理器发布者
 *
 * @author JiaoJinxin
 */
public class DefaultEventPublisher extends AbstractEventPublisher {

    /**
     * 构造方法
     *
     * @param eventProperties 事件相关配置
     * @author JiaoJinxin
     */
    public DefaultEventPublisher(JlnEventProperties eventProperties) {
        super(
                eventProperties.getRingBufferSize(),
                eventProperties.getThreadNamePrefix(),
                eventProperties.getProducerType(),
                new SleepingWaitStrategy()
        );
    }

    @Override
    protected void doPublish(Event event) {
        EventManager.getEventHandlerRepository()
                .find(event.getClass())
                .parallelStream()
                .forEach(eventHandler -> eventHandler.handle(event));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy