List of usage examples for io.vertx.core DeploymentOptions setIsolatedClasses
public DeploymentOptions setIsolatedClasses(List<String> isolatedClasses)
From source file:examples.CoreExamples.java
License:Open Source License
public void example14(Vertx vertx) { DeploymentOptions options = new DeploymentOptions().setIsolationGroup("mygroup"); options.setIsolatedClasses(Arrays.asList("com.mycompany.myverticle.*", "com.mycompany.somepkg.SomeClass", "org.somelibrary.*")); vertx.deployVerticle("com.mycompany.myverticle.VerticleClass", options); }
From source file:io.github.bckfnn.actioner.Main.java
License:Apache License
public static void deploy(Class<? extends Verticle> verticle, String configName, String[] args, Handler<Vertx> result) throws Exception { if (args.length >= 1 && args[0].equals("stop")) { System.out.println("stopping"); System.exit(1);//from ww w . java 2s . co m } System.setProperty("appConfig", configName); System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory"); System.setProperty("vertx.disableFileCaching", "true"); Config config = loadConfig(); boolean develop = config.getBoolean("develop"); checkEndorsed(config, args); VertxOptions vertxOptions = new VertxOptions(); vertxOptions.setWorkerPoolSize(config.getInt("workerPoolSize")); if (config.hasPath("metrics")) { DropwizardMetricsOptions opt = new DropwizardMetricsOptions(); opt.setEnabled(config.getBoolean("metrics.enabled")); opt.setRegistryName(config.getString("metrics.registryName")); opt.addMonitoredHttpServerUri(new Match().setValue(".*").setType(MatchType.REGEX)); opt.addMonitoredHttpClientUri(new Match().setValue(".*").setType(MatchType.REGEX)); opt.addMonitoredEventBusHandler(new Match().setValue(".*").setType(MatchType.REGEX)); vertxOptions.setMetricsOptions(opt); } Vertx vertx = Vertx.vertx(vertxOptions); /* MetricRegistry registry = SharedMetricRegistries.getOrCreate("vertxRegistry"); ConsoleReporter rep = ConsoleReporter.forRegistry(registry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); rep.start(10, TimeUnit.SECONDS); */ /* System.out.println(vertx); MetricsService metricsService = MetricsService.create(vertx); JsonObject metrics = metricsService.getMetricsSnapshot(vertx); System.out.println("xx:" + metrics); System.out.println("xx:" + AbstractMetrics.class.getClassLoader()); */ DeploymentOptions opts = new DeploymentOptions(); opts.setInstances(config.getInt("instances")); if (develop) { opts.setIsolatedClasses(config.getStringList("isolatedClasses")); } AtomicReference<String> deploymentId = new AtomicReference<>(); Function<Handler<Vertx>, Void> deploy = h -> { if (develop) { opts.setIsolationGroup("ethics" + System.currentTimeMillis()); } vertx.deployVerticle(verticle.getName(), opts, res -> { if (res.succeeded()) { deploymentId.set(res.result()); h.handle(vertx); } else { res.cause().printStackTrace(); } }); return null; }; deploy.apply(result); if (develop) { redeploy(() -> { vertx.undeploy(deploymentId.get(), r -> { deploy.apply(h -> { System.err.println("redeployed!"); }); }); }); } }
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 *//*www . j a va 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 *///w w w . ja va 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);/*from ww w .java2 s.c om*/ } // 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(); }