當前位置: 首頁>>代碼示例>>Java>>正文


Java Vertx.close方法代碼示例

本文整理匯總了Java中io.vertx.core.Vertx.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Vertx.close方法的具體用法?Java Vertx.close怎麽用?Java Vertx.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.Vertx的用法示例。


在下文中一共展示了Vertx.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: stop

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Override
public void stop(Runnable callback) {
    Vertx vertx = this.vertx;
    if (vertx != null) {
        logger.debug("Shutting down Vert.x instance");
        vertx.close(ar -> {
            if (ar.succeeded()) {
                logger.info("Vert.x instance shut down successfully");
            } else {
                logger.error("Failed to shut down Vert.x instance", ar.cause());
            }
            this.vertx = null;
            if (callback != null) {
                callback.run();
            }
        });
    }
}
 
開發者ID:unbroken-dome,項目名稱:vertx-spring,代碼行數:19,代碼來源:SpringVertx.java

示例2: testGetOrCreateVertx

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Test
public void testGetOrCreateVertx() throws InterruptedException {
  Vertx vertx = VertxUtils.getOrCreateVertxByName("ut", null);

  Holder<String> name = new Holder<>();
  CountDownLatch latch = new CountDownLatch(1);
  vertx.runOnContext(v -> {
    name.value = Thread.currentThread().getName();
    latch.countDown();
  });
  latch.await();

  Assert.assertEquals(name.value, "ut-vert.x-eventloop-thread-0");
  vertx.close();
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:16,代碼來源:TestVertxUtils.java

示例3: testVertxUtilsInitWithOptions

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Test
public void testVertxUtilsInitWithOptions() {
  VertxOptions oOptions = new VertxOptions();
  oOptions.setClustered(false);

  Vertx vertx = VertxUtils.init(oOptions);
  Assert.assertNotEquals(null, vertx);
  vertx.close();
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:10,代碼來源:TestVertxUtils.java

示例4: close

import io.vertx.core.Vertx; //導入方法依賴的package包/類
protected void close(final Vertx vertx) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    vertx.close(ar -> {
        latch.countDown();
    });
    awaitLatch(latch);
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:8,代碼來源:AsyncTestBase.java

示例5: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {
	Vertx vertx = Vertx.vertx();
	vertx.setPeriodic(2000, id -> {
		System.out.println("Timer fired with id : " +  id);
	});
	vertx.setPeriodic(5000, id -> {
		throw new RuntimeException("I failed in second timer");
	});
	
	try {
		TimeUnit.SECONDS.sleep(10);
	} catch (InterruptedException e) {
	}
	vertx.close();
}
 
開發者ID:gauravrmazra,項目名稱:gauravbytes,代碼行數:16,代碼來源:VertxPeriodicTimerExample.java

示例6: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {
	Vertx vertx = Vertx.vertx();
	CountDownLatch completion = new CountDownLatch(2);
	
	WorkerExecutor sharedWorker = vertx.createSharedWorkerExecutor("my-shared-pool", 20);
	sharedWorker.executeBlocking(successfulBlockingTask(), responseHandler(completion));
	sharedWorker.executeBlocking(failedBlockingTask(), responseHandler(completion));
	vertx.close();
}
 
開發者ID:gauravrmazra,項目名稱:gauravbytes,代碼行數:10,代碼來源:VertxWorkExecutorExample.java

示例7: testServiceAccess

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Test
public void testServiceAccess() {
  Vertx vertx = Vertx.vertx();
  vertx.deployVerticle(PortfolioVerticle.class.getName());

  PortfolioService proxy = ProxyHelper.createProxy(PortfolioService.class, vertx, PortfolioService.ADDRESS);

  assertThat(proxy).isNotNull();
  AtomicReference<Portfolio> reference = new AtomicReference<>();
  proxy.getPortfolio(ar -> reference.set(ar.result()));

  await().untilAtomic(reference, not(nullValue()));

  vertx.close();
}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:16,代碼來源:PortfolioVerticleTest.java

示例8: testVertxUtilsInitNullOptions

import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Test
public void testVertxUtilsInitNullOptions() {
  Vertx vertx = VertxUtils.init(null);
  Assert.assertNotEquals(null, vertx);
  vertx.close();
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:7,代碼來源:TestVertxUtils.java

示例9: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {

        if (args.length < 3) {
            System.err.println("Usage: AMQPReceiver <hostname> <port> <address>");
            System.exit(1);
        }

        host = args[0];
        port = Integer.valueOf(args[1]);
        address = args[2];

        if (args.length > 3) {
            username = args[3];
            password = args[4];
        }

        Vertx vertx = Vertx.vertx();

        ProtonClient client = ProtonClient.create(vertx);

        LOG.info("Starting receiver : connecting to [{}:{}] address [{}]", host, port, address);

        client.connect(host, port, username, password, done -> {

            if (done.succeeded()) {

                connection = done.result();
                connection.open();

                LOG.info("Connected as {}", connection.getContainer());

                receiver = connection.createReceiver(address);

                receiver.handler((delivery, message) -> {

                    Section section = message.getBody();

                    if (section instanceof AmqpValue) {
                        String text = (String) ((AmqpValue)section).getValue();
                        LOG.info("Received max = {} °C", text);
                    } else if (section instanceof Data) {
                        Binary data = ((Data)section).getValue();
                        int temp = Integer.valueOf(new String(data.getArray()));
                        LOG.info("Received max = {} °C", temp);
                    } else {
                        LOG.info("Discarded message : body type not supported");
                    }

                    delivery.disposition(Accepted.getInstance(), true);

                }).open();
            }

        });

        try {
            System.in.read();

            if (receiver.isOpen())
                receiver.close();
            connection.close();

            vertx.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
 
開發者ID:ppatierno,項目名稱:enmasse-iot-demo,代碼行數:70,代碼來源:AMQPReceiver.java

示例10: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {
	Vertx vertx = Vertx.vertx();
	DeploymentOptions options = new DeploymentOptions().setWorker(true);
	vertx.deployVerticle(new MyTestVerticle(), options);
	vertx.close();
}
 
開發者ID:gauravrmazra,項目名稱:gauravbytes,代碼行數:7,代碼來源:VerticleExample.java

示例11: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("h", true, "Messaging host");
    options.addOption("p", true, "Messaging port");
    options.addOption("a", true, "AMQP address");
    options.addOption("c", true, "Number of messages to send");
    options.addOption("d", true, "Delay between messages");
    options.addOption("u", false, "Print this help");

    CommandLineParser parser = new DefaultParser();

    try {
      CommandLine cmd = parser.parse(options, args);

      if (cmd.hasOption("u")) {

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("Sender", options);

      } else {

        String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST);
        int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT)));
        String amqpAddress = cmd.getOptionValue("a", AMQP_ADDRESS);
        int messagesCount = Integer.parseInt(cmd.getOptionValue("c", String.valueOf(MESSAGES_COUNT)));
        int messagesDelay = Integer.parseInt(cmd.getOptionValue("d", String.valueOf(MESSAGES_DELAY)));

        Vertx vertx = Vertx.vertx();

        LOG.info("Starting sender : connecting to [{}:{}] address [{}] msgs count/delay [{}/{}]",
          messagingHost, messagingPort, amqpAddress, messagesCount, messagesDelay);

        Sender sender = new Sender();
        sender.run(vertx, messagingHost, messagingPort, amqpAddress, messagesCount, messagesDelay);

        vertx.close();
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }

  }
 
開發者ID:ppatierno,項目名稱:amqp-kafka-demo,代碼行數:45,代碼來源:Sender.java

示例12: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("h", true, "Messaging host");
    options.addOption("p", true, "Messaging port");
    options.addOption("a", true, "AMQP address");
    options.addOption("f", true, "Filter");
    options.addOption("u", false, "Print this help");

    CommandLineParser parser = new DefaultParser();

    try {
      CommandLine cmd = parser.parse(options, args);

      if (cmd.hasOption("u")) {

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("Receiver", options);

      } else {

        String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST);
        int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT)));
        String amqpAddress = cmd.getOptionValue("a", AMQP_ADDRESS);
        String filter = cmd.getOptionValue("f", null);

        Vertx vertx = Vertx.vertx();

        LOG.info("Starting receiver : connecting to [{}:{}] address [{}]",
          messagingHost, messagingPort, amqpAddress);

        Receiver receiver = new Receiver();
        receiver.run(vertx, messagingHost, messagingPort, amqpAddress, filter);

        vertx.close();
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
 
