Skip to content

Instantly share code, notes, and snippets.

View dalexandrov's full-sized avatar

Dmitry Aleksandrov dalexandrov

View GitHub Profile
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),
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)
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
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;
# Neo4j settings
neo4j.uri=bolt://localhost:7687
neo4j.authentication.username=neo4j
neo4j.authentication.password: secret
neo4j.pool.metricsEnabled: true
@Inject
public MovieRepository(Driver driver) {
this.driver = driver;
}
return configValue.get().driver();
ConfigValue<Neo4j> configValue = helidonConfig.as(Neo4j::create);
Config helidonConfig = MpConfig.toHelidonConfig(config).get(NEO4J_METRIC_NAME_PREFIX);
public class Neo4jCdiExtension implements Extension {
private static final String NEO4J_METRIC_NAME_PREFIX = "neo4j";
void afterBeanDiscovery(@Observes AfterBeanDiscovery addEvent) {
addEvent.addBean()
.types(Driver.class)
.qualifiers(Default.Literal.INSTANCE, Any.Literal.INSTANCE)
.scope(ApplicationScoped.class)
.name(Driver.class.getName())
.beanClass(Driver.class)
.createWith(creationContext -> {