Skip to content

Commit

Permalink
Get rid of ServiceLoaderUtil (#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v authored Sep 22, 2024
1 parent c5d8917 commit eda1057
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
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.lang.reflect.Type;
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<String, DataCodec> INSTANCES =
ServiceLoaderUtil.findAll(DataCodec.class)
StreamSupport.stream(ServiceLoader.load(DataCodec.class).spliterator(), false)
.collect(Collectors.toMap(DataCodec::contentType, Function.identity()));

static Collection<DataCodec> getAllInstances() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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, Class<?>, ServiceMessage> {

ServiceMessageDataDecoder INSTANCE =
ServiceLoaderUtil.findFirst(ServiceMessageDataDecoder.class).orElse(null);
StreamSupport.stream(ServiceLoader.load(ServiceMessageDataDecoder.class).spliterator(), false)
.findFirst()
.orElse(null);
}

0 comments on commit eda1057

Please sign in to comment.