use of io.vertx.core.spi.VerticleFactory in project vert.x by eclipse.
the class DeploymentManager method doDeployVerticle.
private void doDeployVerticle(Iterator<VerticleFactory> iter, Throwable prevErr, String identifier, String deploymentID, DeploymentOptions options, ContextImpl parentContext, ContextImpl callingContext, ClassLoader cl, Handler<AsyncResult<String>> completionHandler) {
if (iter.hasNext()) {
VerticleFactory verticleFactory = iter.next();
Future<String> fut = Future.future();
if (verticleFactory.requiresResolve()) {
try {
verticleFactory.resolve(identifier, options, cl, fut);
} catch (Exception e) {
try {
fut.fail(e);
} catch (Exception ignore) {
// Too late
}
}
} else {
fut.complete(identifier);
}
fut.setHandler(ar -> {
Throwable err;
if (ar.succeeded()) {
String resolvedName = ar.result();
if (!resolvedName.equals(identifier)) {
deployVerticle(resolvedName, options, completionHandler);
return;
} else {
if (verticleFactory.blockingCreate()) {
vertx.<Verticle[]>executeBlocking(createFut -> {
try {
Verticle[] verticles = createVerticles(verticleFactory, identifier, options.getInstances(), cl);
createFut.complete(verticles);
} catch (Exception e) {
createFut.fail(e);
}
}, res -> {
if (res.succeeded()) {
doDeploy(identifier, deploymentID, options, parentContext, callingContext, completionHandler, cl, res.result());
} else {
doDeployVerticle(iter, res.cause(), identifier, deploymentID, options, parentContext, callingContext, cl, completionHandler);
}
});
return;
} else {
try {
Verticle[] verticles = createVerticles(verticleFactory, identifier, options.getInstances(), cl);
doDeploy(identifier, deploymentID, options, parentContext, callingContext, completionHandler, cl, verticles);
return;
} catch (Exception e) {
err = e;
}
}
}
} else {
err = ar.cause();
}
doDeployVerticle(iter, err, identifier, deploymentID, options, parentContext, callingContext, cl, completionHandler);
});
} else {
if (prevErr != null) {
// Report failure if there are no more factories to try otherwise try the next one
reportFailure(prevErr, callingContext, completionHandler);
} else {
// not handled or impossible ?
}
}
}
use of io.vertx.core.spi.VerticleFactory in project vert.x by eclipse.
the class VerticleFactoryTest method testUnregisterNoFact.
@Test
public void testUnregisterNoFact() {
VerticleFactory fact1 = new TestVerticleFactory("foo");
try {
vertx.unregisterVerticleFactory(fact1);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
}
use of io.vertx.core.spi.VerticleFactory in project vert.x by eclipse.
the class VerticleFactoryTest method testRegister.
@Test
public void testRegister() {
assertTrue(vertx.verticleFactories().isEmpty());
VerticleFactory fact1 = new TestVerticleFactory("foo");
vertx.registerVerticleFactory(fact1);
assertEquals(1, vertx.verticleFactories().size());
assertTrue(vertx.verticleFactories().contains(fact1));
}
use of io.vertx.core.spi.VerticleFactory in project vert.x by eclipse.
the class VerticleFactoryTest method testRegisterTwice.
@Test
public void testRegisterTwice() {
VerticleFactory fact1 = new TestVerticleFactory("foo");
vertx.registerVerticleFactory(fact1);
try {
vertx.registerVerticleFactory(fact1);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
}
use of io.vertx.core.spi.VerticleFactory in project vert.x by eclipse.
the class AccessEventBusFromInitVerticleFactoryTest method testLoadFactoryThatCheckEventBusAndSharedDataForNull.
@Test
public void testLoadFactoryThatCheckEventBusAndSharedDataForNull() {
assertEquals(2, vertx.verticleFactories().size());
boolean found = false;
for (VerticleFactory fact : vertx.verticleFactories()) {
if (fact instanceof AccessEventBusFromInitVerticleFactory) {
found = true;
}
}
assertTrue(found);
}
Aggregations