This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 94a9d4c0051 Refactor RuleItemChangedSubscriber, move
RuleItemChangedSubscriber to cluster (#31794)
94a9d4c0051 is described below
commit 94a9d4c00518dae61a4d90daa72c851b3519abf8
Author: Haoran Meng <[email protected]>
AuthorDate: Fri Jun 21 11:49:11 2024 +0800
Refactor RuleItemChangedSubscriber, move RuleItemChangedSubscriber to
cluster (#31794)
---
.../mode/subsciber/RuleItemChangedSubscriber.java | 81 ----------------------
.../ClusterDispatchEventSubscriberRegistry.java | 1 -
.../subscriber/RuleItemChangedSubscriber.java | 54 +++++++++++++++
3 files changed, 54 insertions(+), 82 deletions(-)
diff --git
a/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java
b/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java
deleted file mode 100644
index 61566f762b4..00000000000
---
a/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.subsciber;
-
-import com.google.common.eventbus.Subscribe;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import
org.apache.shardingsphere.infra.rule.event.rule.alter.AlterRuleItemEvent;
-import org.apache.shardingsphere.infra.rule.event.rule.drop.DropRuleItemEvent;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import
org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor;
-
-/**
- * Rule item changed subscriber.
- */
-@RequiredArgsConstructor
-public final class RuleItemChangedSubscriber implements EventSubscriber {
-
- private final ContextManager contextManager;
-
- /**
- * Renew with alter rule item.
- *
- * @param event alter rule item event
- */
- @SuppressWarnings({"rawtypes", "unchecked", "unused"})
- @Subscribe
- public void renew(final AlterRuleItemEvent event) {
- if
(!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService()
- .getActiveVersionByFullPath(event.getActiveVersionKey()))) {
- return;
- }
- RuleItemConfigurationChangedProcessor processor =
TypedSPILoader.getService(RuleItemConfigurationChangedProcessor.class,
event.getType());
- String yamlContent =
-
contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService()
-
.getVersionPathByActiveVersion(event.getActiveVersionKey(),
event.getActiveVersion());
- String databaseName = event.getDatabaseName();
- RuleConfiguration currentRuleConfig =
processor.findRuleConfiguration(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName));
- synchronized (this) {
- processor.changeRuleItemConfiguration(event, currentRuleConfig,
processor.swapRuleItemConfiguration(event, yamlContent));
-
contextManager.getMetaDataContextManager().getConfigurationManager().alterRuleConfiguration(databaseName,
currentRuleConfig);
- }
- }
-
- /**
- * Renew with drop rule item.
- *
- * @param event drop rule item event
- */
- @SuppressWarnings({"rawtypes", "unchecked", "unused"})
- @Subscribe
- public void renew(final DropRuleItemEvent event) {
- String databaseName = event.getDatabaseName();
- if
(!contextManager.getMetaDataContexts().getMetaData().containsDatabase(databaseName))
{
- return;
- }
- RuleItemConfigurationChangedProcessor processor =
TypedSPILoader.getService(RuleItemConfigurationChangedProcessor.class,
event.getType());
- RuleConfiguration currentRuleConfig =
processor.findRuleConfiguration(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName));
- synchronized (this) {
- processor.dropRuleItemConfiguration(event, currentRuleConfig);
-
contextManager.getMetaDataContextManager().getConfigurationManager().dropRuleConfiguration(databaseName,
currentRuleConfig);
- }
- }
-}
diff --git
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterDispatchEventSubscriberRegistry.java
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterDispatchEventSubscriberRegistry.java
index 4cc88ee90c2..f2f02eff017 100644
---
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterDispatchEventSubscriberRegistry.java
+++
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterDispatchEventSubscriberRegistry.java
@@ -27,7 +27,6 @@ import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.nodes
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.subscriber.ProcessListChangedSubscriber;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import org.apache.shardingsphere.mode.subsciber.EventSubscriberRegistry;
-import org.apache.shardingsphere.mode.subsciber.RuleItemChangedSubscriber;
import java.util.Arrays;
import java.util.Collection;
diff --git
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/RuleItemChangedSubscriber.java
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/RuleItemChangedSubscriber.java
new file mode 100644
index 00000000000..bf0b2bd8110
--- /dev/null
+++
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/RuleItemChangedSubscriber.java
@@ -0,0 +1,54 @@
+/*
+ * 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.manager.cluster.coordinator.subscriber;
+
+import com.google.common.eventbus.Subscribe;
+import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.infra.rule.event.rule.alter.AlterRuleItemEvent;
+import org.apache.shardingsphere.infra.rule.event.rule.drop.DropRuleItemEvent;
+import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+
+/**
+ * Rule item changed subscriber.
+ */
+@RequiredArgsConstructor
+public final class RuleItemChangedSubscriber implements EventSubscriber {
+
+ private final ContextManager contextManager;
+
+ /**
+ * Renew with alter rule item.
+ *
+ * @param event alter rule item event
+ */
+ @Subscribe
+ public void renew(final AlterRuleItemEvent event) {
+
contextManager.getMetaDataContextManager().getRuleItemManager().alterRuleItem(event);
+ }
+
+ /**
+ * Renew with drop rule item.
+ *
+ * @param event drop rule item event
+ */
+ @Subscribe
+ public void renew(final DropRuleItemEvent event) {
+
contextManager.getMetaDataContextManager().getRuleItemManager().dropRuleItem(event);
+ }
+}