Java Code Examples for io.vertx.core.DeploymentOptions#setInstances()

The following examples show how to use io.vertx.core.DeploymentOptions#setInstances() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotVerticleFactory.java    From nubes with Apache License 2.0 6 votes vote down vote up
private DeploymentOptions getDeploymentOptions(Verticle annot) {
  DeploymentOptions options = new DeploymentOptions();
  if (annot.inheritsConfig()) {
    options.setConfig(config.json());
  }
  if (annot.instances() > 0) {
    options.setInstances(annot.instances());
  }
  if (!"".equals(annot.isolationGroup())) {
    options.setIsolationGroup(annot.isolationGroup());
  }
  options.setHa(annot.ha());
  options.setMultiThreaded(annot.multiThreaded());
  options.setWorker(annot.worker());
  return options;
}
 
Example 2
Source File: MainVerticle.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Future<Void> future) {

    DeploymentOptions options = new DeploymentOptions();
    options.setInstances(Runtime.getRuntime().availableProcessors());

    vertx.deployVerticle(HttpServerVerticle.class.getName(), options, res -> {
        if (!res.succeeded()) {
            logger.error("Deployment fail reason: ", res.cause());
        }
    });
}
 
Example 3
Source File: VertxNubesTestBase.java    From nubes with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp(TestContext context) throws Exception {
  vertx = Vertx.vertx();
  DeploymentOptions options = new DeploymentOptions();
  options.setInstances(NB_INSTANCES);
  JsonObject config = new JsonObject().put("controller-packages", getControllerPackages());
  //config.put("relectionprovider", "reflections");
  options.setConfig(config);
  vertx.deployVerticle("integration.TestVerticle", options, context.asyncAssertSuccess(handler -> {
    context.assertTrue(TestVerticle.dogService.size() > 0);
    context.assertEquals(NB_INSTANCES, AnnotatedVerticle.nbInstances.get());
    context.assertTrue(AnnotatedVerticle.isStarted.get());
  }));
}
 
Example 4
Source File: NubesServerTestBase.java    From nubes with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp(TestContext context) throws Exception {
  vertx = Vertx.vertx();
  DeploymentOptions options = new DeploymentOptions();
  options.setInstances(NB_INSTANCES);
  config = createConfig();
  options.setConfig(config);
  vertx.deployVerticle(NubesServer.class.getName(), options, context.asyncAssertSuccess(handler -> {
    context.assertEquals(NB_INSTANCES, AnnotatedVerticle.nbInstances.get());
    context.assertTrue(AnnotatedVerticle.isStarted.get());
  }));
}
 
Example 5
Source File: GaeAppEventListener.java    From gae with MIT License 4 votes vote down vote up
private void startHttpServer(ApplicationContext springCtx) {
    GaeServerProps props = springCtx.getBean(GaeServerProps.class);

    GaeHttpServer.springCtx = springCtx;


    // worker线程池选项
    VertxOptions options = new VertxOptions();
    int nioThreads = props.getNioThread() > 0 ? props.getNioThread() : Runtime.getRuntime().availableProcessors();
    options.setEventLoopPoolSize(nioThreads);
    options.setMaxWorkerExecuteTime(1000);
    // options.setWorkerPoolSize(nioThreads * 2);

    // 部署选项
    Vertx vertx = Vertx.vertx(options);
    DeploymentOptions depOptions = new DeploymentOptions();
    // 设置verticle数量为NIO线程数的2倍
    int verticleCount = nioThreads > 0 ? nioThreads * 2 : Runtime.getRuntime().availableProcessors();
    depOptions.setInstances(verticleCount);

    // 部署
    CountDownLatch latch = new CountDownLatch(1);
    vertx.deployVerticle(GaeHttpServer.class.getName(), depOptions, ar -> {
        if (ar.failed()) {
            log.warn("deploy failed, msg:", ar.cause());
        }

        latch.countDown();
    });

    try {
        // 等待部署完成
        latch.await();
        log.info("deploy succeeded, nioThread = {}, verticles = {}", nioThreads, verticleCount);

    } catch (InterruptedException e) {
        log.error("", e);
    }

    this.vertx = vertx;
}