This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Config helidonConfig = MpConfig.toHelidonConfig(config).get(NEO4J_METRIC_NAME_PREFIX); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ConfigValue<Neo4j> configValue = helidonConfig.as(Neo4j::create); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return configValue.get().driver(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Inject | |
public MovieRepository(Driver driver) { | |
this.driver = driver; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Neo4j settings | |
neo4j.uri=bolt://localhost:7687 | |
neo4j.authentication.username=neo4j | |
neo4j.authentication.password: secret | |
neo4j.pool.metricsEnabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Builder implements io.helidon.common.Builder<Neo4jMetricsSupport> { | |
private Driver driver; | |
private Builder() { | |
} | |
public Neo4jMetricsSupport build() { | |
Objects.requireNonNull(driver, "Must set driver before building"); | |
return new Neo4jMetricsSupport(this); | |
} | |
public Builder driver(Driver driver) { | |
this.driver = driver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static class Neo4JCounterWrapper implements Counter { | |
private final Supplier<Long> fn; | |
private Neo4JCounterWrapper(Supplier<Long> fn) { | |
this.fn = fn; | |
} | |
@Override | |
public void inc() { | |
throw new UnsupportedOperationException(); | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void registerCounter(MetricRegistry metricRegistry, | |
ConnectionPoolMetrics cpm, | |
String poolPrefix, | |
String name, | |
Function<ConnectionPoolMetrics, Long> fn) { | |
String counterName = poolPrefix + name; | |
if (metricRegistry.getCounters().get(new MetricID(counterName)) == null) { | |
Metadata metadata = Metadata.builder() | |
.withName(counterName) | |
.withType(MetricType.COUNTER) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void reinit() { | |
Map<String, Function<ConnectionPoolMetrics, Long>> counters = Map.ofEntries( | |
entry("acquired", ConnectionPoolMetrics::acquired), | |
entry("closed", ConnectionPoolMetrics::closed), | |
entry("created", ConnectionPoolMetrics::created), | |
entry("failedToCreate", ConnectionPoolMetrics::failedToCreate), | |
entry("timedOutToAcquire", ConnectionPoolMetrics::timedOutToAcquire), | |
entry("totalAcquisitionTime", ConnectionPoolMetrics::totalAcquisitionTime), | |
entry("totalConnectionTime", ConnectionPoolMetrics::totalConnectionTime), | |
entry("totalInUseCount", ConnectionPoolMetrics::totalInUseCount), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void refreshMetrics(ScheduledExecutorService executor) { | |
Collection<ConnectionPoolMetrics> currentPoolMetrics = driver.metrics().connectionPoolMetrics(); | |
if (!metricsInitialized.get() && currentPoolMetrics.size() >= 1) { | |
lastPoolMetrics.set(currentPoolMetrics); | |
reinit(); | |
if (metricsInitialized.get()) { | |
reinitFuture.get().cancel(false); | |
executor.shutdown(); | |
} | |
} |