Java源码示例:io.quarkus.runtime.StartupEvent
示例1
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.");
}
}
示例2
@Transactional
void onStart(@Observes StartupEvent ev) throws InterruptedException {
// only reindex if we imported some content
if (Book.count() > 0) {
Search.session(em)
.massIndexer()
.startAndWait();
}
}
示例3
@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");
}
示例4
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());
}
}
示例5
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));
}
示例6
@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);
}
示例7
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();
}
示例8
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();
}
示例9
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();
}
示例10
public void init(@Observes StartupEvent ev) {
Assertions.assertNotNull(vertx);
Assertions.assertNotNull(axle);
Assertions.assertNotNull(rx);
Assertions.assertNotNull(mutiny);
ok = true;
}
示例11
public void init(@Observes StartupEvent ev) {
Assertions.assertNotNull(vertx);
Assertions.assertNotNull(axle);
Assertions.assertNotNull(rx);
Assertions.assertNotNull(mutiny);
ok = true;
}
示例12
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());
}
}));
}
示例13
@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);
}
示例14
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);
}
示例15
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);
}
}
示例16
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);
}
示例17
void onApplicationStart(@Observes @Priority(javax.interceptor.Interceptor.Priority.LIBRARY_BEFORE) StartupEvent event) {
try {
mediatorManager.initializeAndRun();
} catch (Exception e) {
throw new DeploymentException(e);
}
}
示例18
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());
}
}
示例19
public void init(@Observes StartupEvent event, ConnectorApplication app) {
app.start();
}
示例20
public void init(@Observes StartupEvent event, KafkaStreams streams) {
streams.start();
}
示例21
public void init(@Observes StartupEvent event, Lifecycle lifecycle) {
lifecycle.start();
}
示例22
public void init(@Observes StartupEvent event, ConsumerActions.DynamicAssignment<Cmmn.UUID, Str.StorageValue> container) {
container.start();
}
示例23
void onStart(@Observes StartupEvent ev) {
LOG.info("Attempting to override the kudu tablet server hostname resolution on application startup");
KuduInfrastructureTestHelper.overrideTabletServerHostnameResolution();
}
示例24
void onStart(@Observes StartupEvent event) {
System.out.printf("onStart, event=%s%n", event);
}
示例25
void onStart(@Observes StartupEvent event) {
System.out.printf("DemoRestApplication.onStart, event=%s%n", event);
}
示例26
public void onStartup(@Observes final StartupEvent ev) throws Exception {
log.info("Initializing camel routes.");
routesSetup.setup();
routesSetup.start();
}
示例27
public void onStartup(@Observes final StartupEvent ev) throws Exception {
log.info("Initializing camel routes.");
routesSetup.setup();
routesSetup.start();
}
示例28
void onStart(@Observes StartupEvent ev) {
LOGGER.info("Create or get cache named mycache with the default configuration");
RemoteCache<Object, Object> cache = cacheManager.administration().getOrCreateCache("mycache",
new XMLStringConfiguration(String.format(CACHE_CONFIG, "mycache")));
cache.put("hello", "Hello World, Infinispan is up!");
}
示例29
void onStart(@Observes StartupEvent ev) {
LOGGER.info("The application is starting...{}", bean.hello());
}
示例30
void onStart(@Observes StartupEvent ev) {
scheduler.scheduleWithFixedDelay(this, 0L, 5L, TimeUnit.SECONDS);
}