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

The following examples show how to use io.vertx.core.VertxOptions#setClustered() . 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: VxApiLauncher.java    From VX-API-Gateway with MIT License 6 votes vote down vote up
/**
 * 设置vert.x配置
 */
@Override
public void beforeStartingVertx(VertxOptions options) {
	try {
		byte[] bytes = Files.readAllBytes(PathUtil.getPath("conf.json"));
		Buffer buff = Buffer.buffer(bytes);
		// 总配置文件
		JsonObject conf = buff.toJsonObject();
		// vert.x配置文件
		JsonObject vertxc = conf.getJsonObject("vertx", getDefaultVertxConfig());
		initVertxConfig(vertxc, options);
		// 集群配置文件
		JsonObject clusterc = conf.getJsonObject("cluster", new JsonObject().put("clusterType", CLUSTER_TYPE));
		if (!CLUSTER_TYPE.equals(clusterc.getString("clusterType"))) {
			ClusterManager cmgr = VxApiClusterManagerFactory.getClusterManager(clusterc.getString("clusterType"),
					clusterc.getJsonObject("clusterConf", getDefaultClusterConfig()));
			options.setClusterManager(cmgr);
			options.setClustered(true);
		}
	} catch (IOException e) {
		throw new FileSystemException(e);
	}
}
 
Example 2
Source File: UsersReadFromMongo.java    From vxms with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

        VertxOptions vOpts = new VertxOptions();
        DeploymentOptions options = new DeploymentOptions().setInstances(1).setConfig(new JsonObject().put("local", true).put("etcdport", 4001).put("etcdhost", "127.0.0.1").put("exportedHost", "localhost"));

        vOpts.setClustered(true);
        Vertx.clusteredVertx(vOpts, cluster -> {
            if (cluster.succeeded()) {
                final Vertx result = cluster.result();
                result.deployVerticle(UsersReadFromMongo.class.getName(), options, handle -> {

                });
            }
        });

    }
 
Example 3
Source File: VxmsGateway.java    From kube_vertx_demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    DeploymentOptions options = new DeploymentOptions().setInstances(1).
            setConfig(new JsonObject().put("local", true).put("host", "0.0.0.0").put("port", 8181));
    VertxOptions vOpts = new VertxOptions();
    vOpts.setClustered(true);
    Vertx.clusteredVertx(vOpts, cluster -> {
        if (cluster.succeeded()) {
            final Vertx result = cluster.result();
            result.deployVerticle(VxmsGateway.class.getName(), options, handle -> {

            });
        }
    });

}
 
Example 4
Source File: Runner.java    From kube_vertx_demo with Apache License 2.0 5 votes vote down vote up
public static void run(DeploymentOptions options, Class clazz) {
    VertxOptions vOpts = new VertxOptions();
    vOpts.setClustered(true);
    Vertx.clusteredVertx(vOpts, cluster -> {
        if (cluster.succeeded()) {
            final Vertx result = cluster.result();
            result.deployVerticle(clazz.getName(), options, handle -> {

            });
        }
    });
}
 
Example 5
Source File: Runner.java    From vxms with Apache License 2.0 5 votes vote down vote up
public static void run(DeploymentOptions options, Class clazz) {
    VertxOptions vOpts = new VertxOptions();
    vOpts.setClustered(true);
    Vertx.clusteredVertx(vOpts, cluster -> {
        if (cluster.succeeded()) {
            final Vertx result = cluster.result();
            result.deployVerticle(clazz.getName(), options, handle -> {

            });
        }
    });
}
 
Example 6
Source File: UsersWriteToMongo.java    From vxms with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        VertxOptions vOpts = new VertxOptions();
        DeploymentOptions options = new DeploymentOptions().setInstances(1).setConfig(new JsonObject().put("local", true).put("etcdport", 4001).put("etcdhost", "127.0.0.1").put("exportedHost", "localhost"));

        vOpts.setClustered(true);
        Vertx.clusteredVertx(vOpts, cluster -> {
            if (cluster.succeeded()) {
                final Vertx result = cluster.result();
                result.deployVerticle(UsersWriteToMongo.class.getName(), options, handle -> {

                });
            }
        });
    }
 
Example 7
Source File: Runner.java    From vxms with Apache License 2.0 5 votes vote down vote up
public static void run(DeploymentOptions options, Class clazz) {
    VertxOptions vOpts = new VertxOptions();
    vOpts.setClustered(true);
    Vertx.clusteredVertx(vOpts, cluster -> {
        if (cluster.succeeded()) {
            final Vertx result = cluster.result();
            result.deployVerticle(clazz.getName(), options, handle -> {

            });
        }
    });
}
 
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());
	}

}