io.vertx.core.Launcher Maven / Gradle / Ivy
/*
* Copyright (c) 2011-2015 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.vertx.core;
import io.vertx.core.impl.launcher.VertxCommandLauncher;
import io.vertx.core.impl.launcher.VertxLifecycleHooks;
/**
* A {@code main()} class that can be used to create Vert.x instance and deploy a verticle, or run a bare Vert.x instance.
*
* This class is used by the {@code vertx} command line utility to deploy verticles from the command line.
* It is extensible as "commands" can be added using the {@link io.vertx.core.spi.launcher.CommandFactory}
* SPI.
*
* E.g.
*
* {@code vertx run myverticle.js}
* {@code vertx my-command ...}
*
* It can also be used as the main class of an executable jar so you can run verticles directly with:
*
* {@code java -jar myapp.jar}
*
* @author Clement Escoffier
*/
public class Launcher extends VertxCommandLauncher implements VertxLifecycleHooks {
/**
* Main entry point.
*
* @param args the user command line arguments.
*/
public static void main(String[] args) {
new Launcher().dispatch(args);
}
/**
* Utility method to execute a specific command.
*
* @param cmd the command
* @param args the arguments
*/
public static void executeCommand(String cmd, String... args) {
new Launcher().execute(cmd, args);
}
/**
* Hook for sub-classes of {@link Launcher} before the vertx instance is started.
*/
public void beforeStartingVertx(VertxOptions options) {
}
/**
* Hook for sub-classes of {@link Launcher} after the vertx instance is started.
*/
public void afterStartingVertx(Vertx vertx) {
}
/**
* Hook for sub-classes of {@link Launcher} before the verticle is deployed.
*/
public void beforeDeployingVerticle(DeploymentOptions deploymentOptions) {
}
/**
* A deployment failure has been encountered. You can override this method to customize the behavior.
* By default it closes the `vertx` instance.
*/
public void handleDeployFailed(Vertx vertx, String mainVerticle, DeploymentOptions deploymentOptions, Throwable cause) {
// Default behaviour is to close Vert.x if the deploy failed
vertx.close();
}
}