io.quarkus.runtime.StartupEvent Java Examples

The following examples show how to use io.quarkus.runtime.StartupEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JPADatabaseManager.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
void onStart(@Observes StartupEvent event) {

        log.info("JPA storage is starting...");

        dsUrl.ifPresent(x -> log.debug("Datasource URL: " + x));
        dsUrl.orElseThrow(() -> new IllegalStateException("Datasource URL missing!"));

        if (!dsUser.isPresent()) {
            log.warn("Datasource username is missing.");
        }
        if (!dsPassword.isPresent()) {
            log.warn("Datasource password is missing.");
        }
    }
 
Example #2
Source File: VerticleWithClassNameDeploymentTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void init(@Observes StartupEvent ev) throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    vertx.deployVerticle(MyVerticle.class.getName(),
            new DeploymentOptions().setInstances(2),
            ar -> latch.countDown());
    latch.await();
}
 
Example #3
Source File: VerticleWithInstanceDeploymentTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void init(@Observes StartupEvent ev) throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(2);
    vertx.deployVerticle(new MyVerticle(),
            ar -> latch.countDown());
    vertx.deployVerticle(new MyVerticle(),
            ar -> latch.countDown());
    latch.await();
}
 
Example #4
Source File: VerticleDeployer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void init(@Observes StartupEvent ev) {
    CountDownLatch latch = new CountDownLatch(5);
    vertx.deployVerticle(BareVerticle::new, new DeploymentOptions().setConfig(new JsonObject()
            .put("id", "bare")))
            .thenAccept(x -> latch.countDown());

    vertx.deployVerticle(BareVerticle.class.getName(), new DeploymentOptions().setConfig(new JsonObject()
            .put("id", "bare-classname")))
            .thenAccept(x -> latch.countDown());

    vertx.deployVerticle(RxVerticle::new, new DeploymentOptions().setConfig(new JsonObject()
            .put("id", "rx")))
            .thenAccept(x -> latch.countDown());

    vertx.deployVerticle(RxVerticle.class.getName(), new DeploymentOptions().setConfig(new JsonObject()
            .put("id", "rx-classname")))
            .thenAccept(x -> latch.countDown());

    vertx.deployVerticle(MutinyAsyncVerticle::new, new DeploymentOptions().setConfig(new JsonObject()
            .put("id", "mutiny")))
            .thenAccept(x -> latch.countDown());

    vertx.deployVerticle(MutinyAsyncVerticle.class.getName(), new DeploymentOptions().setConfig(new JsonObject()
            .put("id", "mutiny-classname")))
            .thenAccept(x -> latch.countDown());
    latch.countDown();
}
 
Example #5
Source File: VertxInjectionTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void init(@Observes StartupEvent ev) {
    Assertions.assertNotNull(vertx);
    Assertions.assertNotNull(axle);
    Assertions.assertNotNull(rx);
    Assertions.assertNotNull(mutiny);
    ok = true;
}
 
Example #6
Source File: ProxyTestEndpoint.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Transactional
public void setup(@Observes StartupEvent startupEvent) {
    Pet pet = new Pet();
    pet.setId(1);
    pet.setName("Goose");

    PetOwner petOwner = new PetOwner();
    petOwner.setId(1);
    petOwner.setName("Stuart");
    petOwner.setPet(pet);

    entityManager.persist(petOwner);

    pet = new Cat();
    pet.setId(2);
    pet.setName("Tiddles");

    petOwner = new PetOwner();
    petOwner.setId(2);
    petOwner.setName("Sanne");
    petOwner.setPet(pet);

    entityManager.persist(petOwner);

    pet = new Dog();
    pet.setId(3);
    pet.setName("Spot");
    ((Dog) pet).setFavoriteToy("Rubber Bone");

    petOwner = new PetOwner();
    petOwner.setId(3);
    petOwner.setName("Emmanuel");
    petOwner.setPet(pet);

    entityManager.persist(petOwner);

}
 
Example #7
Source File: VertxInjectionTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void init(@Observes StartupEvent ev) {
    Assertions.assertNotNull(vertx);
    Assertions.assertNotNull(axle);
    Assertions.assertNotNull(rx);
    Assertions.assertNotNull(mutiny);
    ok = true;
}
 
Example #8
Source File: AppLifecycleBean.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
void onStart(@Observes StartupEvent ev) {
    LOGGER.info("The application is starting...");
    FlowRule rule = new FlowRule()
            .setCount(1)
            .setGrade(RuleConstant.FLOW_GRADE_QPS)
            .setResource("GET:/hello/txt")
            .setLimitApp("default")
            .as(FlowRule.class);
    FlowRuleManager.loadRules(Arrays.asList(rule));

    SystemRule systemRule = new SystemRule();
    systemRule.setLimitApp("default");
    systemRule.setAvgRt(3000);
    SystemRuleManager.loadRules(Arrays.asList(systemRule));

    DegradeRule degradeRule1 = new DegradeRule("greeting1")
            .setCount(1)
            .setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
            .setTimeWindow(10)
            .setMinRequestAmount(1);

    DegradeRule degradeRule2 = new DegradeRule("greeting2")
            .setCount(1)
            .setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
            .setTimeWindow(10)
            .setMinRequestAmount(1);
    DegradeRuleManager.loadRules(Arrays.asList(degradeRule1, degradeRule2));
}
 
Example #9
Source File: SparkOperatorEntrypoint.java    From spark-operator with Apache License 2.0 5 votes vote down vote up
public void onStart(@Observes StartupEvent event) {
    log.info("onStart..");
    try {
        exposeMetrics();
    } catch (Exception e) {
        // ignore, not critical (service may have been already exposed)
        log.warn("Unable to expose the metrics, cause: {}", e.getMessage());
    }
}
 
Example #10
Source File: VertxEventBusProducer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void register(@Observes StartupEvent ev) {
    // Don't use rc.vertx() as it would be the RestEasy instance
    router.get("/").handler(rc -> vertx.eventBus().<String> request("my-address", "", m -> {
        if (m.failed()) {
            rc.response().end("failed");
        } else {
            rc.response().end(m.result().body());
        }
    }));
}
 
Example #11
Source File: Startup.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@Transactional
public void loadUsers(@Observes StartupEvent evt) {
    // reset and load all test users
    User.deleteAll();
    User.add("admin", "admin", "admin");
    User.add("user", "user", "user");
}
 
Example #12
Source File: ArcEndpointTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testBeans() {
    String debugPath = RestAssured.get("/console-path").asString();
    JsonArray beans = new JsonArray(RestAssured.get(debugPath + "/arc/beans").asString());
    JsonArray observers = new JsonArray(RestAssured.get(debugPath + "/arc/observers").asString());
    JsonObject fooBean = null;
    JsonObject fooObserver = null;
    for (int i = 0; i < beans.size(); i++) {
        JsonObject bean = beans.getJsonObject(i);
        if (bean.getString("beanClass").equals(Foo.class.getName())) {
            fooBean = bean;
        }
    }
    assertNotNull(fooBean);
    assertEquals(ApplicationScoped.class.getName(), fooBean.getString("scope"));
    assertEquals("CLASS", fooBean.getString("kind"));
    assertEquals("foo", fooBean.getString("name"));
    String beanId = fooBean.getString("id");
    assertNotNull(beanId);

    for (int i = 0; i < observers.size(); i++) {
        JsonObject observer = observers.getJsonObject(i);
        if (beanId.equals(observer.getString("declaringBean"))
                && StartupEvent.class.getName().equals(observer.getString("observedType"))) {
            fooObserver = observer;
            assertEquals(2500, fooObserver.getInteger("priority"));
        }
    }
    assertNotNull(fooObserver);
}
 
Example #13
Source File: InjectQuartzSchedulerTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
void onStart(@Observes StartupEvent event, Scheduler quartz) throws SchedulerException {
    JobDetail job = JobBuilder.newJob(Starter.class)
            .withIdentity("myJob", "myGroup")
            .build();
    Trigger trigger = TriggerBuilder.newTrigger()
            .withIdentity("myTrigger", "myGroup")
            .startNow()
            .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                    .withIntervalInSeconds(1)
                    .repeatForever())
            .build();
    quartz.scheduleJob(job, trigger);
}
 
Example #14
Source File: QuartzScheduler.java    From quarkus with Apache License 2.0 5 votes vote down vote up
void start(@Observes @Priority(Interceptor.Priority.PLATFORM_BEFORE) StartupEvent startupEvent) {
    if (scheduler == null) {
        return;
    }
    try {
        scheduler.start();
    } catch (SchedulerException e) {
        throw new IllegalStateException("Unable to start Scheduler", e);
    }
}
 
Example #15
Source File: SDKEntrypoint.java    From abstract-operator with Apache License 2.0 5 votes vote down vote up
public void onStart(@Observes StartupEvent event) {
    log.info("Starting..");
    CompletableFuture<Void> future = run().exceptionally(ex -> {
        log.error("Unable to start operator for one or more namespaces", ex);
        System.exit(1);
        return null;
    });
    if (config.isMetrics()) {
        CompletableFuture<Optional<HTTPServer>> maybeMetricServer = future.thenCompose(s -> runMetrics());
    }
}
 
Example #16
Source File: LibraryResource.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@Transactional
void onStart(@Observes StartupEvent ev) throws InterruptedException {
    // only reindex if we imported some content
    if (Book.count() > 0) {
        Search.session(em)
                .massIndexer()
                .startAndWait();
    }
}
 
Example #17
Source File: SimpleScheduler.java    From quarkus with Apache License 2.0 5 votes vote down vote up
void start(@Observes @Priority(Interceptor.Priority.PLATFORM_BEFORE) StartupEvent event) {
    if (scheduledExecutor == null) {
        return;
    }
    // Try to compute the initial delay to execute the checks near to the whole second
    // Note that this does not guarantee anything, it's just best effort
    LocalDateTime now = LocalDateTime.now();
    LocalDateTime trunc = now.plusSeconds(1).truncatedTo(ChronoUnit.SECONDS);
    scheduledExecutor.scheduleAtFixedRate(this::checkTriggers, ChronoUnit.MILLIS.between(now, trunc), CHECK_PERIOD,
            TimeUnit.MILLISECONDS);
}
 
Example #18
Source File: SmallRyeReactiveMessagingLifecycle.java    From quarkus with Apache License 2.0 5 votes vote down vote up
void onApplicationStart(@Observes @Priority(javax.interceptor.Interceptor.Priority.LIBRARY_BEFORE) StartupEvent event) {
    try {
        mediatorManager.initializeAndRun();
    } catch (Exception e) {
        throw new DeploymentException(e);
    }
}
 
Example #19
Source File: VerticleDeployer.java    From quarkus with Apache License 2.0 4 votes vote down vote up
void deploy(@Observes StartupEvent event, MyBeanVerticle verticle, MyUndeployedVerticle undeployedVerticle) {
    vertx.deployVerticle(verticle).await().indefinitely();
    deploymentId = vertx.deployVerticle(undeployedVerticle).await().indefinitely();
}
 
Example #20
Source File: LifecycleEventRunner.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void fireStartupEvent() {
    startup.fire(new StartupEvent());
}
 
Example #21
Source File: VertxInjectionTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void init(@Observes StartupEvent ev) {
    Assertions.assertNotNull(vertx);
    ok = true;
}
 
Example #22
Source File: TestServlet.java    From quarkus with Apache License 2.0 4 votes vote down vote up
void onStart(@Observes StartupEvent ev) {
    log.info("The application is starting...");
}
 
Example #23
Source File: ClientResource.java    From hibernate-demos with Apache License 2.0 4 votes vote down vote up
@Transactional(TxType.NEVER)
void reindexOnStart(@Observes StartupEvent event) throws InterruptedException {
	if ( "dev".equals( ProfileManager.getActiveProfile() ) ) {
		reindex();
	}
}
 
Example #24
Source File: SomeSink.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void init(@Observes StartupEvent event) {
    router.get("/").handler(rc -> rc.response().end(items.encode()));
}
 
Example #25
Source File: UserRouteRegistrationTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void register(@Observes StartupEvent ignored) {
    router.route("/inject").handler(rc -> rc.response().end("inject - ok"));
    router.route().failureHandler(rc -> rc.failure().printStackTrace());
    router.route("/body").consumes("text/plain").handler(BodyHandler.create())
            .handler(rc -> rc.response().end(rc.getBodyAsString()));
}
 
Example #26
Source File: VertxEventBusConsumer.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void init(@Observes StartupEvent event) {
    vertx.eventBus().consumer("my-address", m -> m.reply("hello"));
}
 
Example #27
Source File: ArcEndpointTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
void onStart(@Observes StartupEvent event) {
}
 
Example #28
Source File: NewBean.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void register(@Observes StartupEvent ev) {
    router.get("/bean").handler(rc -> rc.response().end(message));
}
 
Example #29
Source File: DevBean.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void register(@Observes StartupEvent ev) {
    router.get("/dev").handler(rc -> rc.response().end(message));
}
 
Example #30
Source File: SimpleBean.java    From quarkus with Apache License 2.0 4 votes vote down vote up
void onStart(@Observes StartupEvent event) {
    startupEvent.set(event);
}