From 26fc4a4ae9536db4838a9ea57a925962997d450b Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 2 Dec 2018 23:59:53 +0800 Subject: [PATCH] synchronized for renew --- .../datasource/AbstractOrchestrationDataSource.java | 2 +- .../OrchestrationMasterSlaveDataSource.java | 8 ++++---- .../datasource/OrchestrationShardingDataSource.java | 12 ++++++------ .../internal/rule/OrchestrationMasterSlaveRule.java | 2 +- .../shardingproxy/runtime/GlobalRegistry.java | 10 +++++----- .../shardingproxy/runtime/schema/LogicSchema.java | 8 ++++---- .../runtime/schema/MasterSlaveSchema.java | 10 +++++----- .../shardingproxy/runtime/schema/ShardingSchema.java | 10 +++++----- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/AbstractOrchestrationDataSource.java b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/AbstractOrchestrationDataSource.java index 28ba42238473b..cbd38b0881501 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/AbstractOrchestrationDataSource.java +++ b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/AbstractOrchestrationDataSource.java @@ -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(); } } diff --git a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationMasterSlaveDataSource.java b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationMasterSlaveDataSource.java index 3370bf75867fe..85b31064c0bf1 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationMasterSlaveDataSource.java +++ b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationMasterSlaveDataSource.java @@ -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()); } @@ -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 originalDataSourceConfigurations = DataSourceConverter.getDataSourceConfigurationMap(dataSource.getDataSourceMap()); Map newDataSourceConfigurations = dataSourceChangedEvent.getDataSourceConfigurations(); Map result = new LinkedHashMap<>(); @@ -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()); } @@ -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()); } diff --git a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationShardingDataSource.java b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationShardingDataSource.java index a5c2ef08387e6..0b0eeb97c34c5 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationShardingDataSource.java +++ b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationShardingDataSource.java @@ -95,7 +95,7 @@ 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()); } @@ -103,13 +103,13 @@ public final void renew(final ShardingRuleChangedEvent shardingRuleChangedEvent) /** * 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()); } @@ -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()); } @@ -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()); } diff --git a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationMasterSlaveRule.java b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationMasterSlaveRule.java index 41dfc4ccd97fe..9152e6a33a7cb 100644 --- a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationMasterSlaveRule.java +++ b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationMasterSlaveRule.java @@ -61,7 +61,7 @@ public Collection 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)); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java index 6e94bf0cc9487..5ca5cdb222b99 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java @@ -175,7 +175,7 @@ public List 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()); } @@ -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(); } @@ -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(); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/schema/LogicSchema.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/schema/LogicSchema.java index f942a8e67a183..f14333292a068 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/schema/LogicSchema.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/schema/LogicSchema.java @@ -70,16 +70,16 @@ protected final Map getDataSourceURLs(final Map disabledDataSourceNames = disabledStateChangedEvent.getDisabledGroup().getDataSourceNames(getName()); for (MasterSlaveRule each : shardingRule.getMasterSlaveRules()) { OrchestrationShardingSchemaGroup orchestrationShardingSchemaGroup = new OrchestrationShardingSchemaGroup();