// Path: core/src/main/java/org/n52/supervisor/db/StorageModule.java
// public class StorageModule extends AbstractModule {
// 
//     private static Logger log = LoggerFactory.getLogger(StorageModule.class);
// 
//     @Override
//     public void configure() {
//         bind(CheckDatabase.class);
//         bind(ResultDatabase.class);
// 
//         log.info("Configured {}", this);
//     }
// 
// }
// 
// Path: core/src/main/java/org/n52/supervisor/id/IdentificationModule.java
// public class IdentificationModule extends AbstractModule {
// 
//     @Override
//     protected void configure() {
//         bind(IdentifierGenerator.class).to(ShortAlphanumericIdentifierGenerator.class);
//     }
// 
// }
// 
// Path: core/src/main/java/org/n52/supervisor/tasks/TaskModule.java
// public class TaskModule extends AbstractModule {
// 
//     private static Logger log = LoggerFactory.getLogger(TaskModule.class);
// 
//     @Override
//     protected void configure() {
//         bind(TaskExecutor.class).to(QuartzTaskExecutor.class);
//         bind(Scheduler.class).to(JobSchedulerImpl.class);
// 
//         install(new FactoryModuleBuilder().implement(CheckTask.class, CheckTaskImpl.class).build(CheckTaskFactory.class));
// 
//         log.info("Configured {}", this);
//         
//     }
// 
// }


import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
import java.util.concurrent.Executors;
import javax.servlet.ServletContextEvent;
import org.n52.supervisor.db.StorageModule;
import org.n52.supervisor.id.IdentificationModule;
import org.n52.supervisor.tasks.TaskModule;
import org.nnsoft.guice.lifegycle.DisposeModule;
import org.nnsoft.guice.lifegycle.Disposer;
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;





/**
 * http://code.google.com/p/google-guice/wiki/ServletModule
 */
public class GuiceServletConfig extends GuiceServletContextListener {
	
	private static final Logger logger = LoggerFactory.getLogger(GuiceServletConfig.class);

    private class InitThread extends Thread {

        private Injector i;

        public InitThread(Injector i) {
            this.i = i;
        }

        @Override
        public void run() {
            SupervisorInit instance = this.i.getInstance(SupervisorInit.class);
            System.out.println(instance);
        }

    }

	private Injector injector;
    
    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
    	super.contextDestroyed(servletContextEvent);
    	
    	injector.getInstance(Disposer.class).dispose();
    }

    @Override
    protected Injector getInjector() {
    	List<AbstractModule> modules = new ArrayList<>();
    	
    	modules.add(new SupervisorProperties.Module());
    	modules.add(new IdentificationModule());
    	modules.add(new ConfigModule());
    	modules.add(new StorageModule());
    	modules.add(new SupervisorModule());
// Path: core/src/main/java/org/n52/supervisor/db/StorageModule.java
// public class StorageModule extends AbstractModule {
// 
//     private static Logger log = LoggerFactory.getLogger(StorageModule.class);
// 
//     @Override
//     public void configure() {
//         bind(CheckDatabase.class);
//         bind(ResultDatabase.class);
// 
//         log.info("Configured {}", this);
//     }
// 
// }
// 
// Path: core/src/main/java/org/n52/supervisor/id/IdentificationModule.java
// public class IdentificationModule extends AbstractModule {
// 
//     @Override
//     protected void configure() {
//         bind(IdentifierGenerator.class).to(ShortAlphanumericIdentifierGenerator.class);
//     }
// 
// }
// 
// Path: core/src/main/java/org/n52/supervisor/tasks/TaskModule.java
// public class TaskModule extends AbstractModule {
// 
//     private static Logger log = LoggerFactory.getLogger(TaskModule.class);
// 
//     @Override
//     protected void configure() {
//         bind(TaskExecutor.class).to(QuartzTaskExecutor.class);
//         bind(Scheduler.class).to(JobSchedulerImpl.class);
// 
//         install(new FactoryModuleBuilder().implement(CheckTask.class, CheckTaskImpl.class).build(CheckTaskFactory.class));
// 
//         log.info("Configured {}", this);
//         
//     }
// 
// }


// Path: core/src/main/java/org/n52/supervisor/GuiceServletConfig.java
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
import java.util.concurrent.Executors;
import javax.servlet.ServletContextEvent;
import org.n52.supervisor.db.StorageModule;
import org.n52.supervisor.id.IdentificationModule;
import org.n52.supervisor.tasks.TaskModule;
import org.nnsoft.guice.lifegycle.DisposeModule;
import org.nnsoft.guice.lifegycle.Disposer;
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;





/**
 * http://code.google.com/p/google-guice/wiki/ServletModule
 */
public class GuiceServletConfig extends GuiceServletContextListener {
	
	private static final Logger logger = LoggerFactory.getLogger(GuiceServletConfig.class);

    private class InitThread extends Thread {

        private Injector i;

        public InitThread(Injector i) {
            this.i = i;
        }

        @Override
        public void run() {
            SupervisorInit instance = this.i.getInstance(SupervisorInit.class);
            System.out.println(instance);
        }

    }

	private Injector injector;
    
    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
    	super.contextDestroyed(servletContextEvent);
    	
    	injector.getInstance(Disposer.class).dispose();
    }

    @Override
    protected Injector getInjector() {
    	List<AbstractModule> modules = new ArrayList<>();
    	
    	modules.add(new SupervisorProperties.Module());
    	modules.add(new IdentificationModule());
    	modules.add(new ConfigModule());
    	modules.add(new StorageModule());
    	modules.add(new SupervisorModule());
    	modules.add(new TaskModule());