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 Details

    • FailoverAutoConfiguration

      public FailoverAutoConfiguration()
  • Method Details

    • failoverClock

      @ConditionalOnMissingBean @Bean public FailoverClock 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:
      DefaultKeyGenerator using MD5-based fixed-length key hashing
    • keyGeneratorLookup

      @ConditionalOnMissingBean @Bean public KeyGeneratorLookup keyGeneratorLookup()
      Creates the key-generator lookup bean.
      Returns:
      BeanFactoryKeyGeneratorLookup resolving 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 found
      keyGeneratorLookup - lookup that resolves per-@Failover named key generators
      Returns:
      composite FailoverKeyGenerator that delegates to named generators or the default
    • failoverExpiryExtractor

      @ConditionalOnMissingBean @Bean public FailoverExpiryExtractor failoverExpiryExtractor()
      Creates the failover expiry extractor bean.
      Returns:
      BeanFactoryFailoverExpiryExtractor resolving 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 timestamps
      failoverExpiryExtractor - extractor that reads expiry duration from @Failover
      Returns:
      default expiry policy based on the annotation's configured duration
    • expiryPolicyLookup

      @ConditionalOnMissingBean @Bean public ExpiryPolicyLookup<Object> expiryPolicyLookup()
      Creates the expiry-policy lookup bean.
      Returns:
      BeanFactoryExpiryPolicyLookup resolving 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 found
      expiryPolicyLookup - lookup that resolves per-@Failover named expiry policies
      Returns:
      composite expiry policy that delegates to named policies or the default
    • payloadEnricher

      @ConditionalOnMissingBean @Bean public PayloadEnricher<Object> payloadEnricher()
      Creates the default payload enricher bean.
      Returns:
      default pass-through DefaultPayloadEnricher
    • payloadSplitterLookup

      @ConditionalOnMissingBean @Bean public PayloadSplitterLookup<Object,Object> payloadSplitterLookup()
      Creates the payload-splitter lookup bean.
      Returns:
      BeanFactoryPayloadSplitterLookup resolving 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 active ContextPropagator from available propagator beans:
      1. TenantContextPropagator — present when failover.store.multitenant.enabled=true
      2. MicrometerContextPropagator — present when io.micrometer.tracing.Tracer is on classpath and a Tracer bean exists
      3. MdcContextPropagator — always included
      Declare your own ContextPropagator bean to replace this composition entirely.
      Parameters:
      tenantPropagatorProvider - optional TenantContextPropagator bean
      micrometerPropagatorProvider - optional MicrometerContextPropagator bean
      Returns:
      a single propagator or a CompositeContextPropagator when 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 when failover.scatter.parallel=true.

      Override by declaring a bean named scatterGatherExecutor.

      Returns:
      virtual-thread SimpleAsyncTaskExecutor named failover-scatter-*
    • failoverScanner

      @ConditionalOnMissingBean @Bean public FailoverScanner failoverScanner()
      Registers a Spring-native scanner that locates all @Failover-annotated methods by walking the already-built ApplicationContext.
      Returns:
      SpringContextFailoverScanner
    • recoveredPayloadHandler

      @ConditionalOnMissingBean @Bean public RecoveredPayloadHandler recoveredPayloadHandler()
      Registers the default no-op RecoveredPayloadHandler that returns the payload unchanged.
      Returns:
      pass-through PassThroughRecoveredPayloadHandler
    • loggerObservablePublisher

      @Bean public ObservablePublisher loggerObservablePublisher()
      Registers a ObservablePublisher that 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 every ObservablePublisher in the context. Stamping once here ensures all delegates receive the same timestamp regardless of how many publishers are registered.
      Parameters:
      observablePublishers - all ObservablePublisher beans in the context
      clock - 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 full FailoverHandler decorator chain: AdvancedFailoverHandler(ScatterGatherFailoverHandler(DefaultFailoverHandler)).
      Parameters:
      keyGenerator - composite key generator
      expiryPolicy - composite expiry policy
      clock - failover clock
      failoverStore - the assembled store (async/sync, single/multi-tenant)
      payloadEnricher - enriches payloads on store
      recoveredPayloadHandler - handles recovered (or null) payloads
      observablePublisher - composite report publisher
      failoverExpiryExtractor - reads expiry from @Failover
      payloadSplitterLookup - looks up named splitter beans
      contextPropagator - propagates thread context to scatter executor threads
      scatterGatherExecutorProvider - optional executor for parallel scatter (null = sequential)
      Returns:
      assembled AdvancedFailoverHandler
    • methodExceptionHandler

      @ConditionalOnMissingBean @Bean public MethodExceptionHandler methodExceptionHandler(MethodExceptionPolicy methodExceptionPolicy)
      Registers the MethodExceptionHandler that 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)
      Registers BasicFailoverExecution, active when failover.type=basic (the default).
      Parameters:
      failoverHandler - assembled failover handler
      methodExceptionHandler - 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

      @ConditionalOnMissingBean @Bean public ResourceLoader 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 from MANIFEST.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 report
      failoverScanner - scans for all @Failover-annotated methods
      clock - clock for the report timestamp
      manifestInfoExtractor - extracts build info from MANIFEST.MF
      failoverExpiryExtractor - reads expiry config from @Failover
      failoverProperties - active failover properties for inclusion in the report
      Returns:
      reporter that publishes a full failover summary on application startup