// Path: src/main/java/org/chorem/ecd/task/EcdPeriodicTask.java
// public abstract class EcdPeriodicTask implements Runnable {
// 
//     protected EcdConfig config;
// 
//     protected JsonService jsonService;
// 
//     public abstract String getName();
// 
//     public abstract Integer getPeriodicity();
// 
//     public abstract TimeUnit getPeriodicityUnit();
// 
//     public void setConfig(EcdConfig config) {
//         this.config = config;
//     }
// 
//     public void setJsonService(JsonService jsonService) {
//         this.jsonService = jsonService;
//     }
// 
// }


import com.google.common.collect.Maps;
import org.chorem.ecd.task.EcdPeriodicTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Singleton;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
package org.chorem.ecd.service;



/**
 * @author Julien Gaston (gaston@codelutin.com)
 */
@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();
    }

// Path: src/main/java/org/chorem/ecd/task/EcdPeriodicTask.java
// public abstract class EcdPeriodicTask implements Runnable {
// 
//     protected EcdConfig config;
// 
//     protected JsonService jsonService;
// 
//     public abstract String getName();
// 
//     public abstract Integer getPeriodicity();
// 
//     public abstract TimeUnit getPeriodicityUnit();
// 
//     public void setConfig(EcdConfig config) {
//         this.config = config;
//     }
// 
//     public void setJsonService(JsonService jsonService) {
//         this.jsonService = jsonService;
//     }
// 
// }


// Path: src/main/java/org/chorem/ecd/service/PeriodicTasksExecutorService.java
import com.google.common.collect.Maps;
import org.chorem.ecd.task.EcdPeriodicTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Singleton;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;

package org.chorem.ecd.service;



/**
 * @author Julien Gaston (gaston@codelutin.com)
 */
@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) {