// Path: core/src/main/java/org/n52/supervisor/api/CheckRunner.java
// public interface CheckRunner {
// 
// 	final IdentifierGenerator ID_GENERATOR = new ShortAlphanumericIdentifierGenerator();
// 
//     public void addResult(CheckResult r);
// 
//     public boolean check();
// 
//     public Check getCheck();
// 
//     public Collection<CheckResult> getResults();
//     
//     public Collection<CheckResult> getAndClearResults();
// 
//     public void notifyFailure();
// 
//     public void notifySuccess();
// 
//     public void setCheck(Check check) throws UnsupportedCheckException;
// 
//     /**
//      * @param rd
//      *        is required so that the runner can announce its results
//      */
//     public void setResultDatabase(ResultDatabase rd);
// 
// }
// 
// Path: core/src/main/java/org/n52/supervisor/api/CheckTask.java
// public interface CheckTask {
// 
//     public Collection<CheckResult> checkIt(CheckRunner c);
// 
// }
// 
// Path: core/src/main/java/org/n52/supervisor/api/CheckTaskFactory.java
// public interface CheckTaskFactory {
// 
//     CheckTask create(CheckRunner checker);
// 
// }


import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.n52.supervisor.api.CheckRunner;
import org.n52.supervisor.api.CheckTask;
import org.n52.supervisor.api.CheckTaskFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * ﻿Copyright (C) 2013 - 2014 52°North Initiative for Geospatial Open Source Software GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.n52.supervisor.tasks;




/**
 * 
 * This class can be used to execute {@link TimerTask} instances. It runs as a servlet and can be accessed by
 * other servlets for task scheduling and cancelling. The actual service method for GET and POST requests are
 * not implemented. It also provides methods to access the appropriate instances of
 * {@link ICatalogStatusHandler} and {@link ICatalogFactory} for tasks that run within this servlet.
 * 
 * @author Daniel Nüst (daniel.nuest@uni-muenster.de)
 * 
 */
@Singleton
public class ThreadPoolTaskExecutor implements TaskExecutor {


    private static final String CHECK_THREAD_COUNT = "CHECK_THREAD_COUNT";

    private ScheduledThreadPoolExecutor executor;

    private static Logger log = LoggerFactory.getLogger(ThreadPoolTaskExecutor.class);

    private static final String SEND_EMAILS = "supervisor.tasks.email.send";

    private Properties props;

    /**
     * List that holds all repeated task during run-time.
     */
    private ArrayList<TaskElement> tasks = new ArrayList<ThreadPoolTaskExecutor.TaskElement>();

    private String configFile = "/supervisor.properties";

// Path: core/src/main/java/org/n52/supervisor/api/CheckRunner.java
// public interface CheckRunner {
// 
// 	final IdentifierGenerator ID_GENERATOR = new ShortAlphanumericIdentifierGenerator();
// 
//     public void addResult(CheckResult r);
// 
//     public boolean check();
// 
//     public Check getCheck();
// 
//     public Collection<CheckResult> getResults();
//     
//     public Collection<CheckResult> getAndClearResults();
// 
//     public void notifyFailure();
// 
//     public void notifySuccess();
// 
//     public void setCheck(Check check) throws UnsupportedCheckException;
// 
//     /**
//      * @param rd
//      *        is required so that the runner can announce its results
//      */
//     public void setResultDatabase(ResultDatabase rd);
// 
// }
// 
// Path: core/src/main/java/org/n52/supervisor/api/CheckTask.java
// public interface CheckTask {
// 
//     public Collection<CheckResult> checkIt(CheckRunner c);
// 
// }
// 
// Path: core/src/main/java/org/n52/supervisor/api/CheckTaskFactory.java
// public interface CheckTaskFactory {
// 
//     CheckTask create(CheckRunner checker);
// 
// }


// Path: core/src/main/java/org/n52/supervisor/tasks/ThreadPoolTaskExecutor.java
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.n52.supervisor.api.CheckRunner;
import org.n52.supervisor.api.CheckTask;
import org.n52.supervisor.api.CheckTaskFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * ﻿Copyright (C) 2013 - 2014 52°North Initiative for Geospatial Open Source Software GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.n52.supervisor.tasks;




/**
 * 
 * This class can be used to execute {@link TimerTask} instances. It runs as a servlet and can be accessed by
 * other servlets for task scheduling and cancelling. The actual service method for GET and POST requests are
 * not implemented. It also provides methods to access the appropriate instances of
 * {@link ICatalogStatusHandler} and {@link ICatalogFactory} for tasks that run within this servlet.
 * 
 * @author Daniel Nüst (daniel.nuest@uni-muenster.de)
 * 
 */
@Singleton
public class ThreadPoolTaskExecutor implements TaskExecutor {


    private static final String CHECK_THREAD_COUNT = "CHECK_THREAD_COUNT";

    private ScheduledThreadPoolExecutor executor;

    private static Logger log = LoggerFactory.getLogger(ThreadPoolTaskExecutor.class);

    private static final String SEND_EMAILS = "supervisor.tasks.email.send";

    private Properties props;

    /**
     * List that holds all repeated task during run-time.
     */
    private ArrayList<TaskElement> tasks = new ArrayList<ThreadPoolTaskExecutor.TaskElement>();

    private String configFile = "/supervisor.properties";

    private CheckTaskFactory taskFactory;