|
19 | 19 |
|
20 | 20 | import io.shardingsphere.core.config.DataSourceConfiguration;
|
21 | 21 | import io.shardingsphere.core.event.ShardingEventBusInstance;
|
| 22 | +import io.shardingsphere.core.rule.Authentication; |
22 | 23 | import io.shardingsphere.core.rule.ShardingRule;
|
| 24 | +import io.shardingsphere.orchestration.internal.event.config.ConfigurationChangedEvent; |
23 | 25 | import io.shardingsphere.orchestration.internal.event.config.MasterSlaveConfigurationChangedEvent;
|
24 | 26 | import io.shardingsphere.orchestration.internal.event.config.ShardingConfigurationChangedEvent;
|
25 | 27 | import io.shardingsphere.orchestration.internal.listener.ListenerManager;
|
|
29 | 31 | import io.shardingsphere.orchestration.reg.listener.EventListener;
|
30 | 32 |
|
31 | 33 | import java.util.Map;
|
| 34 | +import java.util.Properties; |
32 | 35 |
|
33 | 36 | /**
|
34 | 37 | * Configuration listener manager.
|
@@ -116,22 +119,23 @@ private void watchProxy(final String path) {
|
116 | 119 | @Override
|
117 | 120 | public void onChange(final DataChangedEvent event) {
|
118 | 121 | if (DataChangedEvent.Type.UPDATED == event.getEventType()) {
|
119 |
| - if (configService.isShardingRule(shardingSchemaName)) { |
120 |
| - Map<String, DataSourceConfiguration> dataSourceParameterMap = dataSourceService.getAvailableDataSourceConfigurations(shardingSchemaName); |
121 |
| - ShardingConfigurationChangedEvent shardingEvent = new ShardingConfigurationChangedEvent( |
122 |
| - shardingSchemaName, dataSourceParameterMap, |
123 |
| - new ShardingRule(dataSourceService.getAvailableShardingRuleConfiguration(shardingSchemaName), dataSourceParameterMap.keySet()), |
124 |
| - configService.loadAuthentication(), configService.loadProperties()); |
125 |
| - ShardingEventBusInstance.getInstance().post(shardingEvent); |
126 |
| - } else { |
127 |
| - MasterSlaveConfigurationChangedEvent masterSlaveEvent = new MasterSlaveConfigurationChangedEvent( |
128 |
| - shardingSchemaName, dataSourceService.getAvailableDataSourceConfigurations(shardingSchemaName), |
129 |
| - dataSourceService.getAvailableMasterSlaveRuleConfiguration(shardingSchemaName), |
130 |
| - configService.loadAuthentication(), configService.loadProperties()); |
131 |
| - ShardingEventBusInstance.getInstance().post(masterSlaveEvent); |
132 |
| - } |
| 122 | + Map<String, DataSourceConfiguration> dataSourceConfigurations = dataSourceService.getAvailableDataSourceConfigurations(shardingSchemaName); |
| 123 | + Authentication authentication = configService.loadAuthentication(); |
| 124 | + Properties props = configService.loadProperties(); |
| 125 | + ShardingEventBusInstance.getInstance().post(configService.isShardingRule(shardingSchemaName) |
| 126 | + ? getShardingEvent(dataSourceConfigurations, authentication, props) : getMasterSlaveEvent(dataSourceConfigurations, authentication, props)); |
133 | 127 | }
|
134 | 128 | }
|
| 129 | + |
| 130 | + private ConfigurationChangedEvent getShardingEvent(final Map<String, DataSourceConfiguration> dataSourceConfigurations, final Authentication authentication, final Properties props) { |
| 131 | + return new ShardingConfigurationChangedEvent(shardingSchemaName, dataSourceConfigurations, |
| 132 | + new ShardingRule(dataSourceService.getAvailableShardingRuleConfiguration(shardingSchemaName), dataSourceConfigurations.keySet()), authentication, props); |
| 133 | + } |
| 134 | + |
| 135 | + private ConfigurationChangedEvent getMasterSlaveEvent(final Map<String, DataSourceConfiguration> dataSourceConfigurations, final Authentication authentication, final Properties props) { |
| 136 | + return new MasterSlaveConfigurationChangedEvent(shardingSchemaName, dataSourceConfigurations, |
| 137 | + dataSourceService.getAvailableMasterSlaveRuleConfiguration(shardingSchemaName), authentication, props); |
| 138 | + } |
135 | 139 | });
|
136 | 140 | }
|
137 | 141 | }
|
0 commit comments