diff --git a/services-api/src/main/java/io/scalecube/services/transport/api/DataCodec.java b/services-api/src/main/java/io/scalecube/services/transport/api/DataCodec.java index 38a92086b..6180a7d9d 100644 --- a/services-api/src/main/java/io/scalecube/services/transport/api/DataCodec.java +++ b/services-api/src/main/java/io/scalecube/services/transport/api/DataCodec.java @@ -1,6 +1,5 @@ package io.scalecube.services.transport.api; -import io.scalecube.utils.ServiceLoaderUtil; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -8,14 +7,16 @@ import java.util.Collection; import java.util.Map; import java.util.Objects; +import java.util.ServiceLoader; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.StreamSupport; public interface DataCodec { Map INSTANCES = - ServiceLoaderUtil.findAll(DataCodec.class) + StreamSupport.stream(ServiceLoader.load(DataCodec.class).spliterator(), false) .collect(Collectors.toMap(DataCodec::contentType, Function.identity())); static Collection getAllInstances() { diff --git a/services-api/src/main/java/io/scalecube/services/transport/api/HeadersCodec.java b/services-api/src/main/java/io/scalecube/services/transport/api/HeadersCodec.java index 395c0c002..2cacbd71e 100644 --- a/services-api/src/main/java/io/scalecube/services/transport/api/HeadersCodec.java +++ b/services-api/src/main/java/io/scalecube/services/transport/api/HeadersCodec.java @@ -1,11 +1,12 @@ package io.scalecube.services.transport.api; -import io.scalecube.utils.ServiceLoaderUtil; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Map; +import java.util.ServiceLoader; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.StreamSupport; public interface HeadersCodec { @@ -25,8 +26,9 @@ static HeadersCodec getInstance(String contentType) { * is thrown if not exist) */ static HeadersCodec loadInstance(String contentType) { - return ServiceLoaderUtil.findFirst( - HeadersCodec.class, codec -> codec.contentType().equalsIgnoreCase(contentType)) + return StreamSupport.stream(ServiceLoader.load(HeadersCodec.class).spliterator(), false) + .filter(codec -> codec.contentType().equalsIgnoreCase(contentType)) + .findFirst() .orElseThrow( () -> new IllegalArgumentException( diff --git a/services-api/src/main/java/io/scalecube/services/transport/api/ServiceMessageDataDecoder.java b/services-api/src/main/java/io/scalecube/services/transport/api/ServiceMessageDataDecoder.java index f5fb3239b..cdd09983a 100644 --- a/services-api/src/main/java/io/scalecube/services/transport/api/ServiceMessageDataDecoder.java +++ b/services-api/src/main/java/io/scalecube/services/transport/api/ServiceMessageDataDecoder.java @@ -1,13 +1,16 @@ package io.scalecube.services.transport.api; import io.scalecube.services.api.ServiceMessage; -import io.scalecube.utils.ServiceLoaderUtil; +import java.util.ServiceLoader; import java.util.function.BiFunction; +import java.util.stream.StreamSupport; @FunctionalInterface public interface ServiceMessageDataDecoder extends BiFunction, ServiceMessage> { ServiceMessageDataDecoder INSTANCE = - ServiceLoaderUtil.findFirst(ServiceMessageDataDecoder.class).orElse(null); + StreamSupport.stream(ServiceLoader.load(ServiceMessageDataDecoder.class).spliterator(), false) + .findFirst() + .orElse(null); }