package com.nobodyiam.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean;

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

/**
 * Created by Jason on 7/5/15.
 */
@Configuration
@EnableAspectJAutoProxy
@ComponentScan(value = "com.nobodyiam",
        excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = FilterConfig.class))
@PropertySource("classpath:config.properties")
public class AppConfig {
    @Autowired
    private Environment env;

    @Bean
    public ExecutorService executorService() throws Exception {
        return threadPoolExecutorFactoryBean().getObject();
    }

    @Bean
    public ThreadPoolExecutorFactoryBean threadPoolExecutorFactoryBean() {
        int max_threads = Integer.parseInt(env.getProperty("threadpool.max_threads", "20"));
        int blocking_queue_size = Integer.parseInt(env.getProperty("threadpool.blocking_queue_size", "40"));
        ThreadPoolExecutorFactoryBean threadPoolExecutorFactoryBean = new ThreadPoolExecutorFactoryBean();
        threadPoolExecutorFactoryBean.setMaxPoolSize(max_threads);
        threadPoolExecutorFactoryBean.setCorePoolSize(max_threads);
        threadPoolExecutorFactoryBean.setQueueCapacity(blocking_queue_size);
        threadPoolExecutorFactoryBean.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());

        return threadPoolExecutorFactoryBean;
    }
}

@@ -118,28 +118,168 @@
 ork.
-context.annotation.*
+beans.factory.annotation.Value;%0Aimport org.springframework.context.annotation.*;%0Aimport org.springframework.context.support.PropertySourcesPlaceholderConfigurer
 ;%0Aim
@@ -846,16 +846,89 @@
 t env;%0A%0A
+    @Value(%22$%7Bthreadpool.max_threads:20%7D%22)%0A    private int max_threads;%0A%0A
     @Bea
@@ -1149,101 +1149,8 @@
 ) %7B%0A
-        int max_threads = Integer.parseInt(env.getProperty(%22threadpool.max_threads%22, %2220%22));%0A
     
@@ -1679,16 +1679,16 @@
 cy());%0A%0A
-
         
@@ -1730,11 +1730,183 @@
 n;%0A    %7D
+%0A%0A    @Bean%0A    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() %7B%0A        return new PropertySourcesPlaceholderConfigurer();%0A    %7D
 %0A%7D%0A

add place holder support