/**
 *    Copyright 2012 meltmedia
 *
 *    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 com.meltmedia.cadmium.servlets.guice;

import com.meltmedia.cadmium.core.worker.CheckConfigInitializedTask;
import com.meltmedia.cadmium.core.worker.CheckInitializedTask;
import com.meltmedia.cadmium.core.worker.ConfigInitializeTask;
import com.meltmedia.cadmium.core.worker.InitializeTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.Closeable;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Singleton
public class Initializor implements Closeable {
  private final Logger log = LoggerFactory.getLogger(getClass());
  private ExecutorService pool = null;
  
  @Inject
  public Initializor(InitializeTask task, CheckInitializedTask task2, ConfigInitializeTask task3, CheckConfigInitializedTask task4) {
    log.debug("Submitting initialization tasks.");
    this.pool = Executors.newSingleThreadExecutor();
    
    pool.submit(task2.setExecutor(pool).setFuture(pool.submit(task)));
    
    pool.submit(task4.setExecutor(pool).setFuture(pool.submit(task3)));
  }

  @Override
  public void close() throws IOException {
    try {
      pool.shutdownNow();
    } catch (Throwable t) {}
    pool = null;
  }
  
}

@@ -1612,17 +1612,17 @@
 mit(task
-2
+4
 .setExec
@@ -1658,16 +1658,17 @@
 mit(task
+3
 )));%0A   
@@ -1681,33 +1681,33 @@
 pool.submit(task
-4
+2
 .setExecutor(poo
@@ -1731,25 +1731,24 @@
 .submit(task
-3
 )));%0A  %7D%0A%0A  

Initialize config prior to content