package com.jeequan.jeepay.core.config;

import com.jeequan.jeepay.core.interceptor.ReqInfoInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private ReqInfoInterceptor requestInfoInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(requestInfoInterceptor);
    }

    @Bean
    public ExecutorService executorService() {
        return new ThreadPoolExecutor(4,
                4, 1L
                , TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), Thread::new, new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
