List of usage examples for io.vertx.core Vertx close
Future<Void> close();
From source file:com.baldmountain.depot.DbSeed.java
License:Open Source License
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); JsonObject config = new JsonObject().put("db_name", "depot_development"); mongoService = MongoService.create(vertx, config); mongoService.start();//from w w w. j a v a 2s . c om mongoService.dropCollection("line_items", res1 -> { if (res1.succeeded()) { mongoService.dropCollection("carts", res2 -> { if (res2.succeeded()) { mongoService.dropCollection("products", event1 -> { if (event1.succeeded()) { LinkedList<Product> products = new LinkedList<>(); products.add(new Product("CoffeeScript", "<p>\n" + " CoffeeScript is JavaScript done right. It provides all of JavaScript's " + "functionality wrapped in a cleaner, more succinct syntax. In the first " + "book on this exciting new language, CoffeeScript guru Trevor Burnham " + "shows you how to hold onto all the power and flexibility of JavaScript " + "while writing clearer, cleaner, and safer code.</p>", "/images/cs.jpg", new BigDecimal(36.00).setScale(2, RoundingMode.CEILING))); products.add(new Product("Programming Ruby 1.9 & 2.0", "<p>Ruby is the fastest growing and most exciting dynamic language " + "out there. If you need to get working programs delivered fast, " + "you should add Ruby to your toolbox. </p>", "/images/ruby.jpg", new BigDecimal(49.95).setScale(2, RoundingMode.CEILING))); products.add(new Product("Rails Test Prescriptions", "<p><em>Rails Test Prescriptions</em> is a comprehensive guide to testing " + "Rails applications, covering Test-Driven Development from both a theoretical perspective (why to test) and from a practical perspective " + "(how to test effectively). It covers the core Rails testing tools and procedures for Rails 2 and Rails 3, and introduces popular add-ons, " + "including Cucumber, Shoulda, Machinist, Mocha, and Rcov.</p>", "/images/rtp.jpg", new BigDecimal(34.95).setScale(2, RoundingMode.CEILING))); saveAProduct(products); } else { setDone("Trouble dropping products"); } }); } else { setDone("Trouble dropping carts"); } }); } else { setDone("Trouble dropping line_items"); } }); try { synchronized (lock) { while (!done) lock.wait(); } } catch (InterruptedException e) { e.printStackTrace(); } vertx.close(); }
From source file:com.company.vertxstarter.Bootstrap.java
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); vertx.deployVerticle(new MainVerticle()); Runtime.getRuntime().addShutdownHook(new Thread() { @Override//from w w w .j av a 2 s . c o m public void run() { vertx.close(); } }); }
From source file:com.julienviet.aeron.benchmark.VertxSubscriptionEmbeddedIpcThroughput.java
License:Apache License
public static void main(final String[] args) throws Exception { MediaDriver.loadPropertiesFiles(args); final AtomicBoolean running = new AtomicBoolean(true); SigInt.register(() -> running.set(false)); final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED) .sharedIdleStrategy(new NoOpIdleStrategy()); Vertx vertx = Vertx.vertx(); try (final MediaDriver ignore = MediaDriver.launch(ctx); final Aeron aeron = Aeron.connect(); final Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) { AeronClient client = AeronClient.create(vertx, aeron); final Subscriber subscriber = new Subscriber(); final Thread publisherThread = new Thread(new Publisher(running, publication)); publisherThread.setName("publisher"); final Thread rateReporterThread = new Thread(new RateReporter(running, subscriber)); rateReporterThread.setName("rate-reporter"); rateReporterThread.start();/*from www.j a v a 2 s. com*/ subscriber.run(client); publisherThread.start(); publisherThread.join(); rateReporterThread.join(); subscriber.close(); vertx.close(); } }
From source file:com.redhat.example.ImageAnalyzer.java
License:Apache License
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); ProtonClient client = ProtonClient.create(vertx); client.connect(SERVER_HOST, SERVER_PORT, res -> { if (!res.succeeded()) { System.out.println("Failed to connect: " + res.cause()); vertx.close(); return; }/*w w w. jav a 2 s .c o m*/ ProtonConnection connection = res.result(); connection.open(); ProtonSender sender = connection.createSender(null); sender.openHandler(x -> { connection.createReceiver(REQUEST_ADDRESS).handler((delivery, requestMsg) -> { // Process the request and send a response String content = getRequestContent(requestMsg); System.out.println("image-analyzer: Received request: " + content); String response = content + "\nCompleted Image Analysis"; Message responseMessage = createResponseMessage(requestMsg, response); sender.send(responseMessage); }).open(); }).open(); }); }
From source file:enmasse.kafka.bridge.example.BridgeReceiver.java
License:Apache License
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); BridgeReceiver receiver = new BridgeReceiver(); // multiple receivers on same connection, same session but different links BridgeReceiver.ExampleOne ex1 = receiver.new ExampleOne(); ex1.run(vertx);//from w w w.ja v a 2s . c o m vertx.close(); }
From source file:enmasse.kafka.bridge.example.BridgeSender.java
License:Apache License
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); BridgeSender sender = new BridgeSender(); // simple message sending BridgeSender.ExampleOne ex1 = sender.new ExampleOne(); ex1.run(vertx);/*from w w w . j av a 2 s.co m*/ // periodic message sending BridgeSender.ExampleTwo ex2 = sender.new ExampleTwo(); ex2.run(vertx); vertx.close(); }
From source file:enmasse.kafka.bridge.example.BridgeServer.java
License:Apache License
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); BridgeConfigProperties bridgeConfigProperties = new BridgeConfigProperties(); Bridge bridge = new Bridge(); bridge.setBridgeConfigProperties(bridgeConfigProperties); vertx.deployVerticle(bridge);/*from w w w . j ava2s .c om*/ try { System.in.read(); vertx.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:io.apiman.gateway.platforms.vertx3.ApimanLauncher.java
License:Apache License
/** * A deployment failure has been encountered. You can override this method to customize the behavior. * By default it closes the `vertx` instance. * * @param vertx the vert.x instance * @param mainVerticle the verticle * @param deploymentOptions the verticle deployment options * @param cause the cause of the failure *//*from w ww . j a va 2 s .c o m*/ @Override public void handleDeployFailed(Vertx vertx, String mainVerticle, DeploymentOptions deploymentOptions, Throwable cause) { // Default behaviour is to close Vert.x if the deploy failed vertx.close(); }
From source file:io.rhiot.kafka.bridge.example.BridgeServer.java
License:Apache License
public static void main(String[] args) { String config = (args.length > 0 && !args[0].isEmpty()) ? args[0] : null; Vertx vertx = Vertx.vertx(); Bridge bridge = new Bridge(vertx, config); bridge.start();//from w w w.j a va 2 s .com try { System.in.read(); bridge.stop(); vertx.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.ssorj.quiver.QuiverArrowVertxProton.java
License:Apache License
private static void doMain(final String[] args) throws Exception { final HashMap<String, String> kwargs = new HashMap<>(); for (String arg : args) { final String[] elems = arg.split("=", 2); kwargs.put(elems[0], elems[1]);/*from w w w . j a v a 2 s. c o m*/ } final String connectionMode = kwargs.get("connection-mode"); final String channelMode = kwargs.get("channel-mode"); final String operation = kwargs.get("operation"); final String id = kwargs.get("id"); final String host = kwargs.get("host"); final int port = Integer.parseInt(kwargs.get("port")); final String path = kwargs.get("path"); final int desiredDuration = Integer.parseInt(kwargs.get("duration")); final int desiredCount = Integer.parseInt(kwargs.get("count")); final int bodySize = Integer.parseInt(kwargs.get("body-size")); final int creditWindow = Integer.parseInt(kwargs.get("credit-window")); final int transactionSize = Integer.parseInt(kwargs.get("transaction-size")); final boolean durable = Integer.parseInt(kwargs.get("durable")) == 1; if (!CLIENT.equalsIgnoreCase(connectionMode)) { throw new RuntimeException("This impl currently supports client mode only"); } if (!ACTIVE.equalsIgnoreCase(channelMode)) { throw new RuntimeException("This impl currently supports active mode only"); } if (transactionSize > 0) { throw new RuntimeException("This impl doesn't support transactions"); } final boolean sender; if (SEND.equalsIgnoreCase(operation)) { sender = true; } else if (RECEIVE.equalsIgnoreCase(operation)) { sender = false; } else { throw new java.lang.IllegalStateException("Unknown operation: " + operation); } final CountDownLatch completionLatch = new CountDownLatch(1); final Vertx vertx = Vertx.vertx(new VertxOptions().setPreferNativeTransport(true)); final ProtonClient client = ProtonClient.create(vertx); client.connect(host, port, (res) -> { if (res.succeeded()) { final ProtonConnection connection = res.result(); connection.setContainer(id); connection.closeHandler(x -> { completionLatch.countDown(); }); if (desiredDuration > 0) { vertx.setTimer(desiredDuration * 1000, timerId -> { connection.close(); }); } if (sender) { send(connection, path, desiredCount, bodySize, durable); } else { receive(connection, path, desiredCount, creditWindow); } } else { res.cause().printStackTrace(); completionLatch.countDown(); } }); // Await the operations completing, then shut down the Vertx // instance. completionLatch.await(); vertx.close(); }