Skip to content

Commit

Permalink
fix(vertx): Fix blocking thread issues for vertx verticle (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt committed Jul 13, 2023
1 parent 4f7f147 commit 77f22d8
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import io.github.martinwitt.laughing_train.mining.requests.MineNextProject;
import io.github.martinwitt.laughing_train.mining.requests.StoreResults;
import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository;
import io.quarkus.vertx.ConsumeEvent;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.EventBus;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.ArrayList;
import java.util.List;

public class AnalyzerResultsPersistence {
@ApplicationScoped
public class AnalyzerResultsPersistence extends AbstractVerticle {

Check failure on line 18 in github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/AnalyzerResultsPersistence.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Incorrect managed bean definition

Managed bean must have a constructor with no parameters or a constructor annotated with @Inject

public static final String SERVICE_NAME = "analyzerResultsPersistence";
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
Expand All @@ -25,7 +27,11 @@ public AnalyzerResultsPersistence(ProjectRepository projectRepository, EventBus
this.eventBus = eventBus;
}

@ConsumeEvent(value = SERVICE_NAME, blocking = true)
@Override
public void start() throws Exception {
vertx.eventBus().<StoreResults>consumer(SERVICE_NAME, v -> persistResults(v.body()));
}

void persistResults(StoreResults storeResults) {
Project project = storeResults.project();
CodeAnalyzerResult result = storeResults.result();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,40 @@

import io.github.martinwitt.laughing_train.mining.requests.MineNextProject;
import io.quarkus.runtime.StartupEvent;
import io.vertx.mutiny.core.Vertx;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import java.util.concurrent.TimeUnit;

@ApplicationScoped
public class MiningStartup {

@Inject
Vertx vertx;

Check warning on line 16 in github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/MiningStartup.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Injection point with ambiguous dependencies

Unsatisfied dependency: no bean matches the injection point

@Inject
AnalyzerResultsPersistence persistence;

Check warning on line 19 in github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/MiningStartup.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Injection point with ambiguous dependencies

Unsatisfied dependency: no bean matches the injection point

@Inject
ProjectSupplier projectSupplier;

Check warning on line 22 in github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/MiningStartup.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Injection point with ambiguous dependencies

Unsatisfied dependency: no bean matches the injection point

@Inject
QodanaPeriodicMiner qodanaPeriodicMiner;

Check warning on line 25 in github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/MiningStartup.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Injection point with ambiguous dependencies

Unsatisfied dependency: no bean matches the injection point

@Inject
SpoonPeriodicMiner spoonPeriodicMiner;

Check warning on line 28 in github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/MiningStartup.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Injection point with ambiguous dependencies

Unsatisfied dependency: no bean matches the injection point

void startup(@Observes StartupEvent event) {
vertx.eventBus().send("miner", new MineNextProject(QodanaPeriodicMiner.ANALYZER_NAME));
vertx.eventBus().send("miner", new MineNextProject(SpoonPeriodicMiner.ANALYZER_NAME));
DeploymentOptions options = new DeploymentOptions().setWorker(true);
vertx.deployVerticle(qodanaPeriodicMiner, options);
vertx.deployVerticle(spoonPeriodicMiner, options);
vertx.deployVerticle(persistence, options);
vertx.deployVerticle(projectSupplier, options);
vertx.setTimer(TimeUnit.MINUTES.toMillis(1), v -> vertx.eventBus()
.send("miner", new MineNextProject(QodanaPeriodicMiner.ANALYZER_NAME)));
vertx.setTimer(TimeUnit.MINUTES.toMillis(1), v -> vertx.eventBus()
.send("miner", new MineNextProject(SpoonPeriodicMiner.ANALYZER_NAME)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,39 @@
import io.github.martinwitt.laughing_train.mining.requests.GetProject;
import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository;
import io.github.martinwitt.laughing_train.services.ProjectService;
import io.quarkus.vertx.ConsumeEvent;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
import java.util.Random;

public class ProjectSupplier {
@ApplicationScoped
public class ProjectSupplier extends AbstractVerticle {

Check failure on line 16 in github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/ProjectSupplier.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Incorrect managed bean definition

Managed bean must have a constructor with no parameters or a constructor annotated with @Inject

public static final String SERVICE_NAME = "projectSupplier";

final SearchProjectService searchProjectService;
final ProjectRepository projectRepository;
final ProjectService projectService;
private static final Random random = new Random();
final Vertx vertx;

ProjectSupplier(
SearchProjectService searchProjectService,
ProjectRepository projectRepository,
ProjectService projectService) {
ProjectService projectService,
Vertx vertx) {
this.searchProjectService = searchProjectService;
this.projectRepository = projectRepository;
this.projectService = projectService;
this.vertx = vertx;
}

@Override
public void start() throws Exception {
vertx.eventBus().<GetProject>consumer(SERVICE_NAME, v -> supplyProject(v.body()));
}

@ConsumeEvent(value = SERVICE_NAME, blocking = true)
ProjectResult supplyProject(GetProject getProject) {
try {
Project project = getRandomProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository;
import io.github.martinwitt.laughing_train.services.QodanaService;
import io.quarkus.arc.Unremovable;
import io.quarkus.vertx.ConsumeEvent;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.Message;
Expand All @@ -21,7 +21,7 @@

@Unremovable
@ApplicationScoped
public class QodanaPeriodicMiner {
public class QodanaPeriodicMiner extends AbstractVerticle {

Check failure on line 24 in github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/QodanaPeriodicMiner.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Incorrect managed bean definition

Managed bean must have a constructor with no parameters or a constructor annotated with @Inject

static final FluentLogger logger = FluentLogger.forEnclosingClass();
public static final String ANALYZER_NAME = "Qodana";
Expand Down Expand Up @@ -49,7 +49,11 @@ private void tryDeleteProject(ProjectResult.Success project) {
}
}

@ConsumeEvent(value = "miner", blocking = true)
@Override
public void start() throws Exception {
vertx.eventBus().<MineNextProject>consumer("miner", v -> mineWithQodana(v.body()));
}

void mineWithQodana(MineNextProject event) {
if (!event.analyzerName().equals(ANALYZER_NAME)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.github.martinwitt.laughing_train.mining.requests.StoreResults;
import io.github.martinwitt.laughing_train.services.SpoonAnalyzerService;
import io.quarkus.arc.Unremovable;
import io.quarkus.vertx.ConsumeEvent;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.Message;
Expand All @@ -20,7 +20,7 @@

@Unremovable
@ApplicationScoped
public class SpoonPeriodicMiner {
public class SpoonPeriodicMiner extends AbstractVerticle {

Check failure on line 23 in github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/SpoonPeriodicMiner.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Incorrect managed bean definition

Managed bean must have a constructor with no parameters or a constructor annotated with @Inject

static final FluentLogger logger = FluentLogger.forEnclosingClass();
public static final String ANALYZER_NAME = "spoon-analyzer";
Expand Down Expand Up @@ -48,7 +48,11 @@ private void tryDeleteProject(ProjectResult.Success project) {
}
}

@ConsumeEvent(value = "miner", blocking = true)
@Override
public void start() throws Exception {
vertx.eventBus().<MineNextProject>consumer("miner", v -> mineWithSpoon(v.body()));
}

void mineWithSpoon(MineNextProject event) {
if (!event.analyzerName().equals(ANALYZER_NAME)) {
return;
Expand Down
3 changes: 2 additions & 1 deletion github-bot/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ quarkus.mongodb.database=Laughing-Train
quarkus.mongodb.metrics.enabled=true
quarkus.http.cors.origins=*
%prod.quarkus.oidc.token-state-manager.split-tokens=true
quarkus.vertx.max-worker-execute-time=30m
quarkus.vertx.max-worker-execute-time=30m
%test.quarkus.scheduler.enabled=false

0 comments on commit 77f22d8

Please sign in to comment.