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/12/11 14:11:42 UTC

[shardingsphere] branch master updated: Refactor AgentServiceLoader (#22809)

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 00a3b480420 Refactor AgentServiceLoader (#22809)
00a3b480420 is described below

commit 00a3b480420d178ea2541bcf08bf915ecacf2bf1
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Dec 11 22:11:35 2022 +0800

    Refactor AgentServiceLoader (#22809)
---
 .../apache/shardingsphere/agent/core/spi/AgentServiceLoader.java   | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java
index cd07edf4c13..f5ed142165e 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java
@@ -50,14 +50,13 @@ public final class AgentServiceLoader<T> {
      */
     @SuppressWarnings("unchecked")
     public static <T> AgentServiceLoader<T> getServiceLoader(final Class<T> service) {
-        Preconditions.checkNotNull(service, "Extension clazz is null");
-        Preconditions.checkArgument(service.isInterface(), "Extension clazz `%s` is not interface", service);
+        Preconditions.checkNotNull(service, "Extension clazz is null.");
+        Preconditions.checkArgument(service.isInterface(), "Extension clazz `%s` is not interface.", service);
         AgentServiceLoader<T> agentServiceLoader = (AgentServiceLoader<T>) LOADERS.get(service);
         if (null != agentServiceLoader) {
             return agentServiceLoader;
         }
-        LOADERS.putIfAbsent(service, new AgentServiceLoader<>(service));
-        return (AgentServiceLoader<T>) LOADERS.get(service);
+        return (AgentServiceLoader<T>) LOADERS.computeIfAbsent(service, AgentServiceLoader::new);
     }
     
     /**