From 602d7069fa2e524e9db2fca41c0a4ffc439d70b4 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Mon, 14 Aug 2023 00:48:56 +0300 Subject: [PATCH 1/2] [5.0.0-SNAPSHOT] ArangoDatabaseInitializer in parallel --- .../arango/ArangoDatabaseInitializer.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/micronaut/configuration/arango/ArangoDatabaseInitializer.java b/src/main/java/io/micronaut/configuration/arango/ArangoDatabaseInitializer.java index d7c3bc6..7a01b8b 100644 --- a/src/main/java/io/micronaut/configuration/arango/ArangoDatabaseInitializer.java +++ b/src/main/java/io/micronaut/configuration/arango/ArangoDatabaseInitializer.java @@ -2,10 +2,10 @@ import com.arangodb.ArangoDBException; import io.micronaut.context.annotation.Context; +import io.micronaut.context.annotation.Parallel; import io.micronaut.context.annotation.Requires; import io.micronaut.core.annotation.Internal; import io.micronaut.runtime.exceptions.ApplicationStartupException; -import jakarta.annotation.PostConstruct; import java.time.Duration; import java.util.concurrent.*; import org.slf4j.Logger; @@ -22,12 +22,21 @@ @Requires(beans = ArangoConfiguration.class) @Context @Internal +@Parallel public class ArangoDatabaseInitializer { private final Logger logger = LoggerFactory.getLogger(getClass()); - @PostConstruct - public void setupDatabase(ArangoClient client, ArangoConfiguration configuration) { + private final ArangoClient client; + private final ArangoConfiguration configuration; + + public ArangoDatabaseInitializer(ArangoClient client, ArangoConfiguration configuration) { + this.client = client; + this.configuration = configuration; + setupDatabase(); + } + + public void setupDatabase() { final String database = configuration.getDatabase(); if (ArangoSettings.SYSTEM_DATABASE.equals(database)) { logger.debug("ArangoDB is configured to use System Database, skipping initialization"); From 0d156d0a9c6bcf96a85639e891e8fbc99df84e49 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Mon, 14 Aug 2023 01:00:12 +0300 Subject: [PATCH 2/2] [5.0.0-SNAPSHOT] Constrains improved --- .../configuration/arango/ArangoAccessorFactory.java | 8 +++++++- .../configuration/arango/ArangoClientFactory.java | 4 ++-- .../configuration/arango/ArangoDatabaseInitializer.java | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/micronaut/configuration/arango/ArangoAccessorFactory.java b/src/main/java/io/micronaut/configuration/arango/ArangoAccessorFactory.java index 8ce65cb..699f827 100644 --- a/src/main/java/io/micronaut/configuration/arango/ArangoAccessorFactory.java +++ b/src/main/java/io/micronaut/configuration/arango/ArangoAccessorFactory.java @@ -28,7 +28,7 @@ public class ArangoAccessorFactory { ArangoDB getAccessor(ArangoConfiguration configuration, SSLContextProvider sslContextProvider, @Nullable ArangoSerde serde) { - return getAccessorPrototype(configuration, sslContextProvider, serde); + return createAccessor(configuration, sslContextProvider, serde); } /** @@ -46,6 +46,12 @@ ArangoDB getAccessor(ArangoConfiguration configuration, ArangoDB getAccessorPrototype(ArangoConfiguration configuration, SSLContextProvider sslContextProvider, @Nullable ArangoSerde serde) { + return createAccessor(configuration, sslContextProvider, serde); + } + + private ArangoDB createAccessor(ArangoConfiguration configuration, + SSLContextProvider sslContextProvider, + @Nullable ArangoSerde serde) { final ArangoSSLConfiguration sslConfiguration = configuration.getSslConfiguration(); final ArangoDB.Builder builder = new ArangoDB.Builder(); diff --git a/src/main/java/io/micronaut/configuration/arango/ArangoClientFactory.java b/src/main/java/io/micronaut/configuration/arango/ArangoClientFactory.java index db43102..06b25b4 100644 --- a/src/main/java/io/micronaut/configuration/arango/ArangoClientFactory.java +++ b/src/main/java/io/micronaut/configuration/arango/ArangoClientFactory.java @@ -12,7 +12,7 @@ * @author Anton Kurako (GoodforGod) * @since 29.2.2020 */ -@Requires(beans = ArangoConfiguration.class) +@Requires(beans = { ArangoDB.class, ArangoConfiguration.class }) @Factory public class ArangoClientFactory { @@ -20,7 +20,7 @@ public class ArangoClientFactory { @Bean(preDestroy = "close") @Singleton ArangoClient getClient(ArangoDB accessor, ArangoConfiguration configuration) { - return getClientPrototype(accessor, configuration); + return new ArangoClientImpl(accessor, configuration); } /** diff --git a/src/main/java/io/micronaut/configuration/arango/ArangoDatabaseInitializer.java b/src/main/java/io/micronaut/configuration/arango/ArangoDatabaseInitializer.java index 7a01b8b..bf2094d 100644 --- a/src/main/java/io/micronaut/configuration/arango/ArangoDatabaseInitializer.java +++ b/src/main/java/io/micronaut/configuration/arango/ArangoDatabaseInitializer.java @@ -6,6 +6,7 @@ import io.micronaut.context.annotation.Requires; import io.micronaut.core.annotation.Internal; import io.micronaut.runtime.exceptions.ApplicationStartupException; +import jakarta.annotation.PostConstruct; import java.time.Duration; import java.util.concurrent.*; import org.slf4j.Logger; @@ -19,7 +20,7 @@ * @since 16.3.2020 */ @Requires(property = ArangoSettings.PREFIX + ".create-database-if-not-exist", value = "true", defaultValue = "false") -@Requires(beans = ArangoConfiguration.class) +@Requires(beans = { ArangoClient.class, ArangoConfiguration.class }) @Context @Internal @Parallel @@ -33,9 +34,9 @@ public class ArangoDatabaseInitializer { public ArangoDatabaseInitializer(ArangoClient client, ArangoConfiguration configuration) { this.client = client; this.configuration = configuration; - setupDatabase(); } + @PostConstruct public void setupDatabase() { final String database = configuration.getDatabase(); if (ArangoSettings.SYSTEM_DATABASE.equals(database)) {