本文整理了Java中io.vertx.core.VertxOptions
类的一些代码示例,展示了VertxOptions
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。VertxOptions
类的具体详情如下:
包路径:io.vertx.core.VertxOptions
类名称:VertxOptions
[英]Instances of this class are used to configure io.vertx.core.Vertx instances.
[中]此类的实例用于配置io。维特斯。果心Vertx实例。
代码示例来源:origin: eclipse-vertx/vert.x
options = new VertxOptions().setMetricsOptions(metricsOptions);
configureFromSystemProperties(options, VERTX_OPTIONS_PROP_PREFIX);
if (clustered) {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<AsyncResult<Vertx>> result = new AtomicReference<>();
options.setClusterHost(clusterHost).setClusterPort(clusterPort).setClustered(true);
if (ha) {
String haGroup = args.map.get("-hagroup");
int quorumSize = args.getInt("-quorum");
options.setHAEnabled(true);
if (haGroup != null) {
options.setHAGroup(haGroup);
options.setQuorumSize(quorumSize);
return null;
if (result.get().failed()) {
log.error("Failed to form cluster");
result.get().cause().printStackTrace();
return null;
vertx = result.get().result();
} else {
beforeStartingVertx(options);
vertx = Vertx.vertx(options);
代码示例来源:origin: vert-x3/vertx-examples
public static void runExample(String exampleDir, String verticleID, VertxOptions options, DeploymentOptions deploymentOptions) {
if (options == null) {
options = new VertxOptions();
try {
if (deploymentOptions != null) {
vertx.deployVerticle(verticleID, deploymentOptions);
} else {
vertx.deployVerticle(verticleID);
if (options.isClustered()) {
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
runner.accept(vertx);
} else {
res.cause().printStackTrace();
代码示例来源:origin: eclipse-vertx/vert.x
protected Vertx startVertx(String haGroup, int quorumSize, boolean ha) throws Exception {
VertxOptions options = new VertxOptions().setHAEnabled(ha).setClustered(true).
setClusterHost("localhost").setClusterManager(getClusterManager());
if (ha) {
options.setQuorumSize(quorumSize);
if (haGroup != null) {
options.setHAGroup(haGroup);
}
}
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Vertx> vertxRef = new AtomicReference<>();
clusteredVertx(options, onSuccess(vertx -> {
vertxRef.set(vertx);
latch.countDown();
}));
latch.await(2, TimeUnit.MINUTES);
return vertxRef.get();
}
代码示例来源:origin: vert-x3/vertx-examples
/**
* Specifies Vert.x instance configuration, this is essential for clustering on multiple separate machines and
* Docker containers in order to make Event Bus send/consume messages appropriately
* @param clusterManager represents the cluster manager
* @return VertxOptions object to be used in deployment
*/
private static VertxOptions configureVertx(ClusterManager clusterManager) {
/*
the default value of the cluster host (localhost) is used here, if we want to have multiple machines/docker
containers in our cluster we must configure the cluster host properly on each node in order for the event bus
to send/consume messages properly between our verticles, to do so we use the method setClusterHost and give it
this node's IP. For example:
options.setClusterHost(192.168.1.12);
*/
VertxOptions options = new VertxOptions()
.setClustered(true)
.setClusterManager(clusterManager);
return options;
}
}
代码示例来源:origin: eclipse-vertx/vert.x
protected VertxOptions getOptions() {
VertxOptions options = new VertxOptions();
options.setPreferNativeTransport(USE_NATIVE_TRANSPORT);
return options;
}
代码示例来源:origin: vert-x3/vertx-examples
public static void main(String[] args) {
Vertx.clusteredVertx(new VertxOptions().setClustered(true), ar -> {
if (ar.failed()) {
System.err.println("Cannot create vert.x instance : " + ar.cause());
} else {
Vertx vertx = ar.result();
vertx.deployVerticle(DisplayStatsApp.class.getName());
}
});
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testSearchDomainWithNdots2() throws Exception {
Map<String, String> records = new HashMap<>();
records.put("host1.sub.foo.com", "127.0.0.1");
records.put("host2.sub.foo.com", "127.0.0.2");
records.put("host2.sub", "127.0.0.3");
dnsServer.testResolveA(records);
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(
new AddressResolverOptions().
addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).
setOptResourceEnabled(false).
addSearchDomain("foo.com").
setNdots(2)
));
CountDownLatch latch1 = new CountDownLatch(1);
vertx.resolveAddress("host1.sub", onSuccess(resolved -> {
assertEquals("127.0.0.1", resolved.getHostAddress());
latch1.countDown();
}));
awaitLatch(latch1);
// "host2.sub" is resolved with the foo.com search domain as ndots = 2
CountDownLatch latch2 = new CountDownLatch(1);
vertx.resolveAddress("host2.sub", onSuccess(resolved -> {
assertEquals("127.0.0.2", resolved.getHostAddress());
latch2.countDown();
}));
awaitLatch(latch2);
}
代码示例来源:origin: eclipse-vertx/vert.x
protected void startNodes(int numNodes, VertxOptions options) {
CountDownLatch latch = new CountDownLatch(numNodes);
vertices = new Vertx[numNodes];
for (int i = 0; i < numNodes; i++) {
int index = i;
clusteredVertx(options.setClusterHost("localhost").setClusterPort(0).setClustered(true)
.setClusterManager(getClusterManager()), ar -> {
try {
if (ar.failed()) {
ar.cause().printStackTrace();
}
assertTrue("Failed to start node", ar.succeeded());
vertices[index] = ar.result();
}
finally {
latch.countDown();
}
});
}
try {
assertTrue(latch.await(2, TimeUnit.MINUTES));
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testResolveFromFile() {
File f = new File(new File(new File(new File("src"), "test"), "resources"), "hosts_config.txt");
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setHostsPath(f.getAbsolutePath())));
vertx.resolveAddress("server.net", onSuccess(addr -> {
assertEquals("192.168.0.15", addr.getHostAddress());
assertEquals("server.net", addr.getHostName());
testComplete();
}));
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
if (optionsJson == null) {
MetricsOptions metricsOptions = getMetricsOptions();
options = new VertxOptions().setMetricsOptions(metricsOptions);
} else {
MetricsOptions metricsOptions = getMetricsOptions(optionsJson.getJsonObject("metricsOptions"));
options = new VertxOptions(optionsJson).setMetricsOptions(metricsOptions);
if (isClustered()) {
log.info("Starting clustering...");
if (!Objects.equals(options.getClusterHost(), VertxOptions.DEFAULT_CLUSTER_HOST)) {
clusterHost = options.getClusterHost();
if (options.getClusterPort() != VertxOptions.DEFAULT_CLUSTER_PORT) {
clusterPort = options.getClusterPort();
if (!Objects.equals(options.getClusterPublicHost(), VertxOptions.DEFAULT_CLUSTER_PUBLIC_HOST)) {
clusterPublicHost = options.getClusterPublicHost();
if (options.getClusterPublicPort() != VertxOptions.DEFAULT_CLUSTER_PUBLIC_PORT) {
clusterPublicPort = options.getClusterPublicPort();
options.setClustered(true)
.setClusterHost(clusterHost).setClusterPort(clusterPort)
.setClusterPublicHost(clusterPublicHost);
if (clusterPublicPort != -1) {
options.setClusterPublicPort(clusterPublicPort);
options.setHAEnabled(true);
if (haGroup != null) {
代码示例来源:origin: eclipse-vertx/vert.x
CountDownLatch latch = new CountDownLatch(1);
Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
Context ctx = contextFactory.apply(vertx);
ctx.runOnContext(v1 -> {
HttpServer server = vertx.createHttpServer().websocketHandler(ws -> {
ws.handler(buf -> {
ws.write(Buffer.buffer("bye"));
server.listen(8080, "localhost", onSuccess(s -> {
expectedThread.set(Thread.currentThread());
expectedContext.set(Vertx.currentContext());
latch.countDown();
}));
});
awaitLatch(latch);
HttpClient client = vertx.createHttpClient();
client.websocket(8080, "localhost", "/", ws -> {
ws.handler(buf -> {
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCallbackInvokedOnFailure() throws Exception {
// will trigger java.net.UnknownHostException
String hostName = "zoom.zoom.zen.tld";
VertxOptions options = new VertxOptions()
.setClusterManager(new FakeClusterManager())
.setClusterHost(hostName);
AtomicReference<AsyncResult<Vertx>> resultRef = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
Vertx.clusteredVertx(options, ar -> {
resultRef.set(ar);
latch.countDown();
});
awaitLatch(latch);
assertFalse(resultRef.get() == null);
assertTrue(resultRef.get().failed());
assertTrue("Was expecting failure to be an instance of UnknownHostException", resultRef.get().cause() instanceof UnknownHostException);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
CountDownLatch latch = new CountDownLatch(1);
Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
Context ctx = contextFactory.apply(vertx);
ctx.runOnContext(v1 -> {
NetServer server = vertx.createNetServer().connectHandler(so -> {
so.handler(buf -> {
so.write("bye");
server.listen(1234, "localhost", onSuccess(s -> {
expectedThread.set(Thread.currentThread());
expectedContext.set(Vertx.currentContext());
checker.accept(expectedThread.get(), expectedContext.get());
latch.countDown();
}));
});
awaitLatch(latch);
NetClient client = vertx.createNetClient();
client.connect(1234, "localhost", onSuccess(so -> {
so.handler(buf -> {
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testResolveMissingLocalhost() throws Exception {
InetAddress localhost = InetAddress.getByName("localhost");
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(
new AddressResolverOptions().
addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).
setOptResourceEnabled(false)
));
CompletableFuture<Void> test1 = new CompletableFuture<>();
vertx.resolveAddress("localhost", ar -> {
if (ar.succeeded()) {
InetAddress resolved = ar.result();
if (resolved.equals(localhost)) {
test1.complete(null);
} else {
test1.completeExceptionally(ar.cause());
vertx.resolveAddress("LOCALHOST", ar -> {
if (ar.succeeded()) {
InetAddress resolved = ar.result();
NetServer server = vertx.createNetServer(new NetServerOptions().setPort(1234).setHost(localhost.getHostAddress()));
try {
server.connectHandler(so -> {
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testSimpleFailover() throws Exception {
startNodes(2, new VertxOptions().setHAEnabled(true));
DeploymentOptions options = new DeploymentOptions().setHa(true);
JsonObject config = new JsonObject().put("foo", "bar");
options.setConfig(config);
CountDownLatch latch = new CountDownLatch(1);
vertices[0].deployVerticle("java:" + HAVerticle1.class.getName(), options, ar -> {
assertTrue(ar.succeeded());
assertEquals(1, vertices[0].deploymentIDs().size());
assertEquals(0, vertices[1].deploymentIDs().size());
latch.countDown();
});
awaitLatch(latch);
kill(0);
assertWaitUntil(() -> vertices[1].deploymentIDs().size() == 1);
checkDeploymentExists(1, "java:" + HAVerticle1.class.getName(), options);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testNetSearchDomain() throws Exception {
Map<String, String> records = new HashMap<>();
records.put("host1.foo.com", "127.0.0.1");
dnsServer.testResolveA(records);
vertx.close();
vertx = vertx(new VertxOptions().setAddressResolverOptions(
new AddressResolverOptions().
setHostsValue(Buffer.buffer()).
setNdots(1).
addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).
setOptResourceEnabled(false).
addSearchDomain("foo.com")
));
testNet("host1");
}
代码示例来源:origin: eclipse-vertx/vert.x
AtomicBoolean bytesReadCalled = new AtomicBoolean();
AtomicBoolean bytesWrittenCalled = new AtomicBoolean();
CountDownLatch closeCalled = new CountDownLatch(1);
VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {
@Override
Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
Context ctx = contextFactory.apply(vertx);
ctx.runOnContext(v1 -> {
expectedThread.set(Thread.currentThread());
expectedContext.set(Vertx.currentContext());
DatagramSocket socket = vertx.createDatagramSocket();
socket.listen(1234, "localhost", ar1 -> {
assertTrue(ar1.succeeded());
checker.accept(expectedThread.get(), expectedContext.get());
socket.handler(packet -> {
});
socket.send(Buffer.buffer("msg"), 1234, "localhost", ar2 -> {
assertTrue(ar2.succeeded());
});
});
代码示例来源:origin: vert-x3/vertx-examples
@PostConstruct
void init() throws ExecutionException, InterruptedException {
VertxOptions options = new VertxOptions()
.setClusterManager(new HazelcastClusterManager(hazelcastInstance));
CompletableFuture<Vertx> future = new CompletableFuture<>();
Vertx.clusteredVertx(options, ar -> {
if (ar.succeeded()) {
future.complete(ar.result());
} else {
future.completeExceptionally(ar.cause());
}
});
vertx = future.get();
}
代码示例来源:origin: eclipse-vertx/vert.x
Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
assertTrue(ar1.succeeded());
vertx.undeploy(ar1.result(), ar2 -> {
assertTrue(ar1.succeeded());
assertTrue(deployedCalled.get());
assertTrue(undeployedCalled.get());
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCreateClusteredVertxAsync() {
VertxOptions options = new VertxOptions();
options.setClustered(true);
clusteredVertx(options, ar -> {
assertTrue(ar.succeeded());
assertNotNull(ar.result());
assertTrue(ar.result().isClustered());
Vertx v = ar.result();
v.close(ar2 -> {
assertTrue(ar2.succeeded());
testComplete();
});
});
await();
}
内容来源于网络,如有侵权,请联系作者删除!