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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Class
<?> extractBeanClass
(org.springframework.beans.factory.config.BeanDefinition beanDefinition) Extracts the target class from the scannedBeanDefinition
.void
postProcessBeanDefinitionRegistry
(@NonNull org.springframework.beans.factory.support.BeanDefinitionRegistry registry) No-op.void
postProcessBeanFactory
(@NonNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) Scans the classpath for components annotated withTrackSelf
, based onComponentScan
metadata, and registers each of them as aFluxPrototype
.void
setEnvironment
(org.springframework.core.env.Environment environment) Sets the SpringEnvironment
used for context-aware scanning.
-
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 withTrackSelf
, based onComponentScan
metadata, and registers each of them as aFluxPrototype
.If the
beanFactory
is not aBeanDefinitionRegistry
, a warning is logged and processing is skipped.- Specified by:
postProcessBeanFactory
in interfaceorg.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
- Specified by:
postProcessBeanFactory
in interfaceorg.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 scannedBeanDefinition
.- 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 interfaceorg.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
- Parameters:
registry
- theBeanDefinitionRegistry
- Throws:
org.springframework.beans.BeansException
-
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment) Sets the SpringEnvironment
used for context-aware scanning.- Specified by:
setEnvironment
in interfaceorg.springframework.context.EnvironmentAware
-