-
Notifications
You must be signed in to change notification settings - Fork 784
/
AxonConfiguration.java
132 lines (108 loc) · 3.67 KB
/
AxonConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package org.axonframework.spring.config;
import org.axonframework.commandhandling.CommandBus;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.commandhandling.gateway.DefaultCommandGateway;
import org.axonframework.commandhandling.model.Repository;
import org.axonframework.config.Configuration;
import org.axonframework.config.Configurer;
import org.axonframework.eventhandling.EventBus;
import org.axonframework.eventhandling.saga.ResourceInjector;
import org.axonframework.messaging.Message;
import org.axonframework.messaging.correlation.CorrelationDataProvider;
import org.axonframework.monitoring.MessageMonitor;
import org.axonframework.spring.saga.SpringResourceInjector;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Bean;
import java.util.List;
import java.util.function.Supplier;
@org.springframework.context.annotation.Configuration
public class AxonConfiguration implements Configuration, InitializingBean, ApplicationContextAware, SmartLifecycle {
private Configuration config;
private final Configurer configurer;
private volatile boolean running = false;
public AxonConfiguration(Configurer configurer) {
this.configurer = configurer;
}
@NoBeanOfType(CommandBus.class)
@Bean
public CommandBus commandBus() {
return config.commandBus();
}
@NoBeanOfType(EventBus.class)
@Bean
@Override
public EventBus eventBus() {
return config.eventBus();
}
@NoBeanOfType(ResourceInjector.class)
@Bean
@Override
public ResourceInjector resourceInjector() {
return new SpringResourceInjector();
}
@NoBeanOfType(CommandGateway.class)
@Bean
public CommandGateway commandGateway(CommandBus commandBus) {
return new DefaultCommandGateway(commandBus);
}
@Override
public <T> Repository<T> repository(Class<T> aggregate) {
return config.repository(aggregate);
}
@Override
public <T> T getComponent(Class<T> componentType, Supplier<T> defaultImpl) {
return config.getComponent(componentType, defaultImpl);
}
@Override
public <M extends Message<?>> MessageMonitor<? super M> messageMonitor(Class<?> componentType, String componentName) {
return config.messageMonitor(componentType, componentName);
}
@Override
public List<CorrelationDataProvider> correlationDataProviders() {
return config.correlationDataProviders();
}
@Override
public void start() {
config.start();
this.running = true;
}
@Override
public void shutdown() {
config.shutdown();
}
@Override
public void stop() {
shutdown();
this.running = false;
}
@Override
public boolean isRunning() {
return running;
}
@Override
public boolean isAutoStartup() {
return true;
}
@Override
public void stop(Runnable callback) {
stop();
callback.run();
}
@Override
public int getPhase() {
return 0;
}
@Override
public void afterPropertiesSet() throws Exception {
// TODO: Build configurer based on blocks available in context
config = configurer.buildConfiguration();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
configurer.registerComponent(ApplicationContext.class, c -> applicationContext);
}
}