Class FailoverAutoConfiguration
java.lang.Object
com.societegenerale.failover.configuration.FailoverAutoConfiguration
@AutoConfiguration
@ConditionalOnExpression("${failover.enabled:true} eq true")
@EnableConfigurationProperties(FailoverProperties.class)
@EnableAspectJAutoProxy
public class FailoverAutoConfiguration
extends Object
Root Spring Boot autoconfiguration for the failover framework.
Activates when failover.enabled=true (the default). Registers all core
failover infrastructure beans: AOP aspect, expiry policy, key generators, payload
enricher, recovered-payload handler, method-exception policy, schedulers, and the
in-memory store factory (when no other store type is configured).
Store-type-specific beans (Caffeine, JDBC) are registered by their own
auto-configurations (FailoverCaffeineStoreAutoConfiguration,
FailoverJdbcStoreAutoConfiguration). The final assembled FailoverStore
bean is produced by FailoverStoreAutoConfiguration.
- Author:
- Anand Manissery
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncompositeObservablePublisher(List<ObservablePublisher> observablePublishers, FailoverClock clock) Registers a composite publisher that stamps the publish timestamp once and broadcasts to everyObservablePublisherin the context.contextPropagator(org.springframework.beans.factory.ObjectProvider<TenantContextPropagator> tenantPropagatorProvider, org.springframework.beans.factory.ObjectProvider<MicrometerContextPropagator> micrometerPropagatorProvider) Composes the activeContextPropagatorfrom available propagator beans:TenantContextPropagator— present whenfailover.store.multitenant.enabled=trueMicrometerContextPropagator— present whenio.micrometer.tracing.Traceris on classpath and aTracerbean existsMdcContextPropagator— always included Declare your ownContextPropagatorbean to replace this composition entirely.defaultExpiryPolicy(FailoverClock clock, FailoverExpiryExtractor failoverExpiryExtractor) Creates the default expiry policy bean.Creates the default key generator bean.Creates the expiry-policy lookup bean.failoverAspect(FailoverExecution<Object> failoverExecution) Registers the AOP aspect that intercepts@Failover-annotated methods.Creates the default failover clock bean.failoverExecution(FailoverHandler<Object> failoverHandler, MethodExceptionHandler methodExceptionHandler) RegistersBasicFailoverExecution, active whenfailover.type=basic(the default).Creates the failover expiry extractor bean.failoverExpiryPolicy(ExpiryPolicy<Object> defaultExpiryPolicy, ExpiryPolicyLookup<Object> expiryPolicyLookup) Creates the composite failover expiry policy.failoverHandler(KeyGenerator keyGenerator, ExpiryPolicy<Object> expiryPolicy, FailoverClock clock, FailoverStore<Object> failoverStore, PayloadEnricher<Object> payloadEnricher, RecoveredPayloadHandler recoveredPayloadHandler, CompositeObservablePublisher observablePublisher, FailoverExpiryExtractor failoverExpiryExtractor, PayloadSplitterLookup<Object, Object> payloadSplitterLookup, ContextPropagator contextPropagator, org.springframework.beans.factory.ObjectProvider<org.springframework.core.task.TaskExecutor> scatterGatherExecutorProvider) Assembles the fullFailoverHandlerdecorator chain:AdvancedFailoverHandler(ScatterGatherFailoverHandler(DefaultFailoverHandler)).failoverKeyGenerator(KeyGenerator defaultKeyGenerator, KeyGeneratorLookup keyGeneratorLookup) Creates the composite failover key generator.failoverObserver(CompositeObservablePublisher observablePublisher, FailoverScanner failoverScanner, FailoverClock clock, ManifestInfoExtractor manifestInfoExtractor, FailoverExpiryExtractor failoverExpiryExtractor, FailoverProperties failoverProperties) Creates the failover reporter bean that publishes a startup summary.Registers a Spring-native scanner that locates all@Failover-annotated methods by walking the already-builtApplicationContext.Creates the key-generator lookup bean.Registers aObservablePublisherthat writes failover reports to SLF4J.manifestInfoExtractor(ResourceLoader resourceLoader) Registers a caching manifest extractor for reading build metadata fromMANIFEST.MF.methodExceptionHandler(MethodExceptionPolicy methodExceptionPolicy) Registers theMethodExceptionHandlerthat applies the active exception policy.Creates the default payload enricher bean.Creates the payload-splitter lookup bean.Registers the default no-opRecoveredPayloadHandlerthat returns the payload unchanged.Registers a resource loader for reading classpath resources (e.g.org.springframework.core.task.TaskExecutorVirtual-thread executor for parallel slice dispatch in scatter/gather operations.
-
Constructor Details
-
FailoverAutoConfiguration
public FailoverAutoConfiguration()
-
-
Method Details
-
failoverClock
Creates the default failover clock bean.- Returns:
- default
DefaultFailoverClock
-
defaultKeyGenerator
@ConditionalOnMissingBean(name="defaultKeyGenerator") @Bean(name="defaultKeyGenerator") public KeyGenerator defaultKeyGenerator()Creates the default key generator bean.- Returns:
DefaultKeyGeneratorusing MD5-based fixed-length key hashing
-
keyGeneratorLookup
Creates the key-generator lookup bean.- Returns:
BeanFactoryKeyGeneratorLookupresolving named key-generator beans
-
failoverKeyGenerator
@ConditionalOnMissingBean(name="failoverKeyGenerator") @Bean(name="failoverKeyGenerator") public KeyGenerator failoverKeyGenerator(@Qualifier("defaultKeyGenerator") KeyGenerator defaultKeyGenerator, KeyGeneratorLookup keyGeneratorLookup) Creates the composite failover key generator.- Parameters:
defaultKeyGenerator- fallback key generator when no named override is foundkeyGeneratorLookup- lookup that resolves per-@Failovernamed key generators- Returns:
- composite
FailoverKeyGeneratorthat delegates to named generators or the default
-
failoverExpiryExtractor
Creates the failover expiry extractor bean.- Returns:
BeanFactoryFailoverExpiryExtractorresolving named expiry-policy beans
-
defaultExpiryPolicy
@ConditionalOnMissingBean(name="defaultExpiryPolicy") @Bean public ExpiryPolicy<Object> defaultExpiryPolicy(FailoverClock clock, FailoverExpiryExtractor failoverExpiryExtractor) Creates the default expiry policy bean.- Parameters:
clock- clock used to compute expiry timestampsfailoverExpiryExtractor- extractor that reads expiry duration from@Failover- Returns:
- default expiry policy based on the annotation's configured duration
-
expiryPolicyLookup
Creates the expiry-policy lookup bean.- Returns:
BeanFactoryExpiryPolicyLookupresolving named expiry-policy beans
-
failoverExpiryPolicy
@ConditionalOnMissingBean(name="failoverExpiryPolicy") @Bean public ExpiryPolicy<Object> failoverExpiryPolicy(@Qualifier("defaultExpiryPolicy") ExpiryPolicy<Object> defaultExpiryPolicy, ExpiryPolicyLookup<Object> expiryPolicyLookup) Creates the composite failover expiry policy.- Parameters:
defaultExpiryPolicy- fallback expiry policy when no named override is foundexpiryPolicyLookup- lookup that resolves per-@Failovernamed expiry policies- Returns:
- composite expiry policy that delegates to named policies or the default
-
payloadEnricher
Creates the default payload enricher bean.- Returns:
- default pass-through
DefaultPayloadEnricher
-
payloadSplitterLookup
Creates the payload-splitter lookup bean.- Returns:
BeanFactoryPayloadSplitterLookupresolving named splitter beans
-
contextPropagator
@ConditionalOnMissingBean(name="contextPropagator") @Bean public ContextPropagator contextPropagator(org.springframework.beans.factory.ObjectProvider<TenantContextPropagator> tenantPropagatorProvider, org.springframework.beans.factory.ObjectProvider<MicrometerContextPropagator> micrometerPropagatorProvider) Composes the activeContextPropagatorfrom available propagator beans:TenantContextPropagator— present whenfailover.store.multitenant.enabled=trueMicrometerContextPropagator— present whenio.micrometer.tracing.Traceris on classpath and aTracerbean existsMdcContextPropagator— always included
ContextPropagatorbean to replace this composition entirely.- Parameters:
tenantPropagatorProvider- optionalTenantContextPropagatorbeanmicrometerPropagatorProvider- optionalMicrometerContextPropagatorbean- Returns:
- a single propagator or a
CompositeContextPropagatorwhen multiple are present
-
scatterGatherExecutor
@ConditionalOnMissingBean(name="scatterGatherExecutor") @ConditionalOnProperty(prefix="failover.scatter", name="parallel", havingValue="true") @Bean(name="scatterGatherExecutor") public org.springframework.core.task.TaskExecutor scatterGatherExecutor()Virtual-thread executor for parallel slice dispatch in scatter/gather operations. Activated only whenfailover.scatter.parallel=true.Override by declaring a bean named
scatterGatherExecutor.- Returns:
- virtual-thread
SimpleAsyncTaskExecutornamedfailover-scatter-*
-
failoverScanner
Registers a Spring-native scanner that locates all@Failover-annotated methods by walking the already-builtApplicationContext.- Returns:
SpringContextFailoverScanner
-
recoveredPayloadHandler
Registers the default no-opRecoveredPayloadHandlerthat returns the payload unchanged.- Returns:
- pass-through
PassThroughRecoveredPayloadHandler
-
loggerObservablePublisher
Registers aObservablePublisherthat writes failover reports to SLF4J.- Returns:
MdcLoggerObservablePublisher
-
compositeObservablePublisher
@ConditionalOnMissingBean @Bean public CompositeObservablePublisher compositeObservablePublisher(List<ObservablePublisher> observablePublishers, FailoverClock clock) Registers a composite publisher that stamps the publish timestamp once and broadcasts to everyObservablePublisherin the context. Stamping once here ensures all delegates receive the same timestamp regardless of how many publishers are registered.- Parameters:
observablePublishers- allObservablePublisherbeans in the contextclock- clock used to stamp the single publish timestamp- Returns:
- composite publisher
-
failoverHandler
@ConditionalOnMissingBean @Bean public FailoverHandler<Object> failoverHandler(@Qualifier("failoverKeyGenerator") KeyGenerator keyGenerator, @Qualifier("failoverExpiryPolicy") ExpiryPolicy<Object> expiryPolicy, FailoverClock clock, FailoverStore<Object> failoverStore, PayloadEnricher<Object> payloadEnricher, RecoveredPayloadHandler recoveredPayloadHandler, CompositeObservablePublisher observablePublisher, FailoverExpiryExtractor failoverExpiryExtractor, PayloadSplitterLookup<Object, Object> payloadSplitterLookup, @Qualifier("contextPropagator") ContextPropagator contextPropagator, @Qualifier("scatterGatherExecutor") org.springframework.beans.factory.ObjectProvider<org.springframework.core.task.TaskExecutor> scatterGatherExecutorProvider) Assembles the fullFailoverHandlerdecorator chain:AdvancedFailoverHandler(ScatterGatherFailoverHandler(DefaultFailoverHandler)).- Parameters:
keyGenerator- composite key generatorexpiryPolicy- composite expiry policyclock- failover clockfailoverStore- the assembled store (async/sync, single/multi-tenant)payloadEnricher- enriches payloads on storerecoveredPayloadHandler- handles recovered (or null) payloadsobservablePublisher- composite report publisherfailoverExpiryExtractor- reads expiry from@FailoverpayloadSplitterLookup- looks up named splitter beanscontextPropagator- propagates thread context to scatter executor threadsscatterGatherExecutorProvider- optional executor for parallel scatter (null = sequential)- Returns:
- assembled
AdvancedFailoverHandler
-
methodExceptionHandler
@ConditionalOnMissingBean @Bean public MethodExceptionHandler methodExceptionHandler(MethodExceptionPolicy methodExceptionPolicy) Registers theMethodExceptionHandlerthat applies the active exception policy.- Parameters:
methodExceptionPolicy- active exception policy (rethrow, never-throw, or custom)- Returns:
MethodExceptionHandler
-
failoverExecution
@ConditionalOnProperty(prefix="failover", name="type", havingValue="basic", matchIfMissing=true) @ConditionalOnMissingBean @Bean public FailoverExecution<Object> failoverExecution(FailoverHandler<Object> failoverHandler, MethodExceptionHandler methodExceptionHandler) RegistersBasicFailoverExecution, active whenfailover.type=basic(the default).- Parameters:
failoverHandler- assembled failover handlermethodExceptionHandler- exception handler applying the configured policy- Returns:
BasicFailoverExecution
-
failoverAspect
@ConditionalOnProperty(prefix="failover", name="aspect.enabled", havingValue="true", matchIfMissing=true) @Bean public FailoverAspect<Object> failoverAspect(FailoverExecution<Object> failoverExecution) Registers the AOP aspect that intercepts@Failover-annotated methods.- Parameters:
failoverExecution- the configured failover execution strategy- Returns:
FailoverAspect
-
resourceLoader
Registers a resource loader for reading classpath resources (e.g.MANIFEST.MF).- Returns:
ClassPathResourceLoader
-
manifestInfoExtractor
@ConditionalOnMissingBean @Bean public ManifestInfoExtractor manifestInfoExtractor(ResourceLoader resourceLoader) Registers a caching manifest extractor for reading build metadata fromMANIFEST.MF.- Parameters:
resourceLoader- resource loader for reading MANIFEST.MF- Returns:
- caching wrapper around
DefaultManifestInfoExtractor
-
failoverObserver
@ConditionalOnMissingBean @Bean(initMethod="observe") public FailoverObserver failoverObserver(CompositeObservablePublisher observablePublisher, FailoverScanner failoverScanner, FailoverClock clock, ManifestInfoExtractor manifestInfoExtractor, FailoverExpiryExtractor failoverExpiryExtractor, FailoverProperties failoverProperties) Creates the failover reporter bean that publishes a startup summary.- Parameters:
observablePublisher- composite publisher that receives the startup reportfailoverScanner- scans for all@Failover-annotated methodsclock- clock for the report timestampmanifestInfoExtractor- extracts build info from MANIFEST.MFfailoverExpiryExtractor- reads expiry config from@FailoverfailoverProperties- active failover properties for inclusion in the report- Returns:
- reporter that publishes a full failover summary on application startup
-