開發者ID:ppatierno,項目名稱:amqp-kafka-demo,代碼行數:42,代碼來源:Receiver.java

示例13: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("h", true, "Messaging host");
    options.addOption("p", true, "Messaging port");
    options.addOption("a", true, "AMQP address");
    options.addOption("u", false, "Print this help");

    CommandLineParser parser = new DefaultParser();

    try {
      CommandLine cmd = parser.parse(options, args);

      if (cmd.hasOption("u")) {

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("Client", options);

      } else {

        String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST);
        int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT)));
        String amqpAddress = cmd.getOptionValue("a", AMQP_ADDRESS);

        Vertx vertx = Vertx.vertx();

        LOG.info("Starting server : connecting to [{}:{}]", messagingHost, messagingPort);

        Server server = new Server();
        server.run(vertx, messagingHost, messagingPort, amqpAddress);

        vertx.close();
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }

  }
 
開發者ID:ppatierno,項目名稱:amqp-kafka-demo,代碼行數:40,代碼來源:Server.java

示例14: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("h", true, "Messaging host");
    options.addOption("p", true, "Messaging port");
    options.addOption("a", true, "AMQP address");
    options.addOption("u", false, "Print this help");

    CommandLineParser parser = new DefaultParser();

    try {
      CommandLine cmd = parser.parse(options, args);

      if (cmd.hasOption("u")) {

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("Client", options);

      } else {

        String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST);
        int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT)));
        String amqpAddress = cmd.getOptionValue("a", AMQP_ADDRESS);

        Vertx vertx = Vertx.vertx();

        LOG.info("Starting client : connecting to [{}:{}]", messagingHost, messagingPort);

        Client client = new Client();
        client.run(vertx, messagingHost, messagingPort, amqpAddress);

        vertx.close();
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }

  }
 
