package io.tiler.demo;

import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.AsyncResultHandlerWrapper;
import org.vertx.java.core.Future;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.core.logging.Logger;
import org.vertx.java.platform.Verticle;

public class MainVerticle extends Verticle {
  private Logger logger;

  public void start(final Future<Void> startedResult) {
    logger = container.logger();
    JsonObject config = container.config();

    Async.series()
      .task(handler -> container.deployVerticle("io.tiler.ServerVerticle", config.getObject("server"), 1, AsyncResultHandlerWrapper.wrap(handler)))
      .task(handler -> container.deployModule("io.tiler~tiler-collector-example~0.1.1", config.getObject("example"), 1, AsyncResultHandlerWrapper.wrap(handler)))
      .run(result -> {
        if (result.failed()) {
          startedResult.setFailure(result.cause());
          return;
        }

        logger.info("MainVerticle started");
        startedResult.setResult(null);
      });
  }
}

@@ -152,16 +152,59 @@
 Future;%0A
+import org.vertx.java.core.json.JsonArray;%0A
 import o
@@ -239,16 +239,16 @@
 Object;%0A
-
 import o
@@ -324,16 +324,99 @@
 ticle;%0A%0A
+import java.net.MalformedURLException;%0Aimport java.net.URL;%0Aimport java.util.Map;%0A%0A
 public c
@@ -476,16 +476,51 @@
  logger;
+%0A  private Map%3CString, String%3E env;
 %0A%0A  publ
@@ -602,16 +602,43 @@
 gger();%0A
+    env = container.env();%0A
     Json
@@ -1222,16 +1222,16 @@
 (null);%0A
-
       %7D)
@@ -1235,11 +1235,1181 @@
  %7D);%0A  %7D
+%0A%0A  private void mergeConfigWithEnvironmentVariables(JsonObject config) %7B%0A    mergeConfigWithRedisEnvironmentVariables(config);%0A  %7D%0A%0A  private void mergeConfigWithRedisEnvironmentVariables(JsonObject config) %7B%0A    JsonObject server = config.getObject(%22server%22);%0A%0A    if (server == null) %7B%0A      logger.warn(%22'server' is missing from the config%22);%0A      return;%0A    %7D%0A%0A    JsonObject redis = server.getObject(%22redis%22);%0A%0A    if (redis == null) %7B%0A      logger.warn(%22'redis' is missing from the config%22);%0A      return;%0A    %7D%0A%0A    String redisUrlString = getEnvironmentVariable(%22REDISTOGO_URL%22);%0A%0A    if (redisUrlString != null) %7B%0A      logger.info(%22Using Redis To Go%22);%0A      %0A      try %7B%0A        URL redisURL = new URL(redisUrlString);%0A        redis.putString(%22host%22, redisURL.getHost());%0A        redis.putNumber(%22port%22, redisURL.getPort());%0A      %7D catch (MalformedURLException e) %7B%0A        logger.error(%22Error parsing Redis URL%22, e);%0A      %7D%0A    %7D%0A  %7D%0A%0A  private String getEnvironmentVariable(String name) %7B%0A    String value = env.get(name);%0A%0A    if (value == null) %7B%0A      logger.warn(%22Environment variable '%22 + name + %22' has not been set%22);%0A    %7D%0A%0A    return value;%0A  %7D
 %0A%7D%0A

Load redis config from REDISTOGO_URL environment variable