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

panjuan 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 0b4aacdc924 Remove PluginBootServiceRegistry (#23386)
0b4aacdc924 is described below

commit 0b4aacdc9244319a463eaded610b1f6883029113
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jan 7 09:41:17 2023 +0800

    Remove PluginBootServiceRegistry (#23386)
---
 .../core/plugin/PluginBootServiceManager.java      | 28 +++++++-----
 .../agent/core/spi/PluginBootServiceRegistry.java  | 51 ----------------------
 2 files changed, 16 insertions(+), 63 deletions(-)

diff --git 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
index 205b9162af8..71f94292894 100644
--- 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
+++ 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
@@ -19,10 +19,11 @@ package org.apache.shardingsphere.agent.core.plugin;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.agent.core.spi.PluginBootServiceRegistry;
 import org.apache.shardingsphere.agent.api.PluginConfiguration;
 import org.apache.shardingsphere.agent.core.logging.LoggerFactory;
 import org.apache.shardingsphere.agent.core.logging.LoggerFactory.Logger;
+import org.apache.shardingsphere.agent.core.spi.AgentServiceLoader;
+import org.apache.shardingsphere.agent.spi.PluginBootService;
 
 import java.io.IOException;
 import java.util.Collection;
@@ -49,29 +50,32 @@ public final class PluginBootServiceManager {
         try {
             Thread.currentThread().setContextClassLoader(agentClassLoader);
             for (Entry<String, PluginConfiguration> entry : 
pluginConfigs.entrySet()) {
-                
PluginBootServiceRegistry.getRegisteredService(entry.getKey()).ifPresent(optional
 -> {
-                    try {
-                        LOGGER.info("Start plugin: {}", optional.getType());
-                        optional.start(entry.getValue(), isEnhancedForProxy);
-                        // CHECKSTYLE:OFF
-                    } catch (final Throwable ex) {
-                        // CHECKSTYLE:ON
-                        LOGGER.error("Failed to start service.", ex);
-                    }
-                });
+                
AgentServiceLoader.getServiceLoader(PluginBootService.class).getServices()
+                        .stream().filter(each -> 
each.getType().equalsIgnoreCase(entry.getKey())).findFirst().ifPresent(optional 
-> startService(entry.getValue(), optional, isEnhancedForProxy));
             }
         } finally {
             Thread.currentThread().setContextClassLoader(originalClassLoader);
         }
     }
     
+    private static void startService(final PluginConfiguration pluginConfig, 
final PluginBootService pluginBootService, final boolean isEnhancedForProxy) {
+        try {
+            LOGGER.info("Start plugin: {}", pluginBootService.getType());
+            pluginBootService.start(pluginConfig, isEnhancedForProxy);
+            // CHECKSTYLE:OFF
+        } catch (final Throwable ex) {
+            // CHECKSTYLE:ON
+            LOGGER.error("Failed to start service.", ex);
+        }
+    }
+    
     /**
      * Close all services.
      * 
      * @param pluginJars plugin jars
      */
     public static void closeAllServices(final Collection<PluginJar> 
pluginJars) {
-        PluginBootServiceRegistry.getAllRegisteredServices().forEach(each -> {
+        
AgentServiceLoader.getServiceLoader(PluginBootService.class).getServices().forEach(each
 -> {
             try {
                 each.close();
                 // CHECKSTYLE:OFF
diff --git 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/PluginBootServiceRegistry.java
 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/PluginBootServiceRegistry.java
deleted file mode 100644
index 2fbaa089b28..00000000000
--- 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/PluginBootServiceRegistry.java
+++ /dev/null
@@ -1,51 +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.agent.core.spi;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.agent.spi.PluginBootService;
-
-import java.util.Collection;
-import java.util.Optional;
-
-/**
- *  Plugin boot service registry.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PluginBootServiceRegistry {
-    
-    /**
-     * Get registered service.
-     *
-     * @param type type
-     * @return registered service
-     */
-    public static Optional<PluginBootService> getRegisteredService(final 
String type) {
-        return 
AgentServiceLoader.getServiceLoader(PluginBootService.class).getServices().stream().filter(each
 -> each.getType().equalsIgnoreCase(type)).findFirst();
-    }
-    
-    /**
-     * Get all registered services.
-     *
-     * @return registered services
-     */
-    public static Collection<PluginBootService> getAllRegisteredServices() {
-        return 
AgentServiceLoader.getServiceLoader(PluginBootService.class).getServices();
-    }
-}

Reply via email to