You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/04/30 03:58:57 UTC

[shardingsphere] branch master updated: Add DefaultGlobalRuleConfigurationBuilderFactory (#17220)

This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng 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 fa4877ad104 Add DefaultGlobalRuleConfigurationBuilderFactory (#17220)
fa4877ad104 is described below

commit fa4877ad1048015f29327c28392e287f20add616
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 30 11:58:50 2022 +0800

    Add DefaultGlobalRuleConfigurationBuilderFactory (#17220)
---
 ...faultGlobalRuleConfigurationBuilderFactory.java | 48 ++++++++++++++++++++++
 .../rule/builder/global/GlobalRulesBuilder.java    |  9 +---
 2 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactory.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactory.java
new file mode 100644
index 00000000000..40d444b884e
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactory.java
@@ -0,0 +1,48 @@
+/*
+ * 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.infra.rule.builder.global;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Default global rule configuration builder factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DefaultGlobalRuleConfigurationBuilderFactory {
+    
+    static {
+        ShardingSphereServiceLoader.register(DefaultGlobalRuleConfigurationBuilder.class);
+    }
+    
+    /**
+     * Create new instance default global rule configuration builder.
+     *
+     * @param globalRuleBuilders global rule builders
+     * @return new instance default global rule configuration builder
+     */
+    @SuppressWarnings("rawtypes")
+    public static Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> newInstance(final Collection<GlobalRuleBuilder> globalRuleBuilders) {
+        return OrderedSPIRegistry.getRegisteredServices(DefaultGlobalRuleConfigurationBuilder.class, globalRuleBuilders);
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
index 24195ae86f9..65f8c4e49b1 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
@@ -22,8 +22,6 @@ import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
 
 import java.util.Collection;
 import java.util.LinkedHashMap;
@@ -38,10 +36,6 @@ import java.util.stream.Collectors;
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class GlobalRulesBuilder {
     
-    static {
-        ShardingSphereServiceLoader.register(DefaultGlobalRuleConfigurationBuilder.class);
-    }
-    
     /**
      * Build rules.
      *
@@ -69,8 +63,7 @@ public final class GlobalRulesBuilder {
     @SuppressWarnings("rawtypes")
     private static Map<RuleConfiguration, GlobalRuleBuilder> getMissedDefaultRuleBuilderMap(final Map<RuleConfiguration, GlobalRuleBuilder> builders) {
         Map<RuleConfiguration, GlobalRuleBuilder> result = new LinkedHashMap<>();
-        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> defaultBuilders =
-                OrderedSPIRegistry.getRegisteredServices(DefaultGlobalRuleConfigurationBuilder.class, getMissedDefaultRuleBuilders(builders.values()));
+        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> defaultBuilders = DefaultGlobalRuleConfigurationBuilderFactory.newInstance(getMissedDefaultRuleBuilders(builders.values()));
         for (Entry<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> entry : defaultBuilders.entrySet()) {
             result.put(entry.getValue().build(), entry.getKey());
         }