Example usage for io.vertx.core DeploymentOptions setExtraClasspath

List of usage examples for io.vertx.core DeploymentOptions setExtraClasspath

Introduction

In this page you can find the example usage for io.vertx.core DeploymentOptions setExtraClasspath.

Prototype

public DeploymentOptions setExtraClasspath(List<String> extraClasspath) 

Source Link

Document

Set any extra classpath to be used when deploying the verticle.

Usage

From source file:io.silverware.microservices.utils.VertxUtils.java

License:Apache License

/**
 * Extracts the {@link DeploymentOptions} from {@link Deployment} annotation
 *
 * @param deploymentAnnotation {@link Deployment} annotation
 * @return {@link DeploymentOptions} for the given annotation
 *///from  www.  j  a v a 2  s . c  om
public static DeploymentOptions getDeploymentOptionsFromAnnotation(final Deployment deploymentAnnotation) {

    DeploymentOptions result = new DeploymentOptions();

    //if no deployment annotation is present return the default settings
    if (deploymentAnnotation == null) {
        return result;
    }

    //verticle type
    if (deploymentAnnotation.type() == VerticleType.WORKER) {
        result.setWorker(true);
    } else if (deploymentAnnotation.type() == VerticleType.MULTI_THREADED_WORKER) {
        result.setMultiThreaded(true);
    }

    //number of instances
    if (deploymentAnnotation.instances() > 1) {
        result.setInstances(deploymentAnnotation.instances());
    }

    //verticle isolation group
    if (!deploymentAnnotation.isolationGroup().isEmpty()) {
        result.setIsolationGroup(deploymentAnnotation.isolationGroup());
    }

    //verticle isolated classes
    if (deploymentAnnotation.isolatedClasses().length != 0) {
        result.setIsolatedClasses(Arrays.asList(deploymentAnnotation.isolatedClasses()));
    }

    //verticle extra classpath
    if (deploymentAnnotation.extraClasspath().length != 0) {
        result.setExtraClasspath(Arrays.asList(deploymentAnnotation.extraClasspath()));
    }

    //verticle high availability
    if (deploymentAnnotation.ha()) {
        result.setHa(true);
    }

    //verticle JSON config
    String jsonFileName = deploymentAnnotation.config();

    if (!jsonFileName.isEmpty()) {
        try (FileReader fileReader = new FileReader(jsonFileName)) {
            String jsonContent = IOUtils.toString(fileReader);
            result.setConfig(new JsonObject(jsonContent));
        } catch (Exception ex) {
            log.error("Invalid json config file: ", ex);
        }
    }

    return result;
}

From source file:io.silverware.microservices.utils.VertxUtils.java

License:Apache License

/**
 * Extracts the {@link DeploymentOptions} from the xml element
 *
 * @param verticleElement verticle element
 * @return the {@link DeploymentOptions} for the given verticle element
 *///from   ww w  . jav  a  2  s .  com
public static DeploymentOptions getDeploymentOptionsFromXml(final Node verticleElement) {

    DeploymentOptions result = new DeploymentOptions();
    NamedNodeMap attributes = verticleElement.getAttributes();

    for (int i = 0; i < attributes.getLength(); i++) {

        //verticle type
        if (attributes.getNamedItem(VertxConstants.TYPE) != null) {
            if (attributes.getNamedItem(VertxConstants.TYPE).getNodeValue()
                    .equals(VertxConstants.TYPE_WORKER)) {
                result.setWorker(true);
            } else if (attributes.getNamedItem(VertxConstants.TYPE).getNodeValue()
                    .equals(VertxConstants.TYPE_MULTI_THREADED_WORKER)) {
                result.setMultiThreaded(true);
            }
        }

        //number of instances
        if (attributes.getNamedItem(VertxConstants.INSTANCES) != null) {
            result.setInstances(
                    Integer.parseInt(attributes.getNamedItem(VertxConstants.INSTANCES).getNodeValue()));
        }

        //verticle isolation group
        if (attributes.getNamedItem(VertxConstants.ISOLATION_GROUP) != null) {
            result.setIsolationGroup(attributes.getNamedItem(VertxConstants.ISOLATION_GROUP).getNodeValue());
        }

        //verticle isolated classes
        if (attributes.getNamedItem(VertxConstants.ISOLATED_CLASSES) != null) {
            result.setIsolatedClasses(Arrays.asList(
                    attributes.getNamedItem(VertxConstants.ISOLATED_CLASSES).getNodeValue().split(" ")));
        }

        //verticle extra classpath
        if (attributes.getNamedItem(VertxConstants.EXTRA_CLASSPATH) != null) {
            result.setExtraClasspath(Arrays
                    .asList(attributes.getNamedItem(VertxConstants.EXTRA_CLASSPATH).getNodeValue().split(" ")));
        }

        //verticle high availability
        if (attributes.getNamedItem(VertxConstants.HA) != null) {
            result.setHa(Boolean.valueOf(attributes.getNamedItem(VertxConstants.HA).getNodeValue()));
        }

        //verticle JSON config
        if (attributes.getNamedItem(VertxConstants.CONFIG) != null) {
            try (FileReader fileReader = new FileReader(
                    attributes.getNamedItem(VertxConstants.CONFIG).getNodeValue())) {
                String jsonContent = IOUtils.toString(fileReader);
                result.setConfig(new JsonObject(jsonContent));
            } catch (Exception ex) {
                log.error("Invalid json config file: ", ex);
            }
        }
    }

    return result;
}

From source file:org.mustertech.webapp.vertxutils.VerticleDeployer.java

License:Open Source License

private static Promise<JsonObject, Exception, Double> deployWithOpts(JsonObject opt) {
    Deferred<JsonObject, Exception, Double> deffered = new DeferredObject<JsonObject, Exception, Double>();
    DeploymentOptions deployOpts = new DeploymentOptions();

    // Check and set Config option
    if (opt.containsKey("config")) {
        JsonObject vertCfg = opt.getJsonObject("config");
        deployOpts.setConfig(vertCfg);//  w w w .ja  v  a  2s  .co m
    }

    // Check and set ExtraClasspath option
    if (opt.containsKey("extCps")) {
        JsonArray extCps = opt.getJsonArray("extCps");
        Iterator<Object> cpIter = extCps.iterator();

        ArrayList<String> extCpsList = new ArrayList<String>();
        while (cpIter.hasNext()) {
            extCpsList.add((String) cpIter.next());
        }

        deployOpts.setExtraClasspath(extCpsList);
    }

    // Check and set Isolated-Group option
    if (opt.containsKey("isolatedGrp")) {
        deployOpts.setIsolationGroup(opt.getString("isolatedGrp"));
    }

    // Check and set Isolated-Classes option
    if (opt.containsKey("isolatedCls")) {
        JsonArray isoCls = opt.getJsonArray("isolatedCls");
        Iterator<Object> clsIter = isoCls.iterator();

        ArrayList<String> isoClsList = new ArrayList<String>();
        while (clsIter.hasNext()) {
            isoClsList.add((String) clsIter.next());
        }

        deployOpts.setIsolatedClasses(isoClsList);
    }

    // Check and set HA option
    deployOpts.setHa(opt.containsKey("isHa") && opt.getBoolean("isHa"));

    // Check and set instances option
    deployOpts.setInstances(opt.containsKey("nInst") ? opt.getInteger("nInst").intValue() : 1);

    // Check and set Worker/MT option
    Boolean isWorker = (opt.containsKey("isWorker") && opt.getBoolean("isWorker"));
    if (isWorker) {
        deployOpts.setWorker(true);
        deployOpts.setMultiThreaded(opt.containsKey("isMt") && opt.getBoolean("isMt"));
    }

    String vertName = opt.getString("name");

    // Finally, deploy the verticle
    vertx.deployVerticle(vertName, deployOpts, ar -> {
        if (ar.succeeded()) {
            JsonObject resObj = new JsonObject();
            resObj.put("verticleName", vertName).put("deployId", ar.result());

            deffered.resolve(resObj);
        } else {
            Throwable thr = ar.cause();
            String defErr = vertName + " => Could not be deployed!";
            deffered.reject(
                    (null != thr.getMessage()) ? new Exception(thr.getMessage()) : new Exception(defErr));
        }
    });

    return deffered.promise();
}