Skip to content

Commit

Permalink
Use ShardingSphereServiceLoader to instead of JDK ServiceLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Oct 24, 2023
1 parent 0878e78 commit 71cf3f9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.elasticjob.restful.deserializer.factory.DeserializerFactory;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;

import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand All @@ -50,10 +50,10 @@ public <T> T deserialize(final Class<T> targetType, final byte[] requestBodyByte
};

static {
for (RequestBodyDeserializer deserializer : ServiceLoader.load(RequestBodyDeserializer.class)) {
for (RequestBodyDeserializer deserializer : ShardingSphereServiceLoader.getServiceInstances(RequestBodyDeserializer.class)) {
REQUEST_BODY_DESERIALIZERS.put(deserializer.mimeType(), deserializer);
}
for (DeserializerFactory factory : ServiceLoader.load(DeserializerFactory.class)) {
for (DeserializerFactory factory : ShardingSphereServiceLoader.getServiceInstances(DeserializerFactory.class)) {
DEFAULT_REQUEST_BODY_DESERIALIZER_FACTORIES.put(factory.mimeType(), factory);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
package org.apache.shardingsphere.elasticjob.restful.deserializer.factory;

import org.apache.shardingsphere.elasticjob.restful.deserializer.RequestBodyDeserializer;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;

/**
* Deserializer factory.
*
* @see RequestBodyDeserializer
* @see org.apache.shardingsphere.elasticjob.restful.deserializer.RequestBodyDeserializerFactory
*/
@SingletonSPI
public interface DeserializerFactory {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

import io.netty.handler.codec.http.HttpHeaderValues;
import org.apache.shardingsphere.elasticjob.restful.deserializer.RequestBodyDeserializer;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;

import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;

/**
* Default deserializer for <code>text/plain</code>.
*/
@SingletonSPI
public final class DefaultTextPlainRequestBodyDeserializer implements RequestBodyDeserializer {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

package org.apache.shardingsphere.elasticjob.restful.serializer;

import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;

/**
* Serializer for serializing response body with specific MIME type.
*/
@SingletonSPI
public interface ResponseBodySerializer {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.elasticjob.restful.serializer.factory.SerializerFactory;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;

import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand All @@ -50,10 +50,10 @@ public byte[] serialize(final Object responseBody) {
};

static {
for (ResponseBodySerializer serializer : ServiceLoader.load(ResponseBodySerializer.class)) {
for (ResponseBodySerializer serializer : ShardingSphereServiceLoader.getServiceInstances(ResponseBodySerializer.class)) {
RESPONSE_BODY_SERIALIZERS.put(serializer.mimeType(), serializer);
}
for (SerializerFactory factory : ServiceLoader.load(SerializerFactory.class)) {
for (SerializerFactory factory : ShardingSphereServiceLoader.getServiceInstances(SerializerFactory.class)) {
RESPONSE_BODY_SERIALIZER_FACTORIES.put(factory.mimeType(), factory);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
package org.apache.shardingsphere.elasticjob.restful.serializer.factory;

import org.apache.shardingsphere.elasticjob.restful.serializer.ResponseBodySerializer;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;

/**
* Serializer factory.
*
* @see ResponseBodySerializer
* @see org.apache.shardingsphere.elasticjob.restful.serializer.ResponseBodySerializerFactory
*/
@SingletonSPI
public interface SerializerFactory {

/**
Expand Down

0 comments on commit 71cf3f9

Please sign in to comment.