// Path: src/main/java/com/groupon/vertx/utils/Logger.java
// public interface Logger {
// 
//     /**
//      * Returns a new logger for the specified target class and event source.  If the event source is not specified it
//      * will default to the simple name of the target class.
//      *
//      * @param targetClass target class for logging
//      * @param eventSource the eventSource
//      * @return a new com.groupon.vertx.utils.Logger
//      */
//     static Logger getLogger(Class<?> targetClass, String eventSource) {
//         return new LoggerImpl(targetClass, eventSource);
//     }
// 
//     /**
//      * Returns a new logger for the specified target class.  The logger's event source is defaulted to the
//      * simple name of the target class with the first letter lower cased.
//      *
//      * @param targetClass target class for logging
//      * @return a new com.groupon.vertx.utils.Logger
//      */
//     static Logger getLogger(Class<?> targetClass) {
//         return new LoggerImpl(targetClass, null);
//     }
// 
//     void error(String method, String event, String reason);
// 
//     void error(String method, String event, String reason, Throwable throwable);
// 
//     void error(String method, String event, String reason, String[] extraValueNames, Object... extraValues);
// 
//     void info(String method, String event);
// 
//     void info(String method, String event, String[] extraValueNames, Object... extraValues);
// 
//     void warn(String method, String event);
// 
//     void warn(String method, String event, Throwable throwable);
// 
//     void warn(String method, String event, String[] extraValueNames, Object... extraValues);
// 
//     void debug(String method, String event);
// 
//     void debug(String method, String event, String[] extraValueNames, Object... extraValues);
// 
//     void trace(String method, String event);
// 
//     void trace(String method, String event, String[] extraValueNames, Object... extraValues);
// 
//     boolean isInfoEnabled();
// 
//     boolean isWarnEnabled();
// 
//     boolean isTraceEnabled();
// 
//     boolean isDebugEnabled();
// 
//     boolean isErrorEnabled();
// }


import io.vertx.core.AsyncResult;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import com.groupon.vertx.utils.Logger;
/**
 * Copyright 2015 Groupon.com
 *
 * 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.groupon.vertx.utils.deployment;



/**
 * Handle deployments of verticles
 *
 * @author Tristan Blease (tblease at groupon dot com)
 * @since 2.0.1
 * @version 2.0.1
 */
public class VerticleDeployment implements Deployment {
    private static final Logger log = Logger.getLogger(VerticleDeployment.class, "verticleDeployment");

    protected final Vertx vertx;
    protected final String name;
    protected final String className;
    protected final Promise<String> deployId;


    public VerticleDeployment(Vertx vertx, String name, String className, Handler<AsyncResult<String>> finishedHandler) {
        this.vertx = vertx;
        this.name = name;
        this.className = className;

        deployId = Promise.promise();
        deployId.future().onComplete(finishedHandler);
    }

    @Override
    public void deploy(final int instances, JsonObject config) {
        log.info("deploy", "start", new String[]{"instances", "name", "class"}, instances, name, className);

        doDeploy(instances, config, new Handler<AsyncResult<String>>() {
            @Override
            public void handle(AsyncResult<String> deployResult) {
                if (deployResult.succeeded() && !deployResult.result().isEmpty()) {
                    log.debug("deploy", "success", new String[]{"message"}, String.format("Deployed verticle %s successfully", name));
                    deployId.complete(deployResult.result());
// Path: src/main/java/com/groupon/vertx/utils/Logger.java
// public interface Logger {
// 
//     /**
//      * Returns a new logger for the specified target class and event source.  If the event source is not specified it
//      * will default to the simple name of the target class.
//      *
//      * @param targetClass target class for logging
//      * @param eventSource the eventSource
//      * @return a new com.groupon.vertx.utils.Logger
//      */
//     static Logger getLogger(Class<?> targetClass, String eventSource) {
//         return new LoggerImpl(targetClass, eventSource);
//     }
// 
//     /**
//      * Returns a new logger for the specified target class.  The logger's event source is defaulted to the
//      * simple name of the target class with the first letter lower cased.
//      *
//      * @param targetClass target class for logging
//      * @return a new com.groupon.vertx.utils.Logger
//      */
//     static Logger getLogger(Class<?> targetClass) {
//         return new LoggerImpl(targetClass, null);
//     }
// 
//     void error(String method, String event, String reason);
// 
//     void error(String method, String event, String reason, Throwable throwable);
// 
//     void error(String method, String event, String reason, String[] extraValueNames, Object... extraValues);
// 
//     void info(String method, String event);
// 
//     void info(String method, String event, String[] extraValueNames, Object... extraValues);
// 
//     void warn(String method, String event);
// 
//     void warn(String method, String event, Throwable throwable);
// 
//     void warn(String method, String event, String[] extraValueNames, Object... extraValues);
// 
//     void debug(String method, String event);
// 
//     void debug(String method, String event, String[] extraValueNames, Object... extraValues);
// 
//     void trace(String method, String event);
// 
//     void trace(String method, String event, String[] extraValueNames, Object... extraValues);
// 
//     boolean isInfoEnabled();
// 
//     boolean isWarnEnabled();
// 
//     boolean isTraceEnabled();
// 
//     boolean isDebugEnabled();
// 
//     boolean isErrorEnabled();
// }


// Path: src/main/java/com/groupon/vertx/utils/deployment/VerticleDeployment.java
import io.vertx.core.AsyncResult;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import com.groupon.vertx.utils.Logger;

/**
 * Copyright 2015 Groupon.com
 *
 * 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.groupon.vertx.utils.deployment;



/**
 * Handle deployments of verticles
 *
 * @author Tristan Blease (tblease at groupon dot com)
 * @since 2.0.1
 * @version 2.0.1
 */
public class VerticleDeployment implements Deployment {
    private static final Logger log = Logger.getLogger(VerticleDeployment.class, "verticleDeployment");

    protected final Vertx vertx;
    protected final String name;
    protected final String className;
    protected final Promise<String> deployId;


    public VerticleDeployment(Vertx vertx, String name, String className, Handler<AsyncResult<String>> finishedHandler) {
        this.vertx = vertx;
        this.name = name;
        this.className = className;

        deployId = Promise.promise();
        deployId.future().onComplete(finishedHandler);
    }

    @Override
    public void deploy(final int instances, JsonObject config) {
        log.info("deploy", "start", new String[]{"instances", "name", "class"}, instances, name, className);

        doDeploy(instances, config, new Handler<AsyncResult<String>>() {
            @Override
            public void handle(AsyncResult<String> deployResult) {
                if (deployResult.succeeded() && !deployResult.result().isEmpty()) {
                    log.debug("deploy", "success", new String[]{"message"}, String.format("Deployed verticle %s successfully", name));
                    deployId.complete(deployResult.result());
                } else {