// Path: src/main/java/org/chorem/ecd/exception/InvalidArgumentException.java
// public class InvalidArgumentException extends RuntimeException {
// 
//     public InvalidArgumentException(String msg) {
//         super(msg);
//     }
// 
// }
// 
// Path: src/main/java/org/chorem/ecd/service/PeriodicTasksExecutorService.java
// @Singleton
// public class PeriodicTasksExecutorService {
// 
//     private static final Logger logger = LoggerFactory.getLogger(PeriodicTasksExecutorService.class);
// 
//     private ScheduledExecutorService executor = Executors.newScheduledThreadPool(4);
// 
//     private Map<String, ScheduledFuture<?>> taskFuturesMap = Maps.newConcurrentMap();
// 
//     @PostConstruct
//     public void init() {
//     }
// 
//     @PreDestroy
//     public void shutdown() {
//         taskFuturesMap.forEach((name, future) -> {
//             future.cancel(false);
//             logger.info("Cancelled " + name);
//         });
//         taskFuturesMap.clear();
//     }
// 
//     public void schedule(EcdPeriodicTask task) {
//         ScheduledFuture<?> future;
//         if (taskFuturesMap.containsKey(task.getName())) {
//             future = taskFuturesMap.get(task.getName());
//             future.cancel(false);
//             taskFuturesMap.remove(task.getName());
//         }
//         future = executor.scheduleWithFixedDelay(task, 0, task.getPeriodicity(), task.getPeriodicityUnit());
//         taskFuturesMap.put(task.getName(), future);
//         logger.info("Scheduled " + task.getName());
//     }
// }


import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.chorem.ecd.exception.InvalidArgumentException;
import org.chorem.ecd.service.PeriodicTasksExecutorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spark.Spark;
import java.net.HttpURLConnection;
package org.chorem.ecd;



public class App {

    private static final Logger logger = LoggerFactory.getLogger(App.class);

    public static void main(String args[]) throws Exception {
        Spark.threadPool(4);
        Spark.port(8084);

        Spark.exception(InvalidArgumentException.class, (e, req, resp) -> {
            logger.error(e.getMessage(), e);
            resp.status(HttpURLConnection.HTTP_BAD_REQUEST);
            resp.type("application/json");
            resp.body(String.format("{\"message\":\"%s\"}", e.getMessage()));
        });

        Spark.staticFileLocation("/public");

        Weld.newInstance().initialize();
// Path: src/main/java/org/chorem/ecd/exception/InvalidArgumentException.java
// public class InvalidArgumentException extends RuntimeException {
// 
//     public InvalidArgumentException(String msg) {
//         super(msg);
//     }
// 
// }
// 
// Path: src/main/java/org/chorem/ecd/service/PeriodicTasksExecutorService.java
// @Singleton
// public class PeriodicTasksExecutorService {
// 
//     private static final Logger logger = LoggerFactory.getLogger(PeriodicTasksExecutorService.class);
// 
//     private ScheduledExecutorService executor = Executors.newScheduledThreadPool(4);
// 
//     private Map<String, ScheduledFuture<?>> taskFuturesMap = Maps.newConcurrentMap();
// 
//     @PostConstruct
//     public void init() {
//     }
// 
//     @PreDestroy
//     public void shutdown() {
//         taskFuturesMap.forEach((name, future) -> {
//             future.cancel(false);
//             logger.info("Cancelled " + name);
//         });
//         taskFuturesMap.clear();
//     }
// 
//     public void schedule(EcdPeriodicTask task) {
//         ScheduledFuture<?> future;
//         if (taskFuturesMap.containsKey(task.getName())) {
//             future = taskFuturesMap.get(task.getName());
//             future.cancel(false);
//             taskFuturesMap.remove(task.getName());
//         }
//         future = executor.scheduleWithFixedDelay(task, 0, task.getPeriodicity(), task.getPeriodicityUnit());
//         taskFuturesMap.put(task.getName(), future);
//         logger.info("Scheduled " + task.getName());
//     }
// }


// Path: src/main/java/org/chorem/ecd/App.java
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.chorem.ecd.exception.InvalidArgumentException;
import org.chorem.ecd.service.PeriodicTasksExecutorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spark.Spark;
import java.net.HttpURLConnection;

package org.chorem.ecd;



public class App {

    private static final Logger logger = LoggerFactory.getLogger(App.class);

    public static void main(String args[]) throws Exception {
        Spark.threadPool(4);
        Spark.port(8084);

        Spark.exception(InvalidArgumentException.class, (e, req, resp) -> {
            logger.error(e.getMessage(), e);
            resp.status(HttpURLConnection.HTTP_BAD_REQUEST);
            resp.type("application/json");
            resp.body(String.format("{\"message\":\"%s\"}", e.getMessage()));
        });

        Spark.staticFileLocation("/public");

        Weld.newInstance().initialize();
        WeldContainer.current().select(PeriodicTasksExecutorService.class).get();