Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Neo4j driver as dedicated BuildItem. #11115

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.neo4j.deployment;

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 RuntimeValue<Driver> value;

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

public RuntimeValue<Driver> getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.neo4j.deployment;

import org.neo4j.driver.Driver;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.deployment.Feature;
Expand All @@ -13,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 @@ -33,11 +36,13 @@ AdditionalBeanBuildItem createDriverProducer() {

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
void configureDriverProducer(Neo4jDriverRecorder recorder, BeanContainerBuildItem beanContainerBuildItem,
Neo4jDriverBuildItem configureDriverProducer(Neo4jDriverRecorder recorder, BeanContainerBuildItem beanContainerBuildItem,
Neo4jConfiguration configuration,
ShutdownContextBuildItem shutdownContext) {

recorder.configureNeo4jProducer(beanContainerBuildItem.getValue(), configuration, shutdownContext);
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,17 +24,7 @@ public class Neo4jDriverRecorder {

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

public void configureNeo4jProducer(BeanContainer beanContainer, Neo4jConfiguration configuration,
ShutdownContext shutdownContext) {

Driver driver = initializeDriver(configuration, shutdownContext);

Neo4jDriverProducer driverProducer = beanContainer.instance(Neo4jDriverProducer.class);
driverProducer.initialize(driver);
}

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

String uri = configuration.uri;
AuthToken authToken = AuthTokens.none();
Expand All @@ -47,7 +38,12 @@ private Driver initializeDriver(Neo4jConfiguration configuration,

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

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

private static Config.ConfigBuilder createBaseConfig() {
Expand Down