Skip to content

Commit

Permalink
Switch Hibernate Search Outbox Polling extension to @ConfigMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Apr 6, 2023
1 parent 7e5f826 commit 206e416
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -40,9 +40,9 @@ public void contributeRuntimeProperties(BiConsumer<String, Object> propertyColle
return;
}

contributeCoordinationRuntimeProperties(propertyCollector, null, runtimeConfig.coordination.defaults);
contributeCoordinationRuntimeProperties(propertyCollector, null, runtimeConfig.coordination().defaults());

for (Entry<String, AgentsConfig> tenantEntry : runtimeConfig.coordination.tenants.entrySet()) {
for (Entry<String, AgentsConfig> tenantEntry : runtimeConfig.coordination().tenants().entrySet()) {
contributeCoordinationRuntimeProperties(propertyCollector, tenantEntry.getKey(), tenantEntry.getValue());
}
}
Expand All @@ -51,41 +51,41 @@ private void contributeCoordinationRuntimeProperties(BiConsumer<String, Object>
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());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit> persistenceUnits;
@WithParentName
Map<String, HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit> persistenceUnits();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, AgentsConfig> tenants;
Map<String, AgentsConfig> 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
/**
Expand All @@ -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
/**
Expand All @@ -97,8 +94,8 @@ static class EventProcessorConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem(defaultValue = "0.100S")
Duration pollingInterval;
@WithDefault("0.100S")
Duration pollingInterval();

// @formatter:off
/**
Expand Down Expand Up @@ -127,8 +124,8 @@ static class EventProcessorConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem(defaultValue = "2S")
Duration pulseInterval;
@WithDefault("2S")
Duration pulseInterval();

// @formatter:off
/**
Expand All @@ -154,8 +151,8 @@ static class EventProcessorConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem(defaultValue = "30S")
Duration pulseExpiration;
@WithDefault("30S")
Duration pulseExpiration();

// @formatter:off
/**
Expand All @@ -172,8 +169,8 @@ static class EventProcessorConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem(defaultValue = "50")
int batchSize;
@WithDefault("50")
int batchSize();

// @formatter:off
/**
Expand All @@ -191,8 +188,7 @@ static class EventProcessorConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem
Optional<Duration> transactionTimeout;
Optional<Duration> transactionTimeout();

// @formatter:off
/**
Expand All @@ -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
/**
Expand All @@ -232,8 +228,7 @@ static class EventProcessorShardsConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem
OptionalInt totalCount;
OptionalInt totalCount();

// @formatter:off
/**
Expand All @@ -257,13 +252,12 @@ static class EventProcessorShardsConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem
Optional<List<Integer>> assigned;
Optional<List<Integer>> assigned();

}

@ConfigGroup
static class MassIndexerConfig {
public interface MassIndexerConfig {

// @formatter:off
/**
Expand All @@ -285,8 +279,8 @@ static class MassIndexerConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem(defaultValue = "0.100S")
Duration pollingInterval;
@WithDefault("0.100S")
Duration pollingInterval();

// @formatter:off
/**
Expand All @@ -313,8 +307,8 @@ static class MassIndexerConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem(defaultValue = "2S")
Duration pulseInterval;
@WithDefault("2S")
Duration pulseInterval();

// @formatter:off
/**
Expand All @@ -340,8 +334,8 @@ static class MassIndexerConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem(defaultValue = "30S")
Duration pulseExpiration;
@WithDefault("30S")
Duration pulseExpiration();

}

Expand Down

0 comments on commit 206e416

Please sign in to comment.