Search in sources :

Example 1 with VerticleFactory

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 ?
        }
    }
}
Also used : VerticleFactory(io.vertx.core.spi.VerticleFactory) MalformedURLException(java.net.MalformedURLException)

Example 2 with VerticleFactory

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
    }
}
Also used : VerticleFactory(io.vertx.core.spi.VerticleFactory) Test(org.junit.Test)

Example 3 with VerticleFactory

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));
}
Also used : VerticleFactory(io.vertx.core.spi.VerticleFactory) Test(org.junit.Test)

Example 4 with VerticleFactory

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
    }
}
Also used : VerticleFactory(io.vertx.core.spi.VerticleFactory) Test(org.junit.Test)

Example 5 with VerticleFactory

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);
}
Also used : VerticleFactory(io.vertx.core.spi.VerticleFactory) Test(org.junit.Test)

Aggregations

VerticleFactory (io.vertx.core.spi.VerticleFactory)21 Test (org.junit.Test)16 DeploymentOptions (io.vertx.core.DeploymentOptions)1 Vertx (io.vertx.core.Vertx)1 VertxTestBase (io.vertx.test.core.VertxTestBase)1 MalformedURLException (java.net.MalformedURLException)1 Callable (java.util.concurrent.Callable)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1