package com.fdkankan.disruptormq;

/**
 * @author Xiewj
 * @date 2024/1/17
 */

import com.fdkankan.disruptormq.DisruptorEvent;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.WorkHandler;

/**
 * 消费者接口
 * EventHandler用于EventHandlerGroup，WorkHandler用于WorkPool
 * 同时实现两接口，该类对象可同时用于EventHandlerGroup和WorkPool
 */
public interface DisruptorHandler<T> extends EventHandler<DisruptorEvent<T>>, WorkHandler<DisruptorEvent<T>> {
    @Override
    default void onEvent(DisruptorEvent<T> event, long sequence, boolean endOfBatch) throws Exception {
        onEvent(event);
    }

    @Override
    default void onEvent(DisruptorEvent<T> event) throws Exception {
        consumer(event.getPayload());
    }

    void consumer(T t) throws Exception;
}