use of io.vertx.core.DeploymentOptions in project vert.x by eclipse.
the class HAManager method processFailover.
// Process the failover of a deployment
private void processFailover(JsonObject failedVerticle) {
if (failDuringFailover) {
throw new VertxException("Oops!");
}
// This method must block until the failover is complete - i.e. the verticle is successfully redeployed
final String verticleName = failedVerticle.getString("verticle_name");
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> err = new AtomicReference<>();
// Now deploy this verticle on this node
ContextImpl ctx = vertx.getContext();
if (ctx != null) {
// We could be on main thread in which case we don't want to overwrite tccl
ContextImpl.setContext(null);
}
JsonObject options = failedVerticle.getJsonObject("options");
try {
doDeployVerticle(verticleName, new DeploymentOptions(options), result -> {
if (result.succeeded()) {
log.info("Successfully redeployed verticle " + verticleName + " after failover");
} else {
log.error("Failed to redeploy verticle after failover", result.cause());
err.set(result.cause());
}
latch.countDown();
Throwable t = err.get();
if (t != null) {
throw new VertxException(t);
}
});
} finally {
if (ctx != null) {
ContextImpl.setContext(ctx);
}
}
try {
if (!latch.await(120, TimeUnit.SECONDS)) {
throw new VertxException("Timed out waiting for redeploy on failover");
}
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
use of io.vertx.core.DeploymentOptions in project vert.x by eclipse.
the class NetExamples method example12.
public void example12(Vertx vertx) {
DeploymentOptions options = new DeploymentOptions().setInstances(10);
vertx.deployVerticle("com.mycompany.MyVerticle", options);
}
use of io.vertx.core.DeploymentOptions in project vert.x by eclipse.
the class EventBusTestBase method testNoHandlersCallbackContext.
@Test
public void testNoHandlersCallbackContext() {
startNodes(2);
waitFor(4);
// On an "external" thread
vertices[0].eventBus().send("blah", "blah", ar -> {
assertTrue(ar.failed());
if (ar.cause() instanceof ReplyException) {
ReplyException cause = (ReplyException) ar.cause();
assertSame(ReplyFailure.NO_HANDLERS, cause.failureType());
} else {
fail(ar.cause());
}
assertTrue("Not an EL thread", Context.isOnEventLoopThread());
complete();
});
// On a EL context
vertices[0].runOnContext(v -> {
Context ctx = vertices[0].getOrCreateContext();
vertices[0].eventBus().send("blah", "blah", ar -> {
assertTrue(ar.failed());
if (ar.cause() instanceof ReplyException) {
ReplyException cause = (ReplyException) ar.cause();
assertSame(ReplyFailure.NO_HANDLERS, cause.failureType());
} else {
fail(ar.cause());
}
assertSame(ctx, vertices[0].getOrCreateContext());
complete();
});
});
// On a Worker context
vertices[0].deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
Context ctx = getVertx().getOrCreateContext();
vertices[0].eventBus().send("blah", "blah", ar -> {
assertTrue(ar.failed());
if (ar.cause() instanceof ReplyException) {
ReplyException cause = (ReplyException) ar.cause();
assertSame(ReplyFailure.NO_HANDLERS, cause.failureType());
} else {
fail(ar.cause());
}
assertSame(ctx, getVertx().getOrCreateContext());
complete();
});
}
}, new DeploymentOptions().setWorker(true));
// Inside executeBlocking
vertices[0].executeBlocking(fut -> {
vertices[0].eventBus().send("blah", "blah", ar -> {
assertTrue(ar.failed());
if (ar.cause() instanceof ReplyException) {
ReplyException cause = (ReplyException) ar.cause();
assertSame(ReplyFailure.NO_HANDLERS, cause.failureType());
} else {
fail(ar.cause());
}
assertTrue("Not an EL thread", Context.isOnEventLoopThread());
complete();
});
fut.complete();
}, false, null);
await();
}
use of io.vertx.core.DeploymentOptions in project vert.x by eclipse.
the class EventBusTestBase method testReplyFromWorker.
@Test
public void testReplyFromWorker() throws Exception {
String expectedBody = TestUtils.randomAlphaString(20);
startNodes(2);
CountDownLatch latch = new CountDownLatch(1);
vertices[0].deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
vertices[1].eventBus().<String>consumer(ADDRESS1, msg -> {
msg.reply(expectedBody);
}).completionHandler(ar -> {
assertTrue(ar.succeeded());
latch.countDown();
});
}
}, new DeploymentOptions().setWorker(true));
awaitLatch(latch);
vertices[0].eventBus().send(ADDRESS1, "whatever", reply -> {
assertTrue(reply.succeeded());
assertEquals(expectedBody, reply.result().body());
testComplete();
});
await();
}
use of io.vertx.core.DeploymentOptions in project vert.x by eclipse.
the class DatagramTest method testUseInMultithreadedWorker.
@Test
public void testUseInMultithreadedWorker() throws Exception {
class MyVerticle extends AbstractVerticle {
@Override
public void start() {
assertIllegalStateException(() -> peer1 = vertx.createDatagramSocket(new DatagramSocketOptions()));
testComplete();
}
}
MyVerticle verticle = new MyVerticle();
vertx.deployVerticle(verticle, new DeploymentOptions().setWorker(true).setMultiThreaded(true));
await();
}
Aggregations