use of io.vertx.core.eventbus.EventBusOptions in project vert.x by eclipse.
the class ConnectionHolder method schedulePing.
private void schedulePing() {
EventBusOptions options = eventBus.options();
pingTimeoutID = vertx.setTimer(options.getClusterPingInterval(), id1 -> {
// If we don't get a pong back in time we close the connection
timeoutID = vertx.setTimer(options.getClusterPingReplyInterval(), id2 -> {
// Didn't get pong in time - consider connection dead
log.warn("No pong from server " + remoteNodeId + " - will consider it dead");
close();
});
ClusteredMessage pingMessage = new ClusteredMessage<>(remoteNodeId, PING_ADDRESS, null, null, new PingMessageCodec(), true, eventBus);
Buffer data = pingMessage.encodeToWire();
socket.write(data);
});
}
use of io.vertx.core.eventbus.EventBusOptions in project vert.x by eclipse.
the class BareCommand method startVertx.
/**
* Starts the vert.x instance.
*
* @return the created instance of vert.x
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
protected Vertx startVertx() {
JsonObject optionsJson = getJsonFromFileOrString(vertxOptions, "options");
EventBusOptions eventBusOptions;
VertxBuilder builder;
if (optionsJson == null) {
eventBusOptions = getEventBusOptions();
builder = new VertxBuilder();
} else {
eventBusOptions = getEventBusOptions(optionsJson.getJsonObject("eventBusOptions"));
builder = new VertxBuilder(optionsJson);
}
options = builder.options();
options.setEventBusOptions(eventBusOptions);
beforeStartingVertx(options);
configureFromSystemProperties.set(log);
try {
configureFromSystemProperties(options, VERTX_OPTIONS_PROP_PREFIX);
if (options.getMetricsOptions() != null) {
configureFromSystemProperties(options.getMetricsOptions(), METRICS_OPTIONS_PROP_PREFIX);
}
builder.init();
} finally {
configureFromSystemProperties.set(null);
}
Vertx instance;
if (isClustered()) {
log.info("Starting clustering...");
eventBusOptions = options.getEventBusOptions();
if (!Objects.equals(eventBusOptions.getHost(), EventBusOptions.DEFAULT_CLUSTER_HOST)) {
clusterHost = eventBusOptions.getHost();
}
if (eventBusOptions.getPort() != EventBusOptions.DEFAULT_CLUSTER_PORT) {
clusterPort = eventBusOptions.getPort();
}
if (!Objects.equals(eventBusOptions.getClusterPublicHost(), EventBusOptions.DEFAULT_CLUSTER_PUBLIC_HOST)) {
clusterPublicHost = eventBusOptions.getClusterPublicHost();
}
if (eventBusOptions.getClusterPublicPort() != EventBusOptions.DEFAULT_CLUSTER_PUBLIC_PORT) {
clusterPublicPort = eventBusOptions.getClusterPublicPort();
}
eventBusOptions.setHost(clusterHost).setPort(clusterPort).setClusterPublicHost(clusterPublicHost);
if (clusterPublicPort != -1) {
eventBusOptions.setClusterPublicPort(clusterPublicPort);
}
if (getHA()) {
options.setHAEnabled(true);
if (haGroup != null) {
options.setHAGroup(haGroup);
}
if (quorum != -1) {
options.setQuorumSize(quorum);
}
}
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<AsyncResult<Vertx>> result = new AtomicReference<>();
create(builder, ar -> {
result.set(ar);
latch.countDown();
});
try {
if (!latch.await(2, TimeUnit.MINUTES)) {
log.error("Timed out in starting clustered Vert.x");
return null;
}
} catch (InterruptedException e) {
log.error("Thread interrupted in startup");
Thread.currentThread().interrupt();
return null;
}
if (result.get().failed()) {
log.error("Failed to form cluster", result.get().cause());
return null;
}
instance = result.get().result();
} else {
instance = create(builder);
}
addShutdownHook(instance, log, finalAction);
afterStartingVertx(instance);
return instance;
}
use of io.vertx.core.eventbus.EventBusOptions in project vert.x by eclipse.
the class BareCommand method getEventBusOptions.
/**
* @return the event bus options.
*/
protected EventBusOptions getEventBusOptions(JsonObject jsonObject) {
EventBusOptions eventBusOptions = jsonObject == null ? new EventBusOptions() : new EventBusOptions(jsonObject);
configureFromSystemProperties.set(log);
try {
configureFromSystemProperties(eventBusOptions, VERTX_EVENTBUS_PROP_PREFIX);
} finally {
configureFromSystemProperties.set(null);
}
return eventBusOptions;
}
use of io.vertx.core.eventbus.EventBusOptions in project vert.x by eclipse.
the class EventBusExamples method example13.
public void example13() {
VertxOptions options = new VertxOptions().setEventBusOptions(new EventBusOptions().setSsl(true).setKeyStoreOptions(new JksOptions().setPath("keystore.jks").setPassword("wibble")).setTrustStoreOptions(new JksOptions().setPath("keystore.jks").setPassword("wibble")).setClientAuth(ClientAuth.REQUIRED));
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
EventBus eventBus = vertx.eventBus();
System.out.println("We now have a clustered event bus: " + eventBus);
} else {
System.out.println("Failed: " + res.cause());
}
});
}
use of io.vertx.core.eventbus.EventBusOptions in project vert.x by eclipse.
the class EventBusExamples method example14.
public void example14() {
VertxOptions options = new VertxOptions().setEventBusOptions(new EventBusOptions().setClusterPublicHost("whatever").setClusterPublicPort(1234));
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
EventBus eventBus = vertx.eventBus();
System.out.println("We now have a clustered event bus: " + eventBus);
} else {
System.out.println("Failed: " + res.cause());
}
});
}
Aggregations