Skip to content

Commit

Permalink
chore:use serializer instead of codec (apache#2097)
Browse files Browse the repository at this point in the history
  • Loading branch information
leizhiyuan authored and lovepoem committed Jan 10, 2020
1 parent 028d9bd commit b179c78
Show file tree
Hide file tree
Showing 208 changed files with 741 additions and 737 deletions.
16 changes: 8 additions & 8 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-codec-seata</artifactId>
<artifactId>seata-serializer-seata</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-codec-protobuf</artifactId>
<artifactId>seata-serializer-protobuf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand All @@ -249,12 +249,12 @@
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-codec-kryo</artifactId>
<artifactId>seata-serializer-kryo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-codec-hessian</artifactId>
<artifactId>seata-serializer-hessian</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -624,10 +624,10 @@
<include>io.seata:seata-spring</include>
<include>io.seata:seata-tcc</include>
<include>io.seata:seata-tm</include>
<include>io.seata:seata-codec-seata</include>
<include>io.seata:seata-codec-protobuf</include>
<include>io.seata:seata-codec-kryo</include>
<include>io.seata:seata-codec-hessian</include>
<include>io.seata:seata-serializer-seata</include>
<include>io.seata:seata-serializer-protobuf</include>
<include>io.seata:seata-serializer-kryo</include>
<include>io.seata:seata-serializer-hessian</include>
<!-- saga -->
<include>io.seata:seata-saga-processctrl</include>
<include>io.seata:seata-saga-statelang</include>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ coverage:
precision: 2
range: "50...100"
ignore:
- "codec/seata-codec-protobuf/src/main/java/io/seata/codec/protobuf/generated"
- "codec/seata-serializer-protobuf/src/main/java/io/seata/serializer/protobuf/generated"
- "test/.*"
- ".github/.*"
- ".mvn/.*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package io.seata.core.protocol;

import io.seata.config.ConfigurationFactory;
import io.seata.core.codec.CodecType;
import io.seata.core.serializer.SerializerType;
import io.seata.core.compressor.CompressorType;
import io.seata.core.constants.ConfigurationKeys;

Expand Down Expand Up @@ -73,10 +73,10 @@ public class ProtocolConstants {
/**
* Configured codec by user, default is SEATA
*
* @see CodecType#SEATA
* @see SerializerType#SEATA
*/
public static final byte CONFIGURED_CODEC = CodecType.getByName(ConfigurationFactory.getInstance()
.getConfig(ConfigurationKeys.SERIALIZE_FOR_RPC, CodecType.SEATA.name())).getCode();
public static final byte CONFIGURED_CODEC = SerializerType.getByName(ConfigurationFactory.getInstance()
.getConfig(ConfigurationKeys.SERIALIZE_FOR_RPC, SerializerType.SEATA.name())).getCode();

/**
* Configured compressor by user, default is NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.seata.core.codec.Codec;
import io.seata.core.codec.CodecFactory;
import io.seata.core.serializer.Serializer;
import io.seata.core.serializer.SerializerFactory;
import io.seata.core.compressor.Compressor;
import io.seata.core.compressor.CompressorFactory;
import io.seata.core.protocol.HeartbeatMessage;
Expand Down Expand Up @@ -137,8 +137,8 @@ public Object decodeFrame(ByteBuf frame) {
frame.readBytes(bs);
Compressor compressor = CompressorFactory.getCompressor(compressorType);
bs = compressor.decompress(bs);
Codec codec = CodecFactory.getCodec(codecType);
rpcMessage.setBody(codec.decode(bs));
Serializer serializer = SerializerFactory.getSerializer(codecType);
rpcMessage.setBody(serializer.deserialize(bs));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.seata.core.codec.Codec;
import io.seata.core.codec.CodecFactory;
import io.seata.core.serializer.Serializer;
import io.seata.core.serializer.SerializerFactory;
import io.seata.core.compressor.Compressor;
import io.seata.core.compressor.CompressorFactory;
import io.seata.core.protocol.ProtocolConstants;
Expand Down Expand Up @@ -91,8 +91,8 @@ public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) {
if (messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST
&& messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) {
// heartbeat has no body
Codec codec = CodecFactory.getCodec(rpcMessage.getCodec());
bodyBytes = codec.encode(rpcMessage.getBody());
Serializer serializer = SerializerFactory.getSerializer(rpcMessage.getCodec());
bodyBytes = serializer.serialize(rpcMessage.getBody());
Compressor compressor = CompressorFactory.getCompressor(rpcMessage.getCompressor());
bodyBytes = compressor.compress(bodyBytes);
fullLength += bodyBytes.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.core.codec;
package io.seata.core.serializer;

/**
* The interface Codec.
*
* @author zhangsen
*/
public interface Codec {
public interface Serializer {

/**
* Encode object to byte[].
Expand All @@ -29,7 +29,7 @@ public interface Codec {
* @param t the t
* @return the byte [ ]
*/
<T> byte[] encode(T t);
<T> byte[] serialize(T t);

/**
* Decode t from byte[].
Expand All @@ -38,5 +38,5 @@ public interface Codec {
* @param bytes the bytes
* @return the t
*/
<T> T decode(byte[] bytes);
<T> T deserialize(byte[] bytes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,51 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.core.codec;
package io.seata.core.serializer;

import io.seata.common.loader.EnhancedServiceLoader;

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

import io.seata.common.loader.EnhancedServiceLoader;

/**
* The type Codec factory.
*
* @author zhangsen
*/
public class CodecFactory {
public class SerializerFactory {

/**
* The constant CODEC_MAP.
*/
protected static final Map<CodecType, Codec> CODEC_MAP = new ConcurrentHashMap<CodecType, Codec>();
protected static final Map<SerializerType, Serializer> CODEC_MAP = new ConcurrentHashMap<SerializerType, Serializer>();

/**
* Get codec codec.
* Get serializeCode serializeCode.
*
* @param codec the code
* @return the codec
* @param serializeCode the code
* @return the serializeCode
*/
public static Codec getCodec(byte codec) {
CodecType codecType = CodecType.getByCode(codec);
if (CODEC_MAP.get(codecType) != null) {
return CODEC_MAP.get(codecType);
public static Serializer getSerializer(byte serializeCode) {
SerializerType serializerType = SerializerType.getByCode(serializeCode);
if (CODEC_MAP.get(serializerType) != null) {
return CODEC_MAP.get(serializerType);
}
Codec codecImpl = EnhancedServiceLoader.load(Codec.class, codecType.name());
CODEC_MAP.putIfAbsent(codecType, codecImpl);
Serializer codecImpl = EnhancedServiceLoader.load(Serializer.class, serializerType.name());
CODEC_MAP.putIfAbsent(serializerType, codecImpl);
return codecImpl;
}

/**
* Encode byte [ ].
*
* @param <T> the type parameter
* @param codec the codec
* @param serializeCode the serializeCode
* @param t the t
* @return the byte [ ]
*/
public static <T> byte[] encode(byte codec, T t) {
return getCodec(codec).encode(t);
public static <T> byte[] encode(byte serializeCode, T t) {
return getSerializer(serializeCode).serialize(t);
}

/**
Expand All @@ -69,7 +69,7 @@ public static <T> byte[] encode(byte codec, T t) {
* @return the t
*/
public static <T> T decode(byte codec, byte[] bytes) {
return getCodec(codec).decode(bytes);
return getSerializer(codec).deserialize(bytes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.core.codec;
package io.seata.core.serializer;

/**
* The enum serialize type.
*
* @author leizhiyuan
*/
public enum CodecType {
public enum SerializerType {

/**
* The seata.
Expand All @@ -46,7 +46,7 @@ public enum CodecType {

private final byte code;

CodecType(final byte code) {
SerializerType(final byte code) {
this.code = code;
}

Expand All @@ -56,8 +56,8 @@ public enum CodecType {
* @param code the code
* @return the result code
*/
public static CodecType getByCode(int code) {
for (CodecType b : CodecType.values()) {
public static SerializerType getByCode(int code) {
for (SerializerType b : SerializerType.values()) {
if (code == b.code) {
return b;
}
Expand All @@ -71,8 +71,8 @@ public static CodecType getByCode(int code) {
* @param name the name
* @return the result code
*/
public static CodecType getByName(String name) {
for (CodecType b : CodecType.values()) {
public static SerializerType getByName(String name) {
for (SerializerType b : SerializerType.values()) {
if (b.name().equalsIgnoreCase(name)) {
return b;
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<module>test</module>
<module>tm</module>
<module>metrics</module>
<module>codec</module>
<module>serializer</module>
<module>seata-spring-boot-starter</module>
<module>compressor</module>
<module>saga</module>
Expand Down
2 changes: 1 addition & 1 deletion saga/seata-saga-engine-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-codec-all</artifactId>
<artifactId>seata-serializer-all</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Expand Down
14 changes: 7 additions & 7 deletions codec/pom.xml → serializer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>seata-codec</artifactId>
<artifactId>seata-serializer</artifactId>
<packaging>pom</packaging>
<name>seata-codec ${project.version}</name>
<name>seata-serializer ${project.version}</name>

<modules>
<module>seata-codec-all</module>
<module>seata-codec-protobuf</module>
<module>seata-codec-seata</module>
<module>seata-codec-kryo</module>
<module>seata-codec-hessian</module>
<module>seata-serializer-all</module>
<module>seata-serializer-protobuf</module>
<module>seata-serializer-seata</module>
<module>seata-serializer-kryo</module>
<module>seata-serializer-hessian</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,32 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.seata</groupId>
<artifactId>seata-codec</artifactId>
<artifactId>seata-serializer</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>seata-codec-all</artifactId>
<name>seata-codec-all ${project.version}</name>
<artifactId>seata-serializer-all</artifactId>
<name>seata-serializer-all ${project.version}</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-codec-seata</artifactId>
<artifactId>seata-serializer-seata</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-codec-protobuf</artifactId>
<artifactId>seata-serializer-protobuf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-codec-kryo</artifactId>
<artifactId>seata-serializer-kryo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-serializer-hessian</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>seata-codec</artifactId>
<artifactId>seata-serializer</artifactId>
<groupId>io.seata</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>seata-codec-hessian</artifactId>
<artifactId>seata-serializer-hessian</artifactId>
<dependencies>
<dependency>
<groupId>com.caucho</groupId>
Expand Down
Loading

0 comments on commit b179c78

Please sign in to comment.