// Path: src/main/java/killrvideo/async/KillrVideoThreadFactory.java
// public class KillrVideoThreadFactory implements ThreadFactory {
// 
// 	/** Create dedicated logger to trace ERRORS. */
//     private static final Logger LOGGER = LoggerFactory.getLogger("killrvideo-default-executor");
//     
//     /** Counter keeping track of thread number in executor. */
//     private final AtomicInteger threadNumber = new AtomicInteger(10);
//     
//     /**
//      * Default constructor required for reflection.
//      */
//     public KillrVideoThreadFactory() {
//     }
// 
//     /** {@inheritDoc} */
//     public Thread newThread(Runnable r) {
//         Thread thread = new Thread(r);
//         thread.setName("killrvideo-default-executor-" + this.threadNumber.incrementAndGet());
//         thread.setDaemon(true);
//         thread.setUncaughtExceptionHandler(this.uncaughtExceptionHandler);
//         return thread;
//     }
//     
//     /**
//      * Overriding error handling providing logging.
//      */
//     private Thread.UncaughtExceptionHandler uncaughtExceptionHandler = (t, e) -> {
//         LOGGER.error("Uncaught asynchronous exception : " + e.getMessage(), e);
//     };
// 
// 
// }


import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.validation.Validation;
import javax.validation.Validator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.google.common.eventbus.EventBus;
import killrvideo.async.KillrVideoThreadFactory;
package killrvideo.configuration;






/**
 * Configuration for KillrVideo application leveraging on DSE, ETCD and any external source.
 *
 * @author DataStax evangelist team.
 */
@Configuration
public class KillrVideoConfiguration {
   
    // --- Global Infos
    
    @Value("${killrvideo.application.name:KillrVideo}")
    private String applicationName;
    
    @Value("${killrvideo.application.instance.id: 0}")
    private int applicationInstanceId;
    
    @Value("${killrvideo.server.port: 8899}")
    private int applicationPort;
    
    @Value("#{environment.KILLRVIDEO_HOST_IP}")
    private String applicationHost;
    
    @Value("${killrvideo.cassandra.mutation-error-log: /tmp/killrvideo-mutation-errors.log}")
    private String mutationErrorLog;
    
    // --- ThreadPool Settings
   
    @Value("${killrvideo.threadpool.min.threads:5}")
    private int minThreads;
    
    @Value("${killrvideo.threadpool.max.threads:10}")
    private int maxThreads;
    
    @Value("${killrvideo.thread.ttl.seconds:60}")
    private int threadsTTLSeconds;
    
    @Value("${killrvideo.thread.queue.size:1000}")
    private int threadPoolQueueSize;
    
    // --- Bean definition
    
    @Bean
    public EventBus createEventBus() {
        return new EventBus("killrvideo_event_bus");
    }

    /**
     * Initialize the threadPool.
     *
     * @return
     *      current executor for this
     */
    @Bean(destroyMethod = "shutdownNow")
    public ExecutorService threadPool() {
        return new ThreadPoolExecutor(getMinThreads(), getMaxThreads(), 
                getThreadsTTLSeconds(), TimeUnit.SECONDS, 
                new LinkedBlockingQueue<>(getThreadPoolQueueSize()), 
// Path: src/main/java/killrvideo/async/KillrVideoThreadFactory.java
// public class KillrVideoThreadFactory implements ThreadFactory {
// 
// 	/** Create dedicated logger to trace ERRORS. */
//     private static final Logger LOGGER = LoggerFactory.getLogger("killrvideo-default-executor");
//     
//     /** Counter keeping track of thread number in executor. */
//     private final AtomicInteger threadNumber = new AtomicInteger(10);
//     
//     /**
//      * Default constructor required for reflection.
//      */
//     public KillrVideoThreadFactory() {
//     }
// 
//     /** {@inheritDoc} */
//     public Thread newThread(Runnable r) {
//         Thread thread = new Thread(r);
//         thread.setName("killrvideo-default-executor-" + this.threadNumber.incrementAndGet());
//         thread.setDaemon(true);
//         thread.setUncaughtExceptionHandler(this.uncaughtExceptionHandler);
//         return thread;
//     }
//     
//     /**
//      * Overriding error handling providing logging.
//      */
//     private Thread.UncaughtExceptionHandler uncaughtExceptionHandler = (t, e) -> {
//         LOGGER.error("Uncaught asynchronous exception : " + e.getMessage(), e);
//     };
// 
// 
// }


// Path: src/main/java/killrvideo/configuration/KillrVideoConfiguration.java
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.validation.Validation;
import javax.validation.Validator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.google.common.eventbus.EventBus;
import killrvideo.async.KillrVideoThreadFactory;

package killrvideo.configuration;






/**
 * Configuration for KillrVideo application leveraging on DSE, ETCD and any external source.
 *
 * @author DataStax evangelist team.
 */
@Configuration
public class KillrVideoConfiguration {
   
    // --- Global Infos
    
    @Value("${killrvideo.application.name:KillrVideo}")
    private String applicationName;
    
    @Value("${killrvideo.application.instance.id: 0}")
    private int applicationInstanceId;
    
    @Value("${killrvideo.server.port: 8899}")
    private int applicationPort;
    
    @Value("#{environment.KILLRVIDEO_HOST_IP}")
    private String applicationHost;
    
    @Value("${killrvideo.cassandra.mutation-error-log: /tmp/killrvideo-mutation-errors.log}")
    private String mutationErrorLog;
    
    // --- ThreadPool Settings
   
    @Value("${killrvideo.threadpool.min.threads:5}")
    private int minThreads;
    
    @Value("${killrvideo.threadpool.max.threads:10}")
    private int maxThreads;
    
    @Value("${killrvideo.thread.ttl.seconds:60}")
    private int threadsTTLSeconds;
    
    @Value("${killrvideo.thread.queue.size:1000}")
    private int threadPoolQueueSize;
    
    // --- Bean definition
    
    @Bean
    public EventBus createEventBus() {
        return new EventBus("killrvideo_event_bus");
    }

    /**
     * Initialize the threadPool.
     *
     * @return
     *      current executor for this
     */
    @Bean(destroyMethod = "shutdownNow")
    public ExecutorService threadPool() {
        return new ThreadPoolExecutor(getMinThreads(), getMaxThreads(), 
                getThreadsTTLSeconds(), TimeUnit.SECONDS, 
                new LinkedBlockingQueue<>(getThreadPoolQueueSize()), 
                new KillrVideoThreadFactory());