public void run() { final CountDownLatch latch = new CountDownLatch(1); mgr.undeployAll(new Handler<AsyncResult<Void>>() { public void handle(AsyncResult<Void> res) { latch.countDown(); } }); try { if (!latch.await(30, TimeUnit.SECONDS)) { log.error("Timed out waiting to undeploy"); } } catch (InterruptedException e) { throw new IllegalStateException(e); } // Now shutdown the platform manager mgr.stop(); // Run any extra tasks Runnable task; while ((task = afterShutdownTasks.poll()) != null) { try { task.run(); } catch (Throwable t) { log.error("Failed to run after shutdown task", t); } } } });
@Override public void start(StartContext context) throws StartException { this.vertx = this.platformManagerInjector.getValue().vertx(); }
private void registerExitHandler(PlatformManager mgr) { mgr.registerExitHandler(new VoidHandler() { public void handle() { unblock(); } }); }
mgr.deployModuleFromZip(main, conf, instances, createLoggingHandler("deploying module from zip", doneHandler)); } else if (module) { final String deployMsg = "deploying module"; if (hasClasspath) { mgr.deployModuleFromClasspath(main, conf, instances, classpath, createLoggingHandler(deployMsg, doneHandler)); } else if (ha) { mgr.deployModule(main, conf, instances, true, createLoggingHandler(deployMsg, doneHandler)); } else { mgr.deployModule(main, conf, instances, createLoggingHandler(deployMsg, doneHandler)); String includes = args.map.get("-includes"); if (worker) { mgr.deployWorkerVerticle(false, main, conf, classpath, instances, includes, createLoggingHandler("deploying worker verticle", doneHandler)); } else { mgr.deployVerticle(main, conf, classpath, instances, includes, createLoggingHandler("deploying verticle", doneHandler));
EventBus eb = mgr.vertx().eventBus(); eb.registerHandler(TESTRUNNER_HANDLER_ADDRESS, handler); final CountDownLatch deployLatch = new CountDownLatch(1); mgr.deployVerticle(main, conf, urls.toArray(new URL[urls.size()]), 1, includes, new AsyncResultHandler<String>() { public void handle(AsyncResult<String> ar) { if (ar.succeeded()) { final CountDownLatch undeployLatch = new CountDownLatch(1); final AtomicReference<Throwable> undeployThrowable = new AtomicReference<>(); mgr.undeploy(deploymentIDRef.get(), new AsyncResultHandler<Void>() { public void handle(AsyncResult<Void> ar) { if (ar.failed()) {
/** * Stop the platform manager */ @Override public void stop() { manager.stop(); } }
public static void runDataStoreServer(int port) throws IOException { PlatformManager platformManager = PlatformLocator.factory.createPlatformManager(); JsonObject jsonObject = new JsonObject(); jsonObject.putNumber("port", port); URL url = new File(".", "target/classes").getCanonicalFile().toURL(); platformManager.deployVerticle("org.boon.slumberdb.DataStoreVerticle", jsonObject, new URL[]{url}, 1, null, new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> stringAsyncResult) { if (stringAsyncResult.succeeded()) { puts("Launched verticle"); } } } ); // Prevent the JVM from exiting System.in.read(); }
private void pullDependencies(String modName) { log.info("Attempting to pull in dependencies for module " + modName); createPM().pullInDependencies(modName, createLoggingHandler("pulling in dependencies", unblockHandler())); block(); }
private void installModule(String modName) { log.info("Attempting to install module " + modName); createPM().installModule(modName, createLoggingHandler("installing module", unblockHandler())); block(); }
/** * Deploy a module * * @param moduleName The name of the module to deploy * @param config Any JSON config to pass to the verticle, or null if none * @param instances The number of instances to deploy * @return Promise of deployment */ @Override public Promise<String> deployModule(String moduleName, JsonObject config, int instances) { final Deferred<String> d = when.defer(); manager.deployModule(moduleName, config, instances, result -> { if (result.succeeded()) { d.resolve(result.result()); } else { d.reject(result.cause()); } }); return d.getPromise(); }
/** * Deploy a module from a zip file. The zip must contain a valid Vert.x module. Vert.x will automatically install the module from the zip into the local mods dir or the system mods dir (if it's a system module), or VERTX_MODS if set, and then deploy the module * * @param zipFileName The name of the zip file that contains the module * @param config Any JSON config to pass to the verticle, or null if none * @param instances The number of instances to deploy * @return Promise of deployment */ @Override public Promise<String> deployModuleFromZip(String zipFileName, JsonObject config, int instances) { final Deferred<String> d = when.defer(); manager.deployModuleFromZip(zipFileName, config, instances, result -> { if (result.succeeded()) { d.resolve(result.result()); } else { d.reject(result.cause()); } }); return d.getPromise(); }
/** * Deploy a worker verticle * * @param multiThreaded Is it a multi-threaded worker verticle? * @param main The main, e.g. app.js, foo.rb, org.mycompany.MyMain, etc * @param config Any JSON config to pass to the verticle, or null if none * @param classpath The classpath for the verticle * @param instances The number of instances to deploy * @param includes Comma separated list of modules to include, or null if none * @return Promise of deployment */ @Override public Promise<String> deployWorkerVerticle(boolean multiThreaded, String main, JsonObject config, URL[] classpath, int instances, String includes) { final Deferred<String> d = when.defer(); manager.deployWorkerVerticle(multiThreaded, main, config, classpath, instances, includes, result -> { if (result.succeeded()) { d.resolve(result.result()); } else { d.reject(result.cause()); } }); return d.getPromise(); }
/** * Deploy a module from the classpath. The classpath must contain a single mod.json and the resources for that module only. * * @param moduleName The name of the module to deploy * @param config Any JSON config to pass to the verticle, or null if none * @param instances The number of instances to deploy * @param classpath Array of URLS corresponding to the classpath for the module * @return Promise of deployment */ @Override public Promise<String> deployModuleFromClasspath(String moduleName, JsonObject config, int instances, URL[] classpath) { final Deferred<String> d = when.defer(); manager.deployModuleFromClasspath(moduleName, config, instances, classpath, result -> { if (result.succeeded()) { d.resolve(result.result()); } else { d.reject(result.cause()); } }); return d.getPromise(); }
@Override public void stop(StopContext context) { this.platformManager.stop(); }
/** * Deploy a verticle * * @param main The main, e.g. app.js, foo.rb, org.mycompany.MyMain, etc * @param config Any JSON config to pass to the verticle, or null if none * @param classpath The classpath for the verticle * @param instances The number of instances to deploy * @param includes Comma separated list of modules to include, or null if none * @return Promise of deployment */ @Override public Promise<String> deployVerticle(String main, JsonObject config, URL[] classpath, int instances, String includes) { final Deferred<String> d = when.defer(); manager.deployVerticle(main, config, classpath, instances, includes, result -> { if (result.succeeded()) { d.resolve(result.result()); } else { d.reject(result.cause()); } }); return d.getPromise(); }
/** * Pull in all the dependencies (the 'includes' and the 'deploys' fields in mod.json) and copy them into an internal mods directory in the module. This allows a self contained module to be created. * * @param moduleName The name of the module * @return Promise of pull */ @Override public Promise<Void> pullInDependencies(String moduleName) { final Deferred<Void> d = when.defer(); manager.pullInDependencies(moduleName, result -> { if (result.succeeded()) { d.resolve(result.result()); } else { d.reject(result.cause()); } }); return d.getPromise(); }
/** * Install a module into the filesystem Vert.x will search in the configured repos to locate the module * * @param moduleName The name of the module * @return Promise of installation */ @Override public Promise<Void> installModule(String moduleName) { final Deferred<Void> d = when.defer(); manager.installModule(moduleName, result -> { if (result.succeeded()) { d.resolve(result.result()); } else { d.reject(result.cause()); } }); return d.getPromise(); }
@Override public void stop() throws Exception { if (!isStarted) { return; } eventBus.unregisterHandler(vertxAddress, handler); platformManager.stop(); System.clearProperty("vertx.clusterManagerFactory"); isStarted = false; ActiveMQVertxLogger.LOGGER.debug(connectorName + ": stopped"); }
@Override public void start() throws Exception { if (this.isStarted) { return; } System.setProperty("vertx.clusterManagerFactory", HazelcastClusterManagerFactory.class.getName()); if (quorumSize != -1) { platformManager = PlatformLocator.factory.createPlatformManager(port, host, quorumSize, haGroup); } else { platformManager = PlatformLocator.factory.createPlatformManager(port, host); } eventBus = platformManager.vertx().eventBus(); if (this.connectorName == null || this.connectorName.trim().equals("")) { throw new Exception("invalid connector name: " + this.connectorName); } if (this.queueName == null || this.queueName.trim().equals("")) { throw new Exception("invalid queue name: " + queueName); } SimpleString name = new SimpleString(this.queueName); Binding b = this.postOffice.getBinding(name); if (b == null) { throw new Exception(connectorName + ": queue " + queueName + " not found"); } this.queue = (Queue) b.getBindable(); this.queue.addConsumer(this); this.queue.deliverAsync(); this.isStarted = true; ActiveMQVertxLogger.LOGGER.debug(connectorName + ": started"); }
/** * Register a handler that will be called when the platform exits because of a verticle calling container.exit() * * @param handler The handler */ @Override public void registerExitHandler(Handler<Void> handler) { manager.registerExitHandler(handler); }