package cn.axzo.workflow.starter.handler.execute.interceptor;

import cn.axzo.framework.rocketmq.EventConsumer;
import cn.axzo.workflow.starter.handler.execute.ListenerExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;
import java.util.function.Consumer;

public final class ExecutorInvoker extends AbstractListenerInterceptor {

    private static final Logger log = LoggerFactory.getLogger(ExecutorInvoker.class);

    @Override
    public <T> void execute(ListenerExecutor executor, Consumer<T> consumer, EventConsumer.Context context, T t) {
        if (Objects.isNull(consumer)) {
            log.warn("Unsupported message eventCode type， Please check message producer");
            return;
        }
        consumer.accept(t);
    }

    @Override
    public ExecuteInterceptor getNext() {
        return null;
    }

    @Override
    public void setNext(ExecuteInterceptor next) {
        throw new UnsupportedOperationException("ExecutorInvoker must be the last interceptor in the chain");
    }

}
