From a2812cffa955f04f66738bb800aed4c9fd218071 Mon Sep 17 00:00:00 2001 From: Artem Vysochyn Date: Sun, 22 Sep 2024 08:52:18 +0300 Subject: [PATCH] Get rid of ServiceLoaderUtil (#393) --- .../java/io/scalecube/cluster/metadata/MetadataCodec.java | 7 +++++-- .../src/main/java/io/scalecube/cluster/ClusterImpl.java | 7 +++++-- .../io/scalecube/cluster/transport/api/MessageCodec.java | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cluster-api/src/main/java/io/scalecube/cluster/metadata/MetadataCodec.java b/cluster-api/src/main/java/io/scalecube/cluster/metadata/MetadataCodec.java index d21fbe99..5346aefd 100644 --- a/cluster-api/src/main/java/io/scalecube/cluster/metadata/MetadataCodec.java +++ b/cluster-api/src/main/java/io/scalecube/cluster/metadata/MetadataCodec.java @@ -1,13 +1,16 @@ package io.scalecube.cluster.metadata; -import io.scalecube.utils.ServiceLoaderUtil; import java.nio.ByteBuffer; +import java.util.ServiceLoader; +import java.util.stream.StreamSupport; /** Contains methods for metadata serializing/deserializing logic. */ public interface MetadataCodec { MetadataCodec INSTANCE = - ServiceLoaderUtil.findFirst(MetadataCodec.class).orElseGet(JdkMetadataCodec::new); + StreamSupport.stream(ServiceLoader.load(MetadataCodec.class).spliterator(), false) + .findFirst() + .orElseGet(JdkMetadataCodec::new); /** * Deserializes metadata from buffer. diff --git a/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java b/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java index 4dee1227..77942be8 100644 --- a/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java +++ b/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java @@ -17,13 +17,13 @@ import io.scalecube.cluster.transport.api.TransportConfig; import io.scalecube.cluster.transport.api.TransportFactory; import io.scalecube.net.Address; -import io.scalecube.utils.ServiceLoaderUtil; import java.io.Serializable; import java.nio.ByteBuffer; import java.util.Collection; import java.util.Collections; import java.util.Objects; import java.util.Optional; +import java.util.ServiceLoader; import java.util.Set; import java.util.UUID; import java.util.function.Function; @@ -32,6 +32,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.stream.StreamSupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.Disposable; @@ -300,7 +301,9 @@ private Mono doStart0() { private void validateConfiguration() { final MetadataCodec metadataCodec = - ServiceLoaderUtil.findFirst(MetadataCodec.class).orElse(null); + StreamSupport.stream(ServiceLoader.load(MetadataCodec.class).spliterator(), false) + .findFirst() + .orElse(null); if (metadataCodec == null) { Object metadata = config.metadata(); diff --git a/transport-parent/transport-api/src/main/java/io/scalecube/cluster/transport/api/MessageCodec.java b/transport-parent/transport-api/src/main/java/io/scalecube/cluster/transport/api/MessageCodec.java index 4292c361..00c1fac6 100644 --- a/transport-parent/transport-api/src/main/java/io/scalecube/cluster/transport/api/MessageCodec.java +++ b/transport-parent/transport-api/src/main/java/io/scalecube/cluster/transport/api/MessageCodec.java @@ -1,14 +1,17 @@ package io.scalecube.cluster.transport.api; -import io.scalecube.utils.ServiceLoaderUtil; import java.io.InputStream; import java.io.OutputStream; +import java.util.ServiceLoader; +import java.util.stream.StreamSupport; /** Contains methods for message serializing/deserializing logic. */ public interface MessageCodec { MessageCodec INSTANCE = - ServiceLoaderUtil.findFirst(MessageCodec.class).orElseGet(JdkMessageCodec::new); + StreamSupport.stream(ServiceLoader.load(MessageCodec.class).spliterator(), false) + .findFirst() + .orElseGet(JdkMessageCodec::new); /** * Deserializes message from given input stream.