-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1343 from tristaZero/dev
Fix the bug of getting NULL Pointer exception when disable datasource from registry.
- Loading branch information
Showing
12 changed files
with
198 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationMasterSlaveRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2016-2018 shardingsphere.io. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* </p> | ||
*/ | ||
|
||
package io.shardingsphere.orchestration.internal.rule; | ||
|
||
import com.google.common.eventbus.Subscribe; | ||
import io.shardingsphere.api.config.MasterSlaveRuleConfiguration; | ||
import io.shardingsphere.core.rule.MasterSlaveRule; | ||
import io.shardingsphere.orchestration.internal.event.state.DisabledStateEventBusEvent; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
|
||
/** | ||
* Orchestration master slave rule. | ||
* | ||
* @author panjuan | ||
*/ | ||
public final class OrchestrationMasterSlaveRule extends MasterSlaveRule { | ||
|
||
private final Collection<String> disabledDataSourceNames = new LinkedList<>(); | ||
|
||
public OrchestrationMasterSlaveRule(final MasterSlaveRuleConfiguration config) { | ||
super(config); | ||
} | ||
|
||
/** | ||
* Get slave data source names. | ||
* | ||
* @return available slave data source name | ||
*/ | ||
@Override | ||
public Collection<String> getSlaveDataSourceNames() { | ||
Collection<String> result = new LinkedList<>(super.getSlaveDataSourceNames()); | ||
for (String each : disabledDataSourceNames) { | ||
result.remove(each); | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Renew disable dataSource names. | ||
* | ||
* @param disabledStateEventBusEvent jdbc disabled event bus event | ||
*/ | ||
@Subscribe | ||
public void renew(final DisabledStateEventBusEvent disabledStateEventBusEvent) { | ||
disabledDataSourceNames.clear(); | ||
disabledDataSourceNames.addAll(disabledStateEventBusEvent.getDisabledDataSourceNames()); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...rc/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationShardingRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2016-2018 shardingsphere.io. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* </p> | ||
*/ | ||
|
||
package io.shardingsphere.orchestration.internal.rule; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.collect.Collections2; | ||
import io.shardingsphere.api.config.MasterSlaveRuleConfiguration; | ||
import io.shardingsphere.api.config.ShardingRuleConfiguration; | ||
import io.shardingsphere.core.rule.MasterSlaveRule; | ||
import io.shardingsphere.core.rule.ShardingRule; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
|
||
/** | ||
* Orchestration sharding rule. | ||
* | ||
* @author panjuan | ||
*/ | ||
public final class OrchestrationShardingRule extends ShardingRule { | ||
|
||
private final Collection<OrchestrationMasterSlaveRule> masterSlaveRules = new LinkedList<>(); | ||
|
||
public OrchestrationShardingRule(final ShardingRuleConfiguration shardingRuleConfig, final Collection<String> dataSourceNames) { | ||
super(shardingRuleConfig, dataSourceNames); | ||
initMasterSlaveRules(shardingRuleConfig); | ||
} | ||
|
||
private void initMasterSlaveRules(final ShardingRuleConfiguration shardingRuleConfig) { | ||
for (MasterSlaveRuleConfiguration each : shardingRuleConfig.getMasterSlaveRuleConfigs()) { | ||
masterSlaveRules.add(new OrchestrationMasterSlaveRule(each)); | ||
} | ||
} | ||
|
||
@Override | ||
public Collection<MasterSlaveRule> getMasterSlaveRules() { | ||
return Collections2.transform(masterSlaveRules, new Function<OrchestrationMasterSlaveRule, MasterSlaveRule>() { | ||
|
||
@Override | ||
public MasterSlaveRule apply(final OrchestrationMasterSlaveRule input) { | ||
return input; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.