Skip to content

Commit

Permalink
Wrap driver instancen in RuntimeValue<Driver>.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-simons committed Aug 3, 2020
1 parent 6726974 commit 30446f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import org.neo4j.driver.Driver;

import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.runtime.RuntimeValue;

/**
* Allows access to the Neo4j Driver instance from within other extensions.
*/
public final class Neo4jDriverBuildItem extends SimpleBuildItem {

private final Driver value;
private final RuntimeValue<Driver> value;

public Neo4jDriverBuildItem(Driver value) {
public Neo4jDriverBuildItem(RuntimeValue<Driver> value) {
this.value = value;
}

public Driver getValue() {
public RuntimeValue<Driver> getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.quarkus.neo4j.runtime.Neo4jConfiguration;
import io.quarkus.neo4j.runtime.Neo4jDriverProducer;
import io.quarkus.neo4j.runtime.Neo4jDriverRecorder;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem;

class Neo4jDriverProcessor {
Expand All @@ -39,9 +40,9 @@ Neo4jDriverBuildItem configureDriverProducer(Neo4jDriverRecorder recorder, BeanC
Neo4jConfiguration configuration,
ShutdownContextBuildItem shutdownContext) {

Driver driver = recorder.initializeDriver(configuration, shutdownContext);
recorder.configureNeo4jProducer(beanContainerBuildItem.getValue(), driver);
return new Neo4jDriverBuildItem(driver);
RuntimeValue<Driver> driverHolder = recorder.initializeDriver(configuration, shutdownContext);
recorder.configureNeo4jProducer(beanContainerBuildItem.getValue(), driverHolder);
return new Neo4jDriverBuildItem(driverHolder);
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.neo4j.driver.Logging;

import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.ssl.SslContextConfiguration;
Expand All @@ -23,7 +24,7 @@ public class Neo4jDriverRecorder {

private static final Logger log = Logger.getLogger(Neo4jDriverRecorder.class);

public Driver initializeDriver(Neo4jConfiguration configuration, ShutdownContext shutdownContext) {
public RuntimeValue<Driver> initializeDriver(Neo4jConfiguration configuration, ShutdownContext shutdownContext) {

String uri = configuration.uri;
AuthToken authToken = AuthTokens.none();
Expand All @@ -37,12 +38,12 @@ public Driver initializeDriver(Neo4jConfiguration configuration, ShutdownContext

Driver driver = GraphDatabase.driver(uri, authToken, configBuilder.build());
shutdownContext.addShutdownTask(driver::close);
return driver;
return new RuntimeValue<>(driver);
}

public void configureNeo4jProducer(BeanContainer beanContainer, Driver driver) {
public void configureNeo4jProducer(BeanContainer beanContainer, RuntimeValue<Driver> driverHolder) {
Neo4jDriverProducer driverProducer = beanContainer.instance(Neo4jDriverProducer.class);
driverProducer.initialize(driver);
driverProducer.initialize(driverHolder.getValue());
}

private static Config.ConfigBuilder createBaseConfig() {
Expand Down

0 comments on commit 30446f5

Please sign in to comment.