Class TrackSelfPostProcessor

java.lang.Object
io.fluxcapacitor.javaclient.configuration.spring.TrackSelfPostProcessor
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.config.BeanFactoryPostProcessor, org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.context.EnvironmentAware

public class TrackSelfPostProcessor extends Object implements org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.context.EnvironmentAware
Spring BeanDefinitionRegistryPostProcessor that detects classes annotated with TrackSelf and registers them as FluxPrototype beans for use by Flux Capacitor.

This processor differs from StatefulPostProcessor in that it performs full classpath scanning—rather than only inspecting instantiated beans—because it must also detect interfaces and abstract classes annotated with @TrackSelf. These types represent projection definitions that are later handled dynamically.

All detected @TrackSelf types are wrapped as FluxPrototype and registered as Spring bean definitions, allowing Flux to discover and register them as self-tracking projections at runtime.

Usage

To enable self-tracking on a class use e.g.:

 @TrackSelf
 public interface UserUpdate {
     UserId getUserId();

     @HandleCommand
     default void handle() {
         FluxCapacitor.loadAggregate(getUserId()).assertAndApply(this);
     }
 }
 

Make sure Spring picks up this processor, for example by including FluxCapacitorSpringConfig in your configuration:


 @SpringBootApplication
 @Import(FluxCapacitorSpringConfig.class)
 public class MyApp { ... }
 
See Also:
  • Constructor Details

    • TrackSelfPostProcessor

      public TrackSelfPostProcessor()
  • Method Details

    • postProcessBeanFactory

      public void postProcessBeanFactory(@NonNull @NonNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException
      Scans the classpath for components annotated with TrackSelf, based on ComponentScan metadata, and registers each of them as a FluxPrototype.

      If the beanFactory is not a BeanDefinitionRegistry, a warning is logged and processing is skipped.

      Specified by:
      postProcessBeanFactory in interface org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
      Specified by:
      postProcessBeanFactory in interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
      Throws:
      org.springframework.beans.BeansException
    • extractBeanClass

      protected Class<?> extractBeanClass(org.springframework.beans.factory.config.BeanDefinition beanDefinition)
      Extracts the target class from the scanned BeanDefinition.
      Parameters:
      beanDefinition - the scanned bean definition
      Returns:
      the resolved class, or null if not resolvable
    • postProcessBeanDefinitionRegistry

      public void postProcessBeanDefinitionRegistry(@NonNull @NonNull org.springframework.beans.factory.support.BeanDefinitionRegistry registry) throws org.springframework.beans.BeansException
      No-op. This implementation does not modify the registry at this phase.
      Specified by:
      postProcessBeanDefinitionRegistry in interface org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
      Parameters:
      registry - the BeanDefinitionRegistry
      Throws:
      org.springframework.beans.BeansException
    • setEnvironment

      public void setEnvironment(org.springframework.core.env.Environment environment)
      Sets the Spring Environment used for context-aware scanning.
      Specified by:
      setEnvironment in interface org.springframework.context.EnvironmentAware