-
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.
Revert "Remove RuleItemChangedSubscriber and RuleItemEvent (#34099)"
This reverts commit 0b8df98.
- Loading branch information
1 parent
0b8df98
commit 49effb3
Showing
19 changed files
with
709 additions
and
71 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...rc/main/java/org/apache/shardingsphere/mode/event/dispatch/rule/RuleItemChangedEvent.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,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.shardingsphere.mode.event.dispatch.rule; | ||
|
||
import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; | ||
|
||
/** | ||
* Rule item changed event. | ||
*/ | ||
public interface RuleItemChangedEvent extends DispatchEvent { | ||
|
||
/** | ||
* Get rule item type. | ||
* | ||
* @return rule item type | ||
*/ | ||
String getType(); | ||
} |
39 changes: 39 additions & 0 deletions
39
...ava/org/apache/shardingsphere/mode/event/dispatch/rule/alter/AlterNamedRuleItemEvent.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,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.shardingsphere.mode.event.dispatch.rule.alter; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* Alter named rule item event. | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
public final class AlterNamedRuleItemEvent implements AlterRuleItemEvent { | ||
|
||
private final String databaseName; | ||
|
||
private final String itemName; | ||
|
||
private final String activeVersionKey; | ||
|
||
private final String activeVersion; | ||
|
||
private final String type; | ||
} |
47 changes: 47 additions & 0 deletions
47
...ain/java/org/apache/shardingsphere/mode/event/dispatch/rule/alter/AlterRuleItemEvent.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,47 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.shardingsphere.mode.event.dispatch.rule.alter; | ||
|
||
import org.apache.shardingsphere.mode.event.dispatch.rule.RuleItemChangedEvent; | ||
|
||
/** | ||
* Alter rule item event. | ||
*/ | ||
public interface AlterRuleItemEvent extends RuleItemChangedEvent { | ||
|
||
/** | ||
* Get database name. | ||
* | ||
* @return database name | ||
*/ | ||
String getDatabaseName(); | ||
|
||
/** | ||
* Get active version key. | ||
* | ||
* @return active version key | ||
*/ | ||
String getActiveVersionKey(); | ||
|
||
/** | ||
* Get active version. | ||
* | ||
* @return active version | ||
*/ | ||
String getActiveVersion(); | ||
} |
37 changes: 37 additions & 0 deletions
37
...va/org/apache/shardingsphere/mode/event/dispatch/rule/alter/AlterUniqueRuleItemEvent.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,37 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.shardingsphere.mode.event.dispatch.rule.alter; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* Alter unique rule item event. | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
public final class AlterUniqueRuleItemEvent implements AlterRuleItemEvent { | ||
|
||
private final String databaseName; | ||
|
||
private final String activeVersionKey; | ||
|
||
private final String activeVersion; | ||
|
||
private final String type; | ||
} |
35 changes: 35 additions & 0 deletions
35
.../java/org/apache/shardingsphere/mode/event/dispatch/rule/drop/DropNamedRuleItemEvent.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,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.shardingsphere.mode.event.dispatch.rule.drop; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* Drop named rule item event. | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
public final class DropNamedRuleItemEvent implements DropRuleItemEvent { | ||
|
||
private final String databaseName; | ||
|
||
private final String itemName; | ||
|
||
private final String type; | ||
} |
33 changes: 33 additions & 0 deletions
33
.../main/java/org/apache/shardingsphere/mode/event/dispatch/rule/drop/DropRuleItemEvent.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,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.shardingsphere.mode.event.dispatch.rule.drop; | ||
|
||
import org.apache.shardingsphere.mode.event.dispatch.rule.RuleItemChangedEvent; | ||
|
||
/** | ||
* Drop rule item event. | ||
*/ | ||
public interface DropRuleItemEvent extends RuleItemChangedEvent { | ||
|
||
/** | ||
* Get database name. | ||
* | ||
* @return database name | ||
*/ | ||
String getDatabaseName(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...java/org/apache/shardingsphere/mode/event/dispatch/rule/drop/DropUniqueRuleItemEvent.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,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.shardingsphere.mode.event.dispatch.rule.drop; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* Drop unique rule item event. | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
public final class DropUniqueRuleItemEvent implements DropRuleItemEvent { | ||
|
||
private final String databaseName; | ||
|
||
private final String type; | ||
} |
94 changes: 94 additions & 0 deletions
94
...ache/shardingsphere/mode/event/dispatch/builder/RuleConfigurationChangedEventBuilder.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,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.shardingsphere.mode.event.dispatch.builder; | ||
|
||
import com.google.common.base.Strings; | ||
import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; | ||
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader; | ||
import org.apache.shardingsphere.mode.event.DataChangedEvent; | ||
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; | ||
import org.apache.shardingsphere.mode.event.dispatch.rule.RuleItemChangedEvent; | ||
import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; | ||
import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterUniqueRuleItemEvent; | ||
import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; | ||
import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropUniqueRuleItemEvent; | ||
import org.apache.shardingsphere.mode.path.rule.RuleNodePath; | ||
import org.apache.shardingsphere.mode.path.rule.item.NamedRuleItemNodePath; | ||
import org.apache.shardingsphere.mode.path.rule.item.UniqueRuleItemNodePath; | ||
import org.apache.shardingsphere.mode.spi.RuleNodePathProvider; | ||
|
||
import java.util.Map.Entry; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Rule configuration changed event builder. | ||
*/ | ||
public final class RuleConfigurationChangedEventBuilder { | ||
|
||
/** | ||
* Build rule changed event. | ||
* | ||
* @param databaseName database name | ||
* @param event data changed event | ||
* @return built event | ||
*/ | ||
public Optional<DispatchEvent> build(final String databaseName, final DataChangedEvent event) { | ||
for (RuleNodePathProvider each : ShardingSphereServiceLoader.getServiceInstances(RuleNodePathProvider.class)) { | ||
Optional<DispatchEvent> result = build(each.getRuleNodePath(), databaseName, event); | ||
if (result.isPresent()) { | ||
return result; | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
private Optional<DispatchEvent> build(final RuleNodePath ruleNodePath, final String databaseName, final DataChangedEvent event) { | ||
if (!ruleNodePath.getRoot().isValidatedPath(event.getKey()) || Type.DELETED != event.getType() && Strings.isNullOrEmpty(event.getValue())) { | ||
return Optional.empty(); | ||
} | ||
for (Entry<String, NamedRuleItemNodePath> entry : ruleNodePath.getNamedItems().entrySet()) { | ||
Optional<String> itemName; | ||
if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) { | ||
itemName = entry.getValue().getNameByActiveVersion(event.getKey()); | ||
} else { | ||
itemName = entry.getValue().getNameByItemPath(event.getKey()); | ||
} | ||
if (itemName.isPresent()) { | ||
return Optional.of(create(databaseName, itemName.get(), event, ruleNodePath.getRoot().getRuleType() + "." + entry.getKey())); | ||
} | ||
} | ||
for (Entry<String, UniqueRuleItemNodePath> entry : ruleNodePath.getUniqueItems().entrySet()) { | ||
if (entry.getValue().isActiveVersionPath(event.getKey())) { | ||
return Optional.of(create(databaseName, event, ruleNodePath.getRoot().getRuleType() + "." + entry.getKey())); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
private RuleItemChangedEvent create(final String databaseName, final String itemName, final DataChangedEvent event, final String type) { | ||
return Type.ADDED == event.getType() || Type.UPDATED == event.getType() | ||
? new AlterNamedRuleItemEvent(databaseName, itemName, event.getKey(), event.getValue(), type) | ||
: new DropNamedRuleItemEvent(databaseName, itemName, type); | ||
} | ||
|
||
private RuleItemChangedEvent create(final String databaseName, final DataChangedEvent event, final String type) { | ||
return Type.ADDED == event.getType() || Type.UPDATED == event.getType() | ||
? new AlterUniqueRuleItemEvent(databaseName, event.getKey(), event.getValue(), type) | ||
: new DropUniqueRuleItemEvent(databaseName, type); | ||
} | ||
} |
Oops, something went wrong.