Skip to content

Commit

Permalink
Get rid of ServiceLoaderUtil (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v authored Sep 22, 2024
1 parent fab9192 commit a2812cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 5 additions & 2 deletions cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -300,7 +301,9 @@ private Mono<Cluster> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit a2812cf

Please sign in to comment.