From 206e416488f2b2cc5a833aa0f4c6ec5b21357770 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 6 Apr 2023 16:38:16 +0200 Subject: [PATCH] Switch Hibernate Search Outbox Polling extension to @ConfigMapping --- .../HibernateSearchOutboxPollingRecorder.java | 32 ++++---- ...rnateSearchOutboxPollingRuntimeConfig.java | 16 ++-- ...oxPollingRuntimeConfigPersistenceUnit.java | 78 +++++++++---------- 3 files changed, 61 insertions(+), 65 deletions(-) diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java index 6c7e36d341f28..c65a8566d72e5 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java @@ -20,8 +20,8 @@ public HibernateOrmIntegrationRuntimeInitListener createRuntimeInitListener( HibernateSearchOutboxPollingRuntimeConfig runtimeConfig, String persistenceUnitName) { HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit puConfig = PersistenceUnitUtil .isDefaultPersistenceUnit(persistenceUnitName) - ? runtimeConfig.defaultPersistenceUnit - : runtimeConfig.persistenceUnits.get(persistenceUnitName); + ? runtimeConfig.defaultPersistenceUnit() + : runtimeConfig.persistenceUnits().get(persistenceUnitName); return new RuntimeInitListener(puConfig); } @@ -40,9 +40,9 @@ public void contributeRuntimeProperties(BiConsumer propertyColle return; } - contributeCoordinationRuntimeProperties(propertyCollector, null, runtimeConfig.coordination.defaults); + contributeCoordinationRuntimeProperties(propertyCollector, null, runtimeConfig.coordination().defaults()); - for (Entry tenantEntry : runtimeConfig.coordination.tenants.entrySet()) { + for (Entry tenantEntry : runtimeConfig.coordination().tenants().entrySet()) { contributeCoordinationRuntimeProperties(propertyCollector, tenantEntry.getKey(), tenantEntry.getValue()); } } @@ -51,41 +51,41 @@ private void contributeCoordinationRuntimeProperties(BiConsumer AgentsConfig agentsConfig) { addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_ENABLED, - agentsConfig.eventProcessor.enabled); + agentsConfig.eventProcessor().enabled()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_SHARDS_TOTAL_COUNT, - agentsConfig.eventProcessor.shards.totalCount); + agentsConfig.eventProcessor().shards().totalCount()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_SHARDS_ASSIGNED, - agentsConfig.eventProcessor.shards.assigned); + agentsConfig.eventProcessor().shards().assigned()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_POLLING_INTERVAL, - agentsConfig.eventProcessor.pollingInterval.toMillis()); + agentsConfig.eventProcessor().pollingInterval().toMillis()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_PULSE_INTERVAL, - agentsConfig.eventProcessor.pulseInterval.toMillis()); + agentsConfig.eventProcessor().pulseInterval().toMillis()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_PULSE_EXPIRATION, - agentsConfig.eventProcessor.pulseExpiration.toMillis()); + agentsConfig.eventProcessor().pulseExpiration().toMillis()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_BATCH_SIZE, - agentsConfig.eventProcessor.batchSize); + agentsConfig.eventProcessor().batchSize()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_TRANSACTION_TIMEOUT, - agentsConfig.eventProcessor.transactionTimeout, Optional::isPresent, d -> d.get().toSeconds()); + agentsConfig.eventProcessor().transactionTimeout(), Optional::isPresent, d -> d.get().toSeconds()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_RETRY_DELAY, - agentsConfig.eventProcessor.retryDelay.toSeconds()); + agentsConfig.eventProcessor().retryDelay().toSeconds()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.MASS_INDEXER_POLLING_INTERVAL, - agentsConfig.massIndexer.pollingInterval.toMillis()); + agentsConfig.massIndexer().pollingInterval().toMillis()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.MASS_INDEXER_PULSE_INTERVAL, - agentsConfig.massIndexer.pulseInterval.toMillis()); + agentsConfig.massIndexer().pulseInterval().toMillis()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.MASS_INDEXER_PULSE_EXPIRATION, - agentsConfig.massIndexer.pulseExpiration.toMillis()); + agentsConfig.massIndexer().pulseExpiration().toMillis()); } } diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfig.java b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfig.java index cd420a78fcbcf..1fbf4e7108ff5 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfig.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfig.java @@ -4,25 +4,27 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithParentName; -@ConfigRoot(name = "hibernate-search-orm", phase = ConfigPhase.RUN_TIME) -public class HibernateSearchOutboxPollingRuntimeConfig { +@ConfigMapping(prefix = "quarkus.hibernate-search-orm") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface HibernateSearchOutboxPollingRuntimeConfig { /** * Configuration for the default persistence unit. */ - @ConfigItem(name = ConfigItem.PARENT) - public HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit defaultPersistenceUnit; + @WithParentName + HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit defaultPersistenceUnit(); /** * Configuration for additional named persistence units. */ @ConfigDocSection @ConfigDocMapKey("persistence-unit-name") - @ConfigItem(name = ConfigItem.PARENT) - public Map persistenceUnits; + @WithParentName + Map persistenceUnits(); } diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit.java b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit.java index d59783942c898..413c1e8834c08 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit.java @@ -9,55 +9,53 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithParentName; @ConfigGroup -class HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit { +public interface HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit { /** * Configuration for coordination between threads or application instances. */ - @ConfigItem - CoordinationConfig coordination; + CoordinationConfig coordination(); @ConfigGroup - static class CoordinationConfig { + public interface CoordinationConfig { /** * Default config */ @ConfigDocSection - @ConfigItem(name = ConfigItem.PARENT) - AgentsConfig defaults; + @WithParentName + AgentsConfig defaults(); /** * Per-tenant config */ @ConfigDocSection @ConfigDocMapKey("tenant-id") - Map tenants; + Map tenants(); } @ConfigGroup - static class AgentsConfig { + public interface AgentsConfig { /** * Configuration for the event processor agent. */ - @ConfigItem - EventProcessorConfig eventProcessor; + EventProcessorConfig eventProcessor(); /** * Configuration for the mass indexer agent. */ - @ConfigItem - MassIndexerConfig massIndexer; + MassIndexerConfig massIndexer(); } @ConfigGroup - static class EventProcessorConfig { + public interface EventProcessorConfig { // @formatter:off /** @@ -74,14 +72,13 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "true") - boolean enabled; + @WithDefault("true") + boolean enabled(); /** * Configuration related to shards. */ - @ConfigItem - EventProcessorShardsConfig shards; + EventProcessorShardsConfig shards(); // @formatter:off /** @@ -97,8 +94,8 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "0.100S") - Duration pollingInterval; + @WithDefault("0.100S") + Duration pollingInterval(); // @formatter:off /** @@ -127,8 +124,8 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "2S") - Duration pulseInterval; + @WithDefault("2S") + Duration pulseInterval(); // @formatter:off /** @@ -154,8 +151,8 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "30S") - Duration pulseExpiration; + @WithDefault("30S") + Duration pulseExpiration(); // @formatter:off /** @@ -172,8 +169,8 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "50") - int batchSize; + @WithDefault("50") + int batchSize(); // @formatter:off /** @@ -191,8 +188,7 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem - Optional transactionTimeout; + Optional transactionTimeout(); // @formatter:off /** @@ -207,13 +203,13 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "30S") - Duration retryDelay; + @WithDefault("30S") + Duration retryDelay(); } @ConfigGroup - static class EventProcessorShardsConfig { + public interface EventProcessorShardsConfig { // @formatter:off /** @@ -232,8 +228,7 @@ static class EventProcessorShardsConfig { * @asciidoclet */ // @formatter:on - @ConfigItem - OptionalInt totalCount; + OptionalInt totalCount(); // @formatter:off /** @@ -257,13 +252,12 @@ static class EventProcessorShardsConfig { * @asciidoclet */ // @formatter:on - @ConfigItem - Optional> assigned; + Optional> assigned(); } @ConfigGroup - static class MassIndexerConfig { + public interface MassIndexerConfig { // @formatter:off /** @@ -285,8 +279,8 @@ static class MassIndexerConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "0.100S") - Duration pollingInterval; + @WithDefault("0.100S") + Duration pollingInterval(); // @formatter:off /** @@ -313,8 +307,8 @@ static class MassIndexerConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "2S") - Duration pulseInterval; + @WithDefault("2S") + Duration pulseInterval(); // @formatter:off /** @@ -340,8 +334,8 @@ static class MassIndexerConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "30S") - Duration pulseExpiration; + @WithDefault("30S") + Duration pulseExpiration(); }