Java Code Examples for io.vertx.core.VertxOptions#setBlockedThreadCheckInterval()

The following examples show how to use io.vertx.core.VertxOptions#setBlockedThreadCheckInterval() . 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: TestMain.java    From Summer with MIT License 6 votes vote down vote up
public static void main(String args[]){

        VertxOptions options = new VertxOptions();
        options.setBlockedThreadCheckInterval(20000);
        options.setMaxEventLoopExecuteTime(20000);
        SummerServer summerServer =SummerServer.create("localhost",8080,options);

        DeploymentOptions deploymentOptions = new DeploymentOptions();
        summerServer.getVertx().
                deployVerticle(MyVerticle.class.getName());
        deploymentOptions.setWorker(true);
        summerServer.getSummerRouter().registerResource(Hello.class);
        summerServer.getVertx().
                deployVerticle(SummerServer.WebServer.class.getName());
        summerServer.start(deploymentOptions);
    }
 
Example 2
Source File: VertxNetUtils.java    From Lealone-Plugins with Apache License 2.0 6 votes vote down vote up
public static Vertx getVertx(Map<String, String> config) {
    if (vertx == null) {
        synchronized (VertxNetUtils.class) {
            if (vertx == null) {
                Integer blockedThreadCheckInterval = Integer.MAX_VALUE;
                if (config.containsKey("blocked_thread_check_interval")) {
                    blockedThreadCheckInterval = Integer.parseInt(config.get("blocked_thread_check_interval"));
                    if (blockedThreadCheckInterval <= 0)
                        blockedThreadCheckInterval = Integer.MAX_VALUE;
                }
                VertxOptions opt = new VertxOptions();
                opt.setBlockedThreadCheckInterval(blockedThreadCheckInterval);
                vertx = Vertx.vertx(opt);
            }
        }
    }
    return vertx;
}
 
Example 3
Source File: DockerTest.java    From okapi with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp(TestContext context) {
  Async async = context.async();
  VertxOptions options = new VertxOptions();
  options.setBlockedThreadCheckInterval(60000); // in ms
  options.setWarningExceptionTime(60000); // in ms
  options.setPreferNativeTransport(true);
  vertx = Vertx.vertx(options);
  RestAssured.port = port;
  client = vertx.createHttpClient();

  checkDocker(res -> {
    haveDocker = res.succeeded();
    if (res.succeeded()) {
      dockerImages = res.result();
      logger.info("Docker found");
    } else {
      logger.warn("No docker: " + res.cause().getMessage());
    }
    DeploymentOptions opt = new DeploymentOptions()
      .setConfig(new JsonObject()
        .put("containerHost", "localhost")
        .put("port", Integer.toString(port))
        .put("port_start", Integer.toString(port + 4))
        .put("port_end", Integer.toString(port + 6)));

    vertx.deployVerticle(MainVerticle.class.getName(),
      opt, x -> async.complete());
  });
}
 
Example 4
Source File: RestLauncher.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeStartingVertx(VertxOptions options) {
  // TODO Auto-generated method stub
  super.beforeStartingVertx(options);

  System.out.println("starting rest verticle service..........");
  options.setBlockedThreadCheckInterval(1500000);
  options.setWarningExceptionTime(1500000);
  boolean enabled = options.getMetricsOptions().isEnabled();
  options.setMetricsOptions(new DropwizardMetricsOptions().setEnabled(enabled).addMonitoredHttpServerUri(
      new Match().setValue("/.*").setType(MatchType.REGEX)));
}
 
Example 5
Source File: HttpServer.java    From Lealone-Plugins with Apache License 2.0 5 votes vote down vote up
private void startVertxHttpServer() {
    if (apiPath == null)
        apiPath = "/_lealone_sockjs_/*";
    final String path = apiPath;
    VertxOptions opt = new VertxOptions();
    opt.setBlockedThreadCheckInterval(Integer.MAX_VALUE);
    vertx = Vertx.vertx(opt);
    vertxHttpServer = vertx.createHttpServer();
    Router router = Router.router(vertx);

    String syncRequestUrl = "/_lealone_sync_request_";
    router.post(syncRequestUrl).handler(BodyHandler.create());
    router.post(syncRequestUrl).handler(routingContext -> {
        String command = routingContext.request().params().get("command");
        Buffer result = ServiceHandler.handle(routingContext, command);
        routingContext.request().response().headers().set("Access-Control-Allow-Origin", "*");
        routingContext.request().response().end(result);
    });

    router.route().handler(CorsHandler.create("*").allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.POST));
    setSockJSHandler(router);
    // 放在最后
    setStaticHandler(router);

    vertxHttpServer.requestHandler(router::handle).listen(port, host, res -> {
        if (res.succeeded()) {
            logger.info("web root: " + webRoot);
            logger.info("sockjs path: " + path);
            logger.info("http server is now listening on port: " + vertxHttpServer.actualPort());
        } else {
            logger.error("failed to bind " + port + " port!", res.cause());
        }
    });
}
 
Example 6
Source File: VertxProperties.java    From vertx-spring-boot with Apache License 2.0 4 votes vote down vote up
public VertxOptions toVertxOptions() {
    VertxOptions vertxOptions = new VertxOptions();
    vertxOptions.setEventLoopPoolSize(eventLoopPoolSize);
    vertxOptions.setWorkerPoolSize(workerPoolSize);
    vertxOptions.setInternalBlockingPoolSize(internalBlockingPoolSize);
    vertxOptions.setBlockedThreadCheckInterval(blockedThreadCheckInterval);
    vertxOptions.setMaxEventLoopExecuteTime(maxEventLoopExecuteTime);
    vertxOptions.setMaxWorkerExecuteTime(maxWorkerExecuteTime);
    vertxOptions.setHAEnabled(haEnabled);
    vertxOptions.setQuorumSize(quorumSize);
    vertxOptions.setHAGroup(haGroup);
    vertxOptions.setWarningExceptionTime(warningExceptionTime);
    vertxOptions.setPreferNativeTransport(preferNativeTransport);
    vertxOptions.setMaxEventLoopExecuteTimeUnit(maxEventLoopExecuteTimeUnit);
    vertxOptions.setMaxWorkerExecuteTimeUnit(maxWorkerExecuteTimeUnit);
    vertxOptions.setWarningExceptionTimeUnit(warningExceptionTimeUnit);
    vertxOptions.setBlockedThreadCheckIntervalUnit(blockedThreadCheckIntervalUnit);

    MetricsOptions metricsOptions = new MetricsOptions();
    metricsOptions.setEnabled(metricsEnabled);
    vertxOptions.setMetricsOptions(metricsOptions);

    FileSystemOptions fileSystemOptions = new FileSystemOptions();
    fileSystemOptions.setClassPathResolvingEnabled(fileSystem.isClassPathResolvingEnabled());
    fileSystemOptions.setFileCachingEnabled(fileSystem.isFileCachingEnabled());
    vertxOptions.setFileSystemOptions(fileSystemOptions);

    AddressResolverOptions addressResolverOptions = new AddressResolverOptions();
    addressResolverOptions.setHostsPath(addressResolver.getHostsPath());
    addressResolverOptions.setHostsValue(addressResolver.getHostsValue());
    addressResolverOptions.setServers(addressResolver.getServers());
    addressResolverOptions.setOptResourceEnabled(addressResolver.isOptResourceEnabled());
    addressResolverOptions.setCacheMinTimeToLive(addressResolver.getCacheMinTimeToLive());
    addressResolverOptions.setCacheMaxTimeToLive(addressResolver.getCacheMaxTimeToLive());
    addressResolverOptions.setCacheNegativeTimeToLive(addressResolver.getCacheNegativeTimeToLive());
    addressResolverOptions.setQueryTimeout(addressResolver.getQueryTimeout());
    addressResolverOptions.setMaxQueries(addressResolver.getMaxQueries());
    addressResolverOptions.setRdFlag(addressResolver.isRdFlag());
    addressResolverOptions.setSearchDomains(addressResolver.getSearchDomains());
    addressResolverOptions.setNdots(addressResolver.getNdots());
    addressResolverOptions.setRotateServers(addressResolver.isRotateServers());
    vertxOptions.setAddressResolverOptions(addressResolverOptions);

    return vertxOptions;
}
 
Example 7
Source File: VertxCoreRecorder.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private static VertxOptions convertToVertxOptions(VertxConfiguration conf, VertxOptions options, boolean allowClustering) {

        if (!conf.useAsyncDNS) {
            System.setProperty(ResolverProvider.DISABLE_DNS_RESOLVER_PROP_NAME, "true");
        }

        if (allowClustering) {
            // Order matters, as the cluster options modifies the event bus options.
            setEventBusOptions(conf, options);
            initializeClusterOptions(conf, options);
        }

        String fileCacheDir = System.getProperty(CACHE_DIR_BASE_PROP_NAME,
                System.getProperty("java.io.tmpdir", ".") + File.separator + "vertx-cache");

        options.setFileSystemOptions(new FileSystemOptions()
                .setFileCachingEnabled(conf.caching)
                .setFileCacheDir(fileCacheDir)
                .setClassPathResolvingEnabled(conf.classpathResolving));
        options.setWorkerPoolSize(conf.workerPoolSize);
        options.setInternalBlockingPoolSize(conf.internalBlockingPoolSize);

        options.setBlockedThreadCheckInterval(conf.warningExceptionTime.toMillis());
        if (conf.eventLoopsPoolSize.isPresent()) {
            options.setEventLoopPoolSize(conf.eventLoopsPoolSize.getAsInt());
        } else {
            options.setEventLoopPoolSize(calculateDefaultIOThreads());
        }

        Optional<Duration> maxEventLoopExecuteTime = conf.maxEventLoopExecuteTime;
        if (maxEventLoopExecuteTime.isPresent()) {
            options.setMaxEventLoopExecuteTime(maxEventLoopExecuteTime.get().toMillis());
            options.setMaxEventLoopExecuteTimeUnit(TimeUnit.MILLISECONDS);
        }

        Optional<Duration> maxWorkerExecuteTime = conf.maxWorkerExecuteTime;
        if (maxWorkerExecuteTime.isPresent()) {
            options.setMaxWorkerExecuteTime(maxWorkerExecuteTime.get().toMillis());
            options.setMaxWorkerExecuteTimeUnit(TimeUnit.MILLISECONDS);
        }

        options.setWarningExceptionTime(conf.warningExceptionTime.toNanos());

        options.setPreferNativeTransport(conf.preferNativeTransport);

        return options;
    }
 
Example 8
Source File: VxApiLauncher.java    From VX-API-Gateway with MIT License 4 votes vote down vote up
/**
 * 初始化vert.x的配置文件<br>
 * This method copy from the {@link io.vertx.core.VertxOptionsConverter}
 * fromJson
 * 
 * @param json
 * @param obj
 */
public void initVertxConfig(JsonObject json, VertxOptions obj) {

	if (json.getValue("addressResolverOptions") instanceof JsonObject) {
		obj.setAddressResolverOptions(new io.vertx.core.dns.AddressResolverOptions((JsonObject) json.getValue("addressResolverOptions")));
	}
	if (json.getValue("blockedThreadCheckInterval") instanceof Number) {
		obj.setBlockedThreadCheckInterval(((Number) json.getValue("blockedThreadCheckInterval")).longValue());
	}
	if (json.getValue("clusterHost") instanceof String) {
		obj.setClusterHost((String) json.getValue("clusterHost"));
	}
	if (json.getValue("clusterPingInterval") instanceof Number) {
		obj.setClusterPingInterval(((Number) json.getValue("clusterPingInterval")).longValue());
	}
	if (json.getValue("clusterPingReplyInterval") instanceof Number) {
		obj.setClusterPingReplyInterval(((Number) json.getValue("clusterPingReplyInterval")).longValue());
	}
	if (json.getValue("clusterPort") instanceof Number) {
		obj.setClusterPort(((Number) json.getValue("clusterPort")).intValue());
	}
	if (json.getValue("clusterPublicHost") instanceof String) {
		obj.setClusterPublicHost((String) json.getValue("clusterPublicHost"));
	}
	if (json.getValue("clusterPublicPort") instanceof Number) {
		obj.setClusterPublicPort(((Number) json.getValue("clusterPublicPort")).intValue());
	}
	if (json.getValue("clustered") instanceof Boolean) {
		obj.setClustered((Boolean) json.getValue("clustered"));
	}
	if (json.getValue("eventBusOptions") instanceof JsonObject) {
		obj.setEventBusOptions(new io.vertx.core.eventbus.EventBusOptions((JsonObject) json.getValue("eventBusOptions")));
	}
	if (json.getValue("eventLoopPoolSize") instanceof Number) {
		obj.setEventLoopPoolSize(((Number) json.getValue("eventLoopPoolSize")).intValue());
	}
	if (json.getValue("fileResolverCachingEnabled") instanceof Boolean) {
		obj.setFileResolverCachingEnabled((Boolean) json.getValue("fileResolverCachingEnabled"));
	}
	if (json.getValue("haEnabled") instanceof Boolean) {
		obj.setHAEnabled((Boolean) json.getValue("haEnabled"));
	}
	if (json.getValue("haGroup") instanceof String) {
		obj.setHAGroup((String) json.getValue("haGroup"));
	}
	if (json.getValue("internalBlockingPoolSize") instanceof Number) {
		obj.setInternalBlockingPoolSize(((Number) json.getValue("internalBlockingPoolSize")).intValue());
	}
	if (json.getValue("maxEventLoopExecuteTime") instanceof Number) {
		obj.setMaxEventLoopExecuteTime(((Number) json.getValue("maxEventLoopExecuteTime")).longValue());
	}
	if (json.getValue("maxWorkerExecuteTime") instanceof Number) {
		obj.setMaxWorkerExecuteTime(((Number) json.getValue("maxWorkerExecuteTime")).longValue());
	}
	if (json.getValue("metricsOptions") instanceof JsonObject) {
		obj.setMetricsOptions(new io.vertx.core.metrics.MetricsOptions((JsonObject) json.getValue("metricsOptions")));
	}
	if (json.getValue("preferNativeTransport") instanceof Boolean) {
		obj.setPreferNativeTransport((Boolean) json.getValue("preferNativeTransport"));
	}
	if (json.getValue("quorumSize") instanceof Number) {
		obj.setQuorumSize(((Number) json.getValue("quorumSize")).intValue());
	}
	if (json.getValue("warningExceptionTime") instanceof Number) {
		obj.setWarningExceptionTime(((Number) json.getValue("warningExceptionTime")).longValue());
	}
	if (json.getValue("workerPoolSize") instanceof Number) {
		obj.setWorkerPoolSize(((Number) json.getValue("workerPoolSize")).intValue());
	}

}