package com.jasamedika.medifirst2000.logging.hibernate.async;

import java.util.concurrent.Executor;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 
 * @author Syamsu
 */

@Configuration
@EnableAsync
@EnableScheduling
public class AsynchLogConfigure implements AsyncConfigurer {

	@Value("${corePoolSizeAsyncConfigurer}")
	Integer corePoolSizeAsyncConfigurer;

	@Value("${maxPoolSizeAsyncConfigurer}")
	Integer maxPoolSizeAsyncConfigurer;

	@Override
	public Executor getAsyncExecutor() {
		ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
		taskExecutor.setCorePoolSize(corePoolSizeAsyncConfigurer);
		taskExecutor.setMaxPoolSize(maxPoolSizeAsyncConfigurer);
		taskExecutor.setThreadNamePrefix("jasmed-medifirst2000-executor-");
		taskExecutor.initialize();
		return taskExecutor;
	}

	@Override
	public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
		return new SimpleAsyncUncaughtExceptionHandler();
	}

}