開發者ID:ppatierno,項目名稱:amqp-kafka-demo,代碼行數:40,代碼來源:Client.java

示例15: main

import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static void main(String[] args) {

        if (args.length < 3) {
            System.err.println("Usage: AMQPPublisher <hostname> <port> <address>");
            System.exit(1);
        }

        host = args[0];
        port = Integer.valueOf(args[1]);
        address = args[2];

        if (args.length > 3) {
            username = args[3];
            password = args[4];
        }

        Vertx vertx = Vertx.vertx();

        ProtonClient client = ProtonClient.create(vertx);

        LOG.info("Starting publisher : connecting to [{}:{}] address [{}]", host, port, address);

        client.connect(host, port, username, password, done -> {

            if (done.succeeded()) {

                connection = done.result();
                connection.open();

                LOG.info("Connected as {}", connection.getContainer());

                sender = connection.createSender(address);
                sender.open();

                Random random = new Random();

                vertx.setPeriodic(1000, t -> {

                    if (!sender.sendQueueFull()) {

                        int temp = 20 + random.nextInt(5);

                        Message message = ProtonHelper.message();
                        message.setAddress(address);
                        message.setBody(new AmqpValue(String.valueOf(temp)));

                        LOG.info("Sending temperature = {} °C ...", temp);

                        if (sender.isOpen()) {

                            sender.send(message, delivery -> {
                                LOG.info("... delivered {}", delivery.getRemoteState());
                            });
                        }

                    }

                });
            }
        });

        try {
            System.in.read();

            if (sender.isOpen())
                sender.close();
            connection.close();

            vertx.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
開發者ID:ppatierno,項目名稱:enmasse-iot-demo,代碼行數:75,代碼來源:AMQPPublisher.java


注:本文中的io.vertx.core.Vertx.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。