Skip to content

Commit

Permalink
synchronized for renew
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Dec 2, 2018
1 parent 2e3c38e commit 26fc4a4
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public AbstractOrchestrationDataSource(final ShardingOrchestrationFacade shardin
* @param circuitStateChangedEvent circuit state changed event
*/
@Subscribe
public void renew(final CircuitStateChangedEvent circuitStateChangedEvent) {
public final synchronized void renew(final CircuitStateChangedEvent circuitStateChangedEvent) {
isCircuitBreak = circuitStateChangedEvent.isCircuitBreak();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public final void close() {
* @throws SQLException SQL exception
*/
@Subscribe
public final void renew(final MasterSlaveRuleChangedEvent masterSlaveRuleChangedEvent) throws SQLException {
public final synchronized void renew(final MasterSlaveRuleChangedEvent masterSlaveRuleChangedEvent) throws SQLException {
dataSource = new MasterSlaveDataSource(dataSource.getDataSourceMap(),
masterSlaveRuleChangedEvent.getMasterSlaveRuleConfiguration(), ConfigMapContext.getInstance().getConfigMap(), dataSource.getShardingProperties().getProps());
}
Expand All @@ -113,7 +113,7 @@ public final void renew(final MasterSlaveRuleChangedEvent masterSlaveRuleChanged
*/
@Subscribe
@SneakyThrows
public final void renew(final DataSourceChangedEvent dataSourceChangedEvent) {
public final synchronized void renew(final DataSourceChangedEvent dataSourceChangedEvent) {
Map<String, DataSourceConfiguration> originalDataSourceConfigurations = DataSourceConverter.getDataSourceConfigurationMap(dataSource.getDataSourceMap());
Map<String, DataSourceConfiguration> newDataSourceConfigurations = dataSourceChangedEvent.getDataSourceConfigurations();
Map<String, DataSource> result = new LinkedHashMap<>();
Expand All @@ -136,7 +136,7 @@ public final void renew(final DataSourceChangedEvent dataSourceChangedEvent) {
*/
@SneakyThrows
@Subscribe
public final void renew(final PropertiesChangedEvent propertiesChangedEvent) {
public final synchronized void renew(final PropertiesChangedEvent propertiesChangedEvent) {
dataSource = new MasterSlaveDataSource(dataSource.getDataSourceMap(), dataSource.getMasterSlaveRule(), ConfigMapContext.getInstance().getConfigMap(), propertiesChangedEvent.getProps());
}

Expand All @@ -146,7 +146,7 @@ public final void renew(final PropertiesChangedEvent propertiesChangedEvent) {
* @param configMapChangedEvent config map changed event
*/
@Subscribe
public final void renew(final ConfigMapChangedEvent configMapChangedEvent) {
public final synchronized void renew(final ConfigMapChangedEvent configMapChangedEvent) {
ConfigMapContext.getInstance().getConfigMap().clear();
ConfigMapContext.getInstance().getConfigMap().putAll(configMapChangedEvent.getConfigMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ public final void close() {
*/
@Subscribe
@SneakyThrows
public final void renew(final ShardingRuleChangedEvent shardingRuleChangedEvent) {
public final synchronized void renew(final ShardingRuleChangedEvent shardingRuleChangedEvent) {
dataSource = new ShardingDataSource(dataSource.getDataSourceMap(), new ShardingRule(shardingRuleChangedEvent.getShardingRuleConfiguration(),
dataSource.getDataSourceMap().keySet()), ConfigMapContext.getInstance().getConfigMap(), dataSource.getShardingContext().getShardingProperties().getProps());
}

/**
* Renew sharding data source.
*
* @param dataSourceEvent data source changed event
* @param dataSourceChangedEvent data source changed event
*/
@Subscribe
@SneakyThrows
public final void renew(final DataSourceChangedEvent dataSourceEvent) {
public final synchronized void renew(final DataSourceChangedEvent dataSourceChangedEvent) {
dataSource.close();
dataSource = new ShardingDataSource(DataSourceConverter.getDataSourceMap(dataSourceEvent.getDataSourceConfigurations()), dataSource.getShardingContext().getShardingRule(),
dataSource = new ShardingDataSource(DataSourceConverter.getDataSourceMap(dataSourceChangedEvent.getDataSourceConfigurations()), dataSource.getShardingContext().getShardingRule(),
ConfigMapContext.getInstance().getConfigMap(), dataSource.getShardingContext().getShardingProperties().getProps());
}

Expand All @@ -120,7 +120,7 @@ public final void renew(final DataSourceChangedEvent dataSourceEvent) {
*/
@SneakyThrows
@Subscribe
public void renew(final PropertiesChangedEvent propertiesChangedEvent) {
public final synchronized void renew(final PropertiesChangedEvent propertiesChangedEvent) {
dataSource = new ShardingDataSource(dataSource.getDataSourceMap(),
dataSource.getShardingContext().getShardingRule(), ConfigMapContext.getInstance().getConfigMap(), propertiesChangedEvent.getProps());
}
Expand All @@ -131,7 +131,7 @@ public void renew(final PropertiesChangedEvent propertiesChangedEvent) {
* @param configMapChangedEvent config map changed event
*/
@Subscribe
public final void renew(final ConfigMapChangedEvent configMapChangedEvent) {
public final synchronized void renew(final ConfigMapChangedEvent configMapChangedEvent) {
ConfigMapContext.getInstance().getConfigMap().clear();
ConfigMapContext.getInstance().getConfigMap().putAll(configMapChangedEvent.getConfigMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Collection<String> getSlaveDataSourceNames() {
* @param disabledStateChangedEvent disabled state changed event
*/
@Subscribe
public void renew(final DisabledStateChangedEvent disabledStateChangedEvent) {
public synchronized void renew(final DisabledStateChangedEvent disabledStateChangedEvent) {
disabledDataSourceNames.clear();
disabledDataSourceNames.addAll(disabledStateChangedEvent.getDisabledGroup().getDataSourceNames(ShardingConstant.LOGIC_SCHEMA_NAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public List<String> getSchemaNames() {
* @param propertiesChangedEvent properties changed event
*/
@Subscribe
public void renew(final PropertiesChangedEvent propertiesChangedEvent) {
public synchronized void renew(final PropertiesChangedEvent propertiesChangedEvent) {
shardingProperties = new ShardingProperties(propertiesChangedEvent.getProps());
}

Expand All @@ -185,7 +185,7 @@ public void renew(final PropertiesChangedEvent propertiesChangedEvent) {
* @param authenticationChangedEvent authentication changed event
*/
@Subscribe
public void renew(final AuthenticationChangedEvent authenticationChangedEvent) {
public synchronized void renew(final AuthenticationChangedEvent authenticationChangedEvent) {
authentication = authenticationChangedEvent.getAuthentication();
}

Expand All @@ -195,18 +195,18 @@ public void renew(final AuthenticationChangedEvent authenticationChangedEvent) {
* @param configMapChangedEvent config map changed event
*/
@Subscribe
public void renew(final ConfigMapChangedEvent configMapChangedEvent) {
public synchronized void renew(final ConfigMapChangedEvent configMapChangedEvent) {
ConfigMapContext.getInstance().getConfigMap().clear();
ConfigMapContext.getInstance().getConfigMap().putAll(configMapChangedEvent.getConfigMap());
}

/**
* Renew circuit breaker data source names.
* Renew circuit breaker state.
*
* @param circuitStateChangedEvent circuit state changed event
*/
@Subscribe
public void renewCircuitBreakerDataSourceNames(final CircuitStateChangedEvent circuitStateChangedEvent) {
public synchronized void renew(final CircuitStateChangedEvent circuitStateChangedEvent) {
isCircuitBreak = circuitStateChangedEvent.isCircuitBreak();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ protected final Map<String, String> getDataSourceURLs(final Map<String, DataSour
/**
* Renew data source configuration.
*
* @param dataSourceEvent data source event.
* @param dataSourceChangedEvent data source changed event.
*/
@Subscribe
public final void renew(final DataSourceChangedEvent dataSourceEvent) {
if (!name.equals(dataSourceEvent.getShardingSchemaName())) {
public final synchronized void renew(final DataSourceChangedEvent dataSourceChangedEvent) {
if (!name.equals(dataSourceChangedEvent.getShardingSchemaName())) {
return;
}
backendDataSource.close();
dataSources.clear();
dataSources.putAll(DataSourceConverter.getDataSourceParameterMap(dataSourceEvent.getDataSourceConfigurations()));
dataSources.putAll(DataSourceConverter.getDataSourceParameterMap(dataSourceChangedEvent.getDataSourceConfigurations()));
backendDataSource = new JDBCBackendDataSource(dataSources);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ private ShardingMetaData getShardingMetaData() {
/**
* Renew master-slave rule.
*
* @param masterSlaveEvent master-slave event.
* @param masterSlaveRuleChangedEvent master-slave rule changed event.
*/
@Subscribe
public void renew(final MasterSlaveRuleChangedEvent masterSlaveEvent) {
if (!getName().equals(masterSlaveEvent.getShardingSchemaName())) {
public synchronized void renew(final MasterSlaveRuleChangedEvent masterSlaveRuleChangedEvent) {
if (!getName().equals(masterSlaveRuleChangedEvent.getShardingSchemaName())) {
return;
}
masterSlaveRule = new OrchestrationMasterSlaveRule(masterSlaveEvent.getMasterSlaveRuleConfiguration());
masterSlaveRule = new OrchestrationMasterSlaveRule(masterSlaveRuleChangedEvent.getMasterSlaveRuleConfiguration());
}

/**
Expand All @@ -85,7 +85,7 @@ public void renew(final MasterSlaveRuleChangedEvent masterSlaveEvent) {
* @param disabledStateChangedEvent disabled state changed event
*/
@Subscribe
public void renew(final DisabledStateChangedEvent disabledStateChangedEvent) {
public synchronized void renew(final DisabledStateChangedEvent disabledStateChangedEvent) {
OrchestrationShardingSchemaGroup orchestrationShardingSchemaGroup = new OrchestrationShardingSchemaGroup();
orchestrationShardingSchemaGroup.put(ShardingConstant.LOGIC_SCHEMA_NAME, disabledStateChangedEvent.getDisabledGroup().getDataSourceNames(getName()));
((OrchestrationMasterSlaveRule) masterSlaveRule).renew(new DisabledStateChangedEvent(orchestrationShardingSchemaGroup));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ private ShardingMetaData getShardingMetaData() {
/**
* Renew sharding rule.
*
* @param shardingEvent sharding event.
* @param shardingRuleChangedEvent sharding rule changed event.
*/
@Subscribe
public void renew(final ShardingRuleChangedEvent shardingEvent) {
if (!getName().equals(shardingEvent.getShardingSchemaName())) {
public synchronized void renew(final ShardingRuleChangedEvent shardingRuleChangedEvent) {
if (!getName().equals(shardingRuleChangedEvent.getShardingSchemaName())) {
return;
}
shardingRule = new OrchestrationShardingRule(shardingEvent.getShardingRuleConfiguration(), getDataSources().keySet());
shardingRule = new OrchestrationShardingRule(shardingRuleChangedEvent.getShardingRuleConfiguration(), getDataSources().keySet());
}

/**
Expand All @@ -90,7 +90,7 @@ public void renew(final ShardingRuleChangedEvent shardingEvent) {
* @param disabledStateChangedEvent disabled state changed event
*/
@Subscribe
public void renew(final DisabledStateChangedEvent disabledStateChangedEvent) {
public synchronized void renew(final DisabledStateChangedEvent disabledStateChangedEvent) {
Collection<String> disabledDataSourceNames = disabledStateChangedEvent.getDisabledGroup().getDataSourceNames(getName());
for (MasterSlaveRule each : shardingRule.getMasterSlaveRules()) {
OrchestrationShardingSchemaGroup orchestrationShardingSchemaGroup = new OrchestrationShardingSchemaGroup();
Expand Down

0 comments on commit 26fc4a4

Please sign in to comment.