From 5bff2f2885dfefa0841e162b23ff0746fe2c7cb0 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Tue, 18 Jul 2023 12:38:44 +0800 Subject: [PATCH 01/22] encoder --- .../seata/core/rpc/netty/ProtocolEncoder.java | 122 ++++++++++++++++++ .../rpc/netty/old/ProtocolOldEncoder.java | 122 ++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java new file mode 100644 index 00000000000..0ffadda7064 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java @@ -0,0 +1,122 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import io.seata.core.compressor.Compressor; +import io.seata.core.compressor.CompressorFactory; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.v1.HeadMapSerializer; +import io.seata.core.rpc.netty.v1.ProtocolV1Decoder; +import io.seata.core.serializer.Serializer; +import io.seata.core.serializer.SerializerServiceLoader; +import io.seata.core.serializer.SerializerType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +/** + *
+ * 0     1     2     3     4     5     6     7     8     9    10     11    12    13    14    15    16
+ * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
+ * |   magic   |Proto|     Full length       |    Head   | Msg |Seria|Compr|     RequestId         |
+ * |   code    |colVer|    (head+body)      |   Length  |Type |lizer|ess  |                       |
+ * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
+ * |                                                                                               |
+ * |                                   Head Map [Optional]                                         |
+ * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
+ * |                                                                                               |
+ * |                                         body                                                  |
+ * |                                                                                               |
+ * |                                        ... ...                                                |
+ * +-----------------------------------------------------------------------------------------------+
+ * 
+ *

+ *

  • Full Length: include all data
  • + *
  • Head Length: include head data from magic code to head map.
  • + *
  • Body Length: Full Length - Head Length
  • + *

    + * https://github.com/seata/seata/issues/893 + * + * @author Geng Zhang + * @see ProtocolV1Decoder + * @since 0.7.0 + */ +public class ProtocolEncoder extends MessageToByteEncoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolEncoder.class); + + @Override + public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) { + try { + if (msg instanceof RpcMessage) { + RpcMessage rpcMessage = (RpcMessage) msg; + + int fullLength = ProtocolConstants.V1_HEAD_LENGTH; + int headLength = ProtocolConstants.V1_HEAD_LENGTH; + + byte messageType = rpcMessage.getMessageType(); + out.writeBytes(ProtocolConstants.MAGIC_CODE_BYTES); + out.writeByte(ProtocolConstants.VERSION); + // full Length(4B) and head length(2B) will fix in the end. + out.writerIndex(out.writerIndex() + 6); + out.writeByte(messageType); + out.writeByte(rpcMessage.getCodec()); + out.writeByte(rpcMessage.getCompressor()); + out.writeInt(rpcMessage.getId()); + + // direct write head with zero-copy + Map headMap = rpcMessage.getHeadMap(); + if (headMap != null && !headMap.isEmpty()) { + int headMapBytesLength = HeadMapSerializer.getInstance().encode(headMap, out); + headLength += headMapBytesLength; + fullLength += headMapBytesLength; + } + + byte[] bodyBytes = null; + if (messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST + && messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) { + // heartbeat has no body + Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec())); + bodyBytes = serializer.serialize(rpcMessage.getBody()); + Compressor compressor = CompressorFactory.getCompressor(rpcMessage.getCompressor()); + bodyBytes = compressor.compress(bodyBytes); + fullLength += bodyBytes.length; + } + + if (bodyBytes != null) { + out.writeBytes(bodyBytes); + } + + // fix fullLength and headLength + int writeIndex = out.writerIndex(); + // skip magic code(2B) + version(1B) + out.writerIndex(writeIndex - fullLength + 3); + out.writeInt(fullLength); + out.writeShort(headLength); + out.writerIndex(writeIndex); + } else { + throw new UnsupportedOperationException("Not support this class:" + msg.getClass()); + } + } catch (Throwable e) { + LOGGER.error("Encode request error!", e); + } + } +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java new file mode 100644 index 00000000000..097696652f5 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java @@ -0,0 +1,122 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty.old; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import io.seata.core.compressor.Compressor; +import io.seata.core.compressor.CompressorFactory; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.v1.HeadMapSerializer; +import io.seata.core.rpc.netty.v1.ProtocolV1Decoder; +import io.seata.core.serializer.Serializer; +import io.seata.core.serializer.SerializerServiceLoader; +import io.seata.core.serializer.SerializerType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +/** + *
    + * 0     1     2     3     4     5     6     7     8     9    10     11    12    13    14    15    16
    + * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    + * |   magic   |Proto|     Full length       |    Head   | Msg |Seria|Compr|     RequestId         |
    + * |   code    |colVer|    (head+body)      |   Length  |Type |lizer|ess  |                       |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    + * |                                                                                               |
    + * |                                   Head Map [Optional]                                         |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    + * |                                                                                               |
    + * |                                         body                                                  |
    + * |                                                                                               |
    + * |                                        ... ...                                                |
    + * +-----------------------------------------------------------------------------------------------+
    + * 
    + *

    + *

  • Full Length: include all data
  • + *
  • Head Length: include head data from magic code to head map.
  • + *
  • Body Length: Full Length - Head Length
  • + *

    + * https://github.com/seata/seata/issues/893 + * + * @author Geng Zhang + * @see ProtocolV1Decoder + * @since 0.7.0 + */ +public class ProtocolOldEncoder extends MessageToByteEncoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolOldEncoder.class); + + @Override + public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) { + try { + if (msg instanceof RpcMessage) { + RpcMessage rpcMessage = (RpcMessage) msg; + + int fullLength = ProtocolConstants.V1_HEAD_LENGTH; + int headLength = ProtocolConstants.V1_HEAD_LENGTH; + + byte messageType = rpcMessage.getMessageType(); + out.writeBytes(ProtocolConstants.MAGIC_CODE_BYTES); + out.writeByte(ProtocolConstants.VERSION); + // full Length(4B) and head length(2B) will fix in the end. + out.writerIndex(out.writerIndex() + 6); + out.writeByte(messageType); + out.writeByte(rpcMessage.getCodec()); + out.writeByte(rpcMessage.getCompressor()); + out.writeInt(rpcMessage.getId()); + + // direct write head with zero-copy + Map headMap = rpcMessage.getHeadMap(); + if (headMap != null && !headMap.isEmpty()) { + int headMapBytesLength = HeadMapSerializer.getInstance().encode(headMap, out); + headLength += headMapBytesLength; + fullLength += headMapBytesLength; + } + + byte[] bodyBytes = null; + if (messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST + && messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) { + // heartbeat has no body + Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec())); + bodyBytes = serializer.serialize(rpcMessage.getBody()); + Compressor compressor = CompressorFactory.getCompressor(rpcMessage.getCompressor()); + bodyBytes = compressor.compress(bodyBytes); + fullLength += bodyBytes.length; + } + + if (bodyBytes != null) { + out.writeBytes(bodyBytes); + } + + // fix fullLength and headLength + int writeIndex = out.writerIndex(); + // skip magic code(2B) + version(1B) + out.writerIndex(writeIndex - fullLength + 3); + out.writeInt(fullLength); + out.writeShort(headLength); + out.writerIndex(writeIndex); + } else { + throw new UnsupportedOperationException("Not support this class:" + msg.getClass()); + } + } catch (Throwable e) { + LOGGER.error("Encode request error!", e); + } + } +} From c7497c1e167e3db550a546a042c7a74b7cc7686e Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 19 Jul 2023 11:45:43 +0800 Subject: [PATCH 02/22] protocol --- .../core/protocol/ProtocolConstants.java | 5 + .../rpc/netty/CompatibleProtocolDecoder.java | 143 ++++++++++++++++++ .../rpc/netty/CompatibleProtocolEncoder.java | 54 +++++++ .../core/rpc/netty/NettyClientBootstrap.java | 4 +- .../core/rpc/netty/NettyServerBootstrap.java | 6 +- .../seata/core/rpc/netty/ProtocolEncoder.java | 122 --------------- .../rpc/netty/old/ProtocolOldConstants.java | 16 ++ .../rpc/netty/old/ProtocolOldDecoder.java | 139 +++++++++++++++++ .../rpc/netty/old/ProtocolOldEncoder.java | 103 +++---------- .../core/rpc/netty/v1/ProtocolV1Decoder.java | 62 +------- .../core/rpc/netty/v1/ProtocolV1Encoder.java | 21 +-- .../serializer/seata/MessageCodecFactory.java | 56 +++---- .../seata/protocol/old/package-info.java | 1 + .../AbstractIdentifyRequestCodec.java | 2 +- .../AbstractIdentifyResponseCodec.java | 2 +- .../{ => v1}/AbstractMessageCodec.java | 2 +- .../{ => v1}/AbstractResultMessageCodec.java | 2 +- .../{ => v1}/BatchResultMessageCodec.java | 2 +- .../{ => v1}/MergeResultMessageCodec.java | 2 +- .../{ => v1}/MergedWarpMessageCodec.java | 2 +- .../{ => v1}/RegisterRMRequestCodec.java | 2 +- .../{ => v1}/RegisterRMResponseCodec.java | 2 +- .../{ => v1}/RegisterTMRequestCodec.java | 2 +- .../{ => v1}/RegisterTMResponseCodec.java | 2 +- .../AbstractBranchEndRequestCodec.java | 2 +- .../AbstractBranchEndResponseCodec.java | 2 +- .../AbstractGlobalEndRequestCodec.java | 2 +- .../AbstractGlobalEndResponseCodec.java | 2 +- .../AbstractTransactionRequestCodec.java | 4 +- .../AbstractTransactionRequestToRMCodec.java | 2 +- .../AbstractTransactionRequestToTCCodec.java | 2 +- .../AbstractTransactionResponseCodec.java | 4 +- .../transaction/BranchCommitRequestCodec.java | 2 +- .../BranchCommitResponseCodec.java | 2 +- .../BranchRegisterRequestCodec.java | 2 +- .../BranchRegisterResponseCodec.java | 2 +- .../transaction/BranchReportRequestCodec.java | 2 +- .../BranchReportResponseCodec.java | 2 +- .../BranchRollbackRequestCodec.java | 2 +- .../BranchRollbackResponseCodec.java | 2 +- .../transaction/GlobalBeginRequestCodec.java | 2 +- .../transaction/GlobalBeginResponseCodec.java | 2 +- .../transaction/GlobalCommitRequestCodec.java | 2 +- .../GlobalCommitResponseCodec.java | 2 +- .../GlobalLockQueryRequestCodec.java | 2 +- .../GlobalLockQueryResponseCodec.java | 2 +- .../transaction/GlobalReportRequestCodec.java | 2 +- .../GlobalReportResponseCodec.java | 2 +- .../GlobalRollbackRequestCodec.java | 2 +- .../GlobalRollbackResponseCodec.java | 2 +- .../transaction/GlobalStatusRequestCodec.java | 2 +- .../GlobalStatusResponseCodec.java | 2 +- .../UndoLogDeleteRequestCodec.java | 2 +- .../core/rpc/netty/v1/ProtocolV1Client.java | 6 +- .../core/rpc/netty/v1/ProtocolV1Server.java | 6 +- 55 files changed, 479 insertions(+), 349 deletions(-) create mode 100644 core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java delete mode 100644 core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldConstants.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/old/package-info.java rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/AbstractIdentifyRequestCodec.java (98%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/AbstractIdentifyResponseCodec.java (97%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/AbstractMessageCodec.java (97%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/AbstractResultMessageCodec.java (98%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/BatchResultMessageCodec.java (98%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/MergeResultMessageCodec.java (98%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/MergedWarpMessageCodec.java (98%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/RegisterRMRequestCodec.java (98%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/RegisterRMResponseCodec.java (95%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/RegisterTMRequestCodec.java (95%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/RegisterTMResponseCodec.java (95%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/AbstractBranchEndRequestCodec.java (98%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/AbstractBranchEndResponseCodec.java (97%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/AbstractGlobalEndRequestCodec.java (97%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/AbstractGlobalEndResponseCodec.java (96%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/AbstractTransactionRequestCodec.java (88%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/AbstractTransactionRequestToRMCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/AbstractTransactionRequestToTCCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/AbstractTransactionResponseCodec.java (93%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/BranchCommitRequestCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/BranchCommitResponseCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/BranchRegisterRequestCodec.java (98%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/BranchRegisterResponseCodec.java (96%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/BranchReportRequestCodec.java (98%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/BranchReportResponseCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/BranchRollbackRequestCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/BranchRollbackResponseCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalBeginRequestCodec.java (97%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalBeginResponseCodec.java (97%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalCommitRequestCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalCommitResponseCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalLockQueryRequestCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalLockQueryResponseCodec.java (96%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalReportRequestCodec.java (96%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalReportResponseCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalRollbackRequestCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalRollbackResponseCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalStatusRequestCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/GlobalStatusResponseCodec.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{ => v1}/transaction/UndoLogDeleteRequestCodec.java (97%) diff --git a/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java b/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java index ef5d9a4ddd6..6684f3c980a 100644 --- a/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java +++ b/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java @@ -31,6 +31,11 @@ public interface ProtocolConstants { */ byte[] MAGIC_CODE_BYTES = {(byte) 0xda, (byte) 0xda}; + /** + * Old protocol version + */ + byte OLD_VERSION = 0; + /** * Protocol version */ diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java new file mode 100644 index 00000000000..5a92b9afe8b --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java @@ -0,0 +1,143 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.LengthFieldBasedFrameDecoder; +import io.seata.core.compressor.Compressor; +import io.seata.core.compressor.CompressorFactory; +import io.seata.core.exception.DecodeException; +import io.seata.core.protocol.HeartbeatMessage; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.old.ProtocolOldDecoder; +import io.seata.core.rpc.netty.v1.ProtocolV1Decoder; +import io.seata.core.serializer.Serializer; +import io.seata.core.serializer.SerializerServiceLoader; +import io.seata.core.serializer.SerializerType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + *
    + * (> 0.7.0)
    + * 0     1     2     3     4     5     6     7     8     9    10     11    12    13    14    15    16
    + * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    + * |   magic   |Proto|     Full length       |    Head   | Msg |Seria|Compr|     RequestId         |
    + * |   code    |colVer|    (head+body)      |   Length  |Type |lizer|ess  |                       |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    + *
    + * (<= 0.7.0)
    + * 0     1     2     3     4           6           8          10           12          14
    + * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    + * |   0xdada  |   flag    | typecode/ |                 requestid                     |
    + * |           |           | bodylength|                                               |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    + *
    + * 
    + *

    + *

  • Full Length: include all data
  • + *
  • Head Length: include head data from magic code to head map.
  • + *
  • Body Length: Full Length - Head Length
  • + *

    + * https://github.com/seata/seata/issues/893 + * + * @author minghua.xie + * @since 2.0.0 + */ +public class CompatibleProtocolDecoder extends LengthFieldBasedFrameDecoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(CompatibleProtocolDecoder.class); + + public CompatibleProtocolDecoder() { + // default is 8M + this(ProtocolConstants.MAX_FRAME_LENGTH); + } + + public CompatibleProtocolDecoder(int maxFrameLength) { + /* + int maxFrameLength, + int lengthFieldOffset, magic code is 2B, and version is 1B, and then FullLength. so value is 3 + int lengthFieldLength, FullLength is int(4B). so values is 4 + int lengthAdjustment, FullLength include all data and read 7 bytes before, so the left length is (FullLength-7). so values is -7 + int initialBytesToStrip we will check magic code and version self, so do not strip any bytes. so values is 0 + */ + super(maxFrameLength, 3, 4, -7, 0); + } + + @Override + protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { + Object decoded; + try { + decoded = super.decode(ctx, in); + if (decoded instanceof ByteBuf) { + ByteBuf frame = (ByteBuf)decoded; + try { + byte version = decideVersion(frame); + if(version == ProtocolConstants.OLD_VERSION){ + return ProtocolOldDecoder.decodeFrame(frame); + }else if(version == ProtocolConstants.VERSION){ + return ProtocolV1Decoder.decodeFrame(frame); + }else { + throw new IllegalArgumentException("Unknown version: " + version ); + } + + } finally { + frame.release(); + } + } + } catch (Exception exx) { + LOGGER.error("Decode frame error, cause: {}", exx.getMessage()); + throw new DecodeException(exx); + } + return decoded; + } + + protected byte decideVersion(ByteBuf frame) { + frame.markReaderIndex(); + byte b0 = frame.readByte(); + byte b1 = frame.readByte(); + if (ProtocolConstants.MAGIC_CODE_BYTES[0] != b0 + || ProtocolConstants.MAGIC_CODE_BYTES[1] != b1) { + throw new IllegalArgumentException("Unknown magic code: " + b0 + ", " + b1); + } + + byte version = frame.readByte(); + frame.resetReaderIndex(); + return version; + } + + + public static Object getBody(ByteBuf frame, byte messageType, byte compressorType, byte codecType, int bodyLength) { + Object body = null; + if (messageType == ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST) { + body = HeartbeatMessage.PING; + } else if (messageType == ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) { + body = HeartbeatMessage.PONG; + } else { + if (bodyLength > 0) { + byte[] bs = new byte[bodyLength]; + frame.readBytes(bs); + Compressor compressor = CompressorFactory.getCompressor(compressorType); + bs = compressor.decompress(bs); + Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codecType)); + body = serializer.deserialize(bs); + } + } + return body; + } +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java new file mode 100644 index 00000000000..b129072ef6c --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java @@ -0,0 +1,54 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import io.seata.core.protocol.RpcMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + *
    + * 
    + *

    + *

  • Full Length: include all data
  • + *
  • Head Length: include head data from magic code to head map.
  • + *
  • Body Length: Full Length - Head Length
  • + *

    + * https://github.com/seata/seata/issues/893 + * + * @author minghua.xie + * @since 2.0.0 + */ +public class CompatibleProtocolEncoder extends MessageToByteEncoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(CompatibleProtocolEncoder.class); + + @Override + public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) { + try { + if (msg instanceof RpcMessage) { + // todo 调用子类进行encode,公共逻辑现在没有抽取 + } else { + throw new UnsupportedOperationException("Not support this class:" + msg.getClass()); + } + } catch (Throwable e) { + LOGGER.error("Encode request error!", e); + } + } +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/NettyClientBootstrap.java b/core/src/main/java/io/seata/core/rpc/netty/NettyClientBootstrap.java index 2d52bb51b94..8e44eec36b8 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/NettyClientBootstrap.java +++ b/core/src/main/java/io/seata/core/rpc/netty/NettyClientBootstrap.java @@ -135,8 +135,8 @@ public void initChannel(SocketChannel ch) { new IdleStateHandler(nettyClientConfig.getChannelMaxReadIdleSeconds(), nettyClientConfig.getChannelMaxWriteIdleSeconds(), nettyClientConfig.getChannelMaxAllIdleSeconds())) - .addLast(new ProtocolV1Decoder()) - .addLast(new ProtocolV1Encoder()); + .addLast(new CompatibleProtocolDecoder()) + .addLast(new CompatibleProtocolEncoder()); if (channelHandlers != null) { addChannelPipelineLast(ch, channelHandlers); } diff --git a/core/src/main/java/io/seata/core/rpc/netty/NettyServerBootstrap.java b/core/src/main/java/io/seata/core/rpc/netty/NettyServerBootstrap.java index d41e296ee97..8126bdd31e9 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/NettyServerBootstrap.java +++ b/core/src/main/java/io/seata/core/rpc/netty/NettyServerBootstrap.java @@ -35,8 +35,6 @@ import io.seata.common.thread.NamedThreadFactory; import io.seata.config.ConfigurationFactory; import io.seata.core.rpc.RemotingBootstrap; -import io.seata.core.rpc.netty.v1.ProtocolV1Decoder; -import io.seata.core.rpc.netty.v1.ProtocolV1Encoder; import io.seata.discovery.registry.MultiRegistryFactory; import io.seata.discovery.registry.RegistryService; import org.slf4j.Logger; @@ -156,8 +154,8 @@ public void start() { @Override public void initChannel(SocketChannel ch) { ch.pipeline().addLast(new IdleStateHandler(nettyServerConfig.getChannelMaxReadIdleSeconds(), 0, 0)) - .addLast(new ProtocolV1Decoder()) - .addLast(new ProtocolV1Encoder()); + .addLast(new CompatibleProtocolDecoder()) + .addLast(new CompatibleProtocolEncoder()); if (channelHandlers != null) { addChannelPipelineLast(ch, channelHandlers); } diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java deleted file mode 100644 index 0ffadda7064..00000000000 --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.core.rpc.netty; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import io.seata.core.compressor.Compressor; -import io.seata.core.compressor.CompressorFactory; -import io.seata.core.protocol.ProtocolConstants; -import io.seata.core.protocol.RpcMessage; -import io.seata.core.rpc.netty.v1.HeadMapSerializer; -import io.seata.core.rpc.netty.v1.ProtocolV1Decoder; -import io.seata.core.serializer.Serializer; -import io.seata.core.serializer.SerializerServiceLoader; -import io.seata.core.serializer.SerializerType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; - -/** - *
    - * 0     1     2     3     4     5     6     7     8     9    10     11    12    13    14    15    16
    - * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    - * |   magic   |Proto|     Full length       |    Head   | Msg |Seria|Compr|     RequestId         |
    - * |   code    |colVer|    (head+body)      |   Length  |Type |lizer|ess  |                       |
    - * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    - * |                                                                                               |
    - * |                                   Head Map [Optional]                                         |
    - * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    - * |                                                                                               |
    - * |                                         body                                                  |
    - * |                                                                                               |
    - * |                                        ... ...                                                |
    - * +-----------------------------------------------------------------------------------------------+
    - * 
    - *

    - *

  • Full Length: include all data
  • - *
  • Head Length: include head data from magic code to head map.
  • - *
  • Body Length: Full Length - Head Length
  • - *

    - * https://github.com/seata/seata/issues/893 - * - * @author Geng Zhang - * @see ProtocolV1Decoder - * @since 0.7.0 - */ -public class ProtocolEncoder extends MessageToByteEncoder { - - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolEncoder.class); - - @Override - public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) { - try { - if (msg instanceof RpcMessage) { - RpcMessage rpcMessage = (RpcMessage) msg; - - int fullLength = ProtocolConstants.V1_HEAD_LENGTH; - int headLength = ProtocolConstants.V1_HEAD_LENGTH; - - byte messageType = rpcMessage.getMessageType(); - out.writeBytes(ProtocolConstants.MAGIC_CODE_BYTES); - out.writeByte(ProtocolConstants.VERSION); - // full Length(4B) and head length(2B) will fix in the end. - out.writerIndex(out.writerIndex() + 6); - out.writeByte(messageType); - out.writeByte(rpcMessage.getCodec()); - out.writeByte(rpcMessage.getCompressor()); - out.writeInt(rpcMessage.getId()); - - // direct write head with zero-copy - Map headMap = rpcMessage.getHeadMap(); - if (headMap != null && !headMap.isEmpty()) { - int headMapBytesLength = HeadMapSerializer.getInstance().encode(headMap, out); - headLength += headMapBytesLength; - fullLength += headMapBytesLength; - } - - byte[] bodyBytes = null; - if (messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST - && messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) { - // heartbeat has no body - Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec())); - bodyBytes = serializer.serialize(rpcMessage.getBody()); - Compressor compressor = CompressorFactory.getCompressor(rpcMessage.getCompressor()); - bodyBytes = compressor.compress(bodyBytes); - fullLength += bodyBytes.length; - } - - if (bodyBytes != null) { - out.writeBytes(bodyBytes); - } - - // fix fullLength and headLength - int writeIndex = out.writerIndex(); - // skip magic code(2B) + version(1B) - out.writerIndex(writeIndex - fullLength + 3); - out.writeInt(fullLength); - out.writeShort(headLength); - out.writerIndex(writeIndex); - } else { - throw new UnsupportedOperationException("Not support this class:" + msg.getClass()); - } - } catch (Throwable e) { - LOGGER.error("Encode request error!", e); - } - } -} diff --git a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldConstants.java b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldConstants.java new file mode 100644 index 00000000000..9317cbd391b --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldConstants.java @@ -0,0 +1,16 @@ +package io.seata.core.rpc.netty.old; + +/** + * ? + * + * @author minghua.xie + * @date 2023/7/18 + **/ +public class ProtocolOldConstants { + + public static int HEAD_LENGTH = 14; + public static final int FLAG_REQUEST = 0x80; + public static final int FLAG_ASYNC = 0x40; + public static final int FLAG_HEARTBEAT = 0x20; + public static final int FLAG_SEATA_CODEC = 0x10; +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java new file mode 100644 index 00000000000..179e4331859 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java @@ -0,0 +1,139 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty.old; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.LengthFieldBasedFrameDecoder; +import io.seata.core.compressor.Compressor; +import io.seata.core.compressor.CompressorFactory; +import io.seata.core.compressor.CompressorType; +import io.seata.core.exception.DecodeException; +import io.seata.core.protocol.AbstractMessage; +import io.seata.core.protocol.HeartbeatMessage; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.CompatibleProtocolDecoder; +import io.seata.core.rpc.netty.v1.HeadMapSerializer; +import io.seata.core.rpc.netty.v1.ProtocolV1Encoder; +import io.seata.core.serializer.Serializer; +import io.seata.core.serializer.SerializerServiceLoader; +import io.seata.core.serializer.SerializerType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.ByteBuffer; +import java.util.Map; + +/** + *
    + *  seata-version < 0.7
    + *  Only used in TC receives a request from RM/TM.
    + * 0     1     2     3     4           6           8          10           12          14         16
    + * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    + * |   0xdada  |   flag    | typecode/ |                 requestid                     |           |
    + * |           |           | bodylength|                                               |           |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+           +
    + * |                                    ... ...                                                    |
    + * +                                                                                               +
    + * |                                     body                                                      |
    + * +                                                                                               +
    + * |                                    ... ...                                                    |
    + * +-----------------------------------------------------------------------------------------------+
    + *
    + * 
    + *

    + *

  • flag: msg type
  • + *
  • typecode: action type code
  • + *
  • bodylength: body Length
  • + *
  • requestid: request id
  • + *

    + * + * @author minghua.xie + * @see ProtocolOldEncoder + * @since 2.0.0 + */ +public class ProtocolOldDecoder { + + + + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolOldDecoder.class); + + + public static RpcMessage decodeFrame(ByteBuf frame) { + // todo 旧版本是直接返回跳过了,我们需要保留这个逻辑? +// if (frame.readableBytes() < HEAD_LENGTH) { +// return; +// } + + // todo 这里是为了bodyLength不满足要求时reset,意义是什么? + frame.markReaderIndex(); + + // todo 外层已经判断过了,这里可以跳过 + short protocol = frame.readShort(); + + int flag = (int)frame.readShort(); + + boolean isHeartbeat = (ProtocolOldConstants.FLAG_HEARTBEAT & flag) > 0; + boolean isRequest = (ProtocolOldConstants.FLAG_REQUEST & flag) > 0; + boolean isSeataCodec = (ProtocolOldConstants.FLAG_SEATA_CODEC & flag) > 0; + + // todo 目前看来,旧协议不是seata就是hessian + byte codecType = isSeataCodec?SerializerType.SEATA.getCode():SerializerType.HESSIAN.getCode(); + + short bodyLength = 0; + short typeCode = 0; + if (!isSeataCodec) { bodyLength = frame.readShort(); } else { typeCode = frame.readShort(); } + long msgId = frame.readLong(); + RpcMessage rpcMessage = new RpcMessage(); + rpcMessage.setCompressor(CompressorType.NONE.getCode()); + rpcMessage.setCodec(codecType); + + // todo reqid之前是long的,设置不进去,要把rpcMessage也隔离成两套吗? +// rpcMessage.setId(msgId); + if (isHeartbeat) { + // todo MessageType是新字段,以前其实分了两个字段,一个是isHeartbeat,一个是isRequest + if (isRequest) { + rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST); + rpcMessage.setBody(HeartbeatMessage.PING); + } else { + rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE); + rpcMessage.setBody(HeartbeatMessage.PONG); + } + return rpcMessage; + } + + if (bodyLength > 0 && frame.readableBytes() < bodyLength) { + frame.resetReaderIndex(); + return rpcMessage; + } + + // TODO 怎样知道是不是one way + rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESQUEST_SYNC); + rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY); + + rpcMessage.setBody(CompatibleProtocolDecoder.getBody(frame, rpcMessage.getMessageType(), + rpcMessage.getCompressor(),rpcMessage.getCodec(),bodyLength)); + return rpcMessage; + } + + private static short getShort(byte b0, byte b1) { + ByteBuffer byteBufferX = ByteBuffer.allocate(128); + byteBufferX.put(b0); + byteBufferX.put(b1); + return byteBufferX.getShort(0); + } +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java index 097696652f5..689f03ad38c 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java @@ -17,104 +17,45 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import io.seata.core.compressor.Compressor; -import io.seata.core.compressor.CompressorFactory; -import io.seata.core.protocol.ProtocolConstants; import io.seata.core.protocol.RpcMessage; -import io.seata.core.rpc.netty.v1.HeadMapSerializer; -import io.seata.core.rpc.netty.v1.ProtocolV1Decoder; -import io.seata.core.serializer.Serializer; -import io.seata.core.serializer.SerializerServiceLoader; -import io.seata.core.serializer.SerializerType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Map; - /** *
    - * 0     1     2     3     4     5     6     7     8     9    10     11    12    13    14    15    16
    + *  seata-version < 0.7
    + *  Only used in TC send a request to RM/TM.
    + * 0     1     2     3     4           6           8          10           12          14         16
      * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    - * |   magic   |Proto|     Full length       |    Head   | Msg |Seria|Compr|     RequestId         |
    - * |   code    |colVer|    (head+body)      |   Length  |Type |lizer|ess  |                       |
    - * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    - * |                                                                                               |
    - * |                                   Head Map [Optional]                                         |
    - * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    - * |                                                                                               |
    - * |                                         body                                                  |
    - * |                                                                                               |
    - * |                                        ... ...                                                |
    + * |   0xdada  |   flag    | typecode/ |                 requestid                     |           |
    + * |           |           | bodylength|                                               |           |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+           +
    + * |                                    ... ...                                                    |
    + * +                                                                                               +
    + * |                                     body                                                      |
    + * +                                                                                               +
    + * |                                    ... ...                                                    |
      * +-----------------------------------------------------------------------------------------------+
    + *
      * 
    *

    - *

  • Full Length: include all data
  • - *
  • Head Length: include head data from magic code to head map.
  • - *
  • Body Length: Full Length - Head Length
  • + *
  • flag: msg type
  • + *
  • typecode: action type code
  • + *
  • bodylength: body Length
  • + *
  • requestid: request id
  • *

    - * https://github.com/seata/seata/issues/893 * - * @author Geng Zhang - * @see ProtocolV1Decoder - * @since 0.7.0 + * @author minghua.xie + * @see ProtocolOldDecoder + * @since 2.0.0 */ -public class ProtocolOldEncoder extends MessageToByteEncoder { +public class ProtocolOldEncoder { private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolOldEncoder.class); - @Override - public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) { + public static void encode(ChannelHandlerContext ctx, RpcMessage rpcMessage, ByteBuf out) { try { - if (msg instanceof RpcMessage) { - RpcMessage rpcMessage = (RpcMessage) msg; - - int fullLength = ProtocolConstants.V1_HEAD_LENGTH; - int headLength = ProtocolConstants.V1_HEAD_LENGTH; - - byte messageType = rpcMessage.getMessageType(); - out.writeBytes(ProtocolConstants.MAGIC_CODE_BYTES); - out.writeByte(ProtocolConstants.VERSION); - // full Length(4B) and head length(2B) will fix in the end. - out.writerIndex(out.writerIndex() + 6); - out.writeByte(messageType); - out.writeByte(rpcMessage.getCodec()); - out.writeByte(rpcMessage.getCompressor()); - out.writeInt(rpcMessage.getId()); - - // direct write head with zero-copy - Map headMap = rpcMessage.getHeadMap(); - if (headMap != null && !headMap.isEmpty()) { - int headMapBytesLength = HeadMapSerializer.getInstance().encode(headMap, out); - headLength += headMapBytesLength; - fullLength += headMapBytesLength; - } - - byte[] bodyBytes = null; - if (messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST - && messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) { - // heartbeat has no body - Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec())); - bodyBytes = serializer.serialize(rpcMessage.getBody()); - Compressor compressor = CompressorFactory.getCompressor(rpcMessage.getCompressor()); - bodyBytes = compressor.compress(bodyBytes); - fullLength += bodyBytes.length; - } - - if (bodyBytes != null) { - out.writeBytes(bodyBytes); - } - - // fix fullLength and headLength - int writeIndex = out.writerIndex(); - // skip magic code(2B) + version(1B) - out.writerIndex(writeIndex - fullLength + 3); - out.writeInt(fullLength); - out.writeShort(headLength); - out.writerIndex(writeIndex); - } else { - throw new UnsupportedOperationException("Not support this class:" + msg.getClass()); - } + // todo 按照旧协议方式encode } catch (Throwable e) { LOGGER.error("Encode request error!", e); } diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java index fa34cb16c51..2c3ba775216 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java @@ -16,9 +16,7 @@ package io.seata.core.rpc.netty.v1; import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.LengthFieldBasedFrameDecoder; -import io.seata.core.exception.DecodeException; +import io.seata.core.rpc.netty.CompatibleProtocolDecoder; import io.seata.core.serializer.Serializer; import io.seata.core.compressor.Compressor; import io.seata.core.compressor.CompressorFactory; @@ -59,47 +57,11 @@ * @see ProtocolV1Encoder * @since 0.7.0 */ -public class ProtocolV1Decoder extends LengthFieldBasedFrameDecoder { +public class ProtocolV1Decoder{ private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV1Decoder.class); - public ProtocolV1Decoder() { - // default is 8M - this(ProtocolConstants.MAX_FRAME_LENGTH); - } - - public ProtocolV1Decoder(int maxFrameLength) { - /* - int maxFrameLength, - int lengthFieldOffset, magic code is 2B, and version is 1B, and then FullLength. so value is 3 - int lengthFieldLength, FullLength is int(4B). so values is 4 - int lengthAdjustment, FullLength include all data and read 7 bytes before, so the left length is (FullLength-7). so values is -7 - int initialBytesToStrip we will check magic code and version self, so do not strip any bytes. so values is 0 - */ - super(maxFrameLength, 3, 4, -7, 0); - } - - @Override - protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { - Object decoded; - try { - decoded = super.decode(ctx, in); - if (decoded instanceof ByteBuf) { - ByteBuf frame = (ByteBuf)decoded; - try { - return decodeFrame(frame); - } finally { - frame.release(); - } - } - } catch (Exception exx) { - LOGGER.error("Decode frame error, cause: {}", exx.getMessage()); - throw new DecodeException(exx); - } - return decoded; - } - - public Object decodeFrame(ByteBuf frame) { + public static Object decodeFrame(ByteBuf frame) { byte b0 = frame.readByte(); byte b1 = frame.readByte(); if (ProtocolConstants.MAGIC_CODE_BYTES[0] != b0 @@ -131,22 +93,10 @@ public Object decodeFrame(ByteBuf frame) { } // read body - if (messageType == ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST) { - rpcMessage.setBody(HeartbeatMessage.PING); - } else if (messageType == ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) { - rpcMessage.setBody(HeartbeatMessage.PONG); - } else { - int bodyLength = fullLength - headLength; - if (bodyLength > 0) { - byte[] bs = new byte[bodyLength]; - frame.readBytes(bs); - Compressor compressor = CompressorFactory.getCompressor(compressorType); - bs = compressor.decompress(bs); - Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec())); - rpcMessage.setBody(serializer.deserialize(bs)); - } - } + int bodyLength = fullLength - headLength; + rpcMessage.setBody(CompatibleProtocolDecoder.getBody(frame, messageType, compressorType, codecType, bodyLength)); return rpcMessage; } + } diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java index 9a775af09be..522ff8835d8 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java @@ -17,7 +17,8 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; +import io.seata.core.rpc.netty.CompatibleProtocolEncoder; +import io.seata.core.rpc.netty.old.ProtocolOldEncoder; import io.seata.core.serializer.Serializer; import io.seata.core.compressor.Compressor; import io.seata.core.compressor.CompressorFactory; @@ -57,15 +58,15 @@ * @see ProtocolV1Decoder * @since 0.7.0 */ -public class ProtocolV1Encoder extends MessageToByteEncoder { +public class ProtocolV1Encoder{ - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV1Encoder.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolOldEncoder.class); - @Override - public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) { + public static void encode(RpcMessage rpcMessage, ByteBuf out) { try { - if (msg instanceof RpcMessage) { - RpcMessage rpcMessage = (RpcMessage) msg; + // todo 外层已经判断好,可以去掉 +// if (msg instanceof RpcMessage) { +// RpcMessage rpcMessage = (RpcMessage) msg; int fullLength = ProtocolConstants.V1_HEAD_LENGTH; int headLength = ProtocolConstants.V1_HEAD_LENGTH; @@ -110,9 +111,9 @@ public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) { out.writeInt(fullLength); out.writeShort(headLength); out.writerIndex(writeIndex); - } else { - throw new UnsupportedOperationException("Not support this class:" + msg.getClass()); - } +// } else { +// throw new UnsupportedOperationException("Not support this class:" + msg.getClass()); +// } } catch (Throwable e) { LOGGER.error("Encode request error!", e); } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java index e40253fd322..612b550d16c 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java @@ -18,34 +18,34 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import io.seata.serializer.seata.protocol.BatchResultMessageCodec; -import io.seata.serializer.seata.protocol.MergeResultMessageCodec; -import io.seata.serializer.seata.protocol.MergedWarpMessageCodec; -import io.seata.serializer.seata.protocol.RegisterRMRequestCodec; -import io.seata.serializer.seata.protocol.RegisterRMResponseCodec; -import io.seata.serializer.seata.protocol.RegisterTMRequestCodec; -import io.seata.serializer.seata.protocol.RegisterTMResponseCodec; -import io.seata.serializer.seata.protocol.transaction.BranchCommitRequestCodec; -import io.seata.serializer.seata.protocol.transaction.BranchCommitResponseCodec; -import io.seata.serializer.seata.protocol.transaction.BranchRegisterRequestCodec; -import io.seata.serializer.seata.protocol.transaction.BranchRegisterResponseCodec; -import io.seata.serializer.seata.protocol.transaction.BranchReportRequestCodec; -import io.seata.serializer.seata.protocol.transaction.BranchReportResponseCodec; -import io.seata.serializer.seata.protocol.transaction.BranchRollbackRequestCodec; -import io.seata.serializer.seata.protocol.transaction.BranchRollbackResponseCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalBeginRequestCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalBeginResponseCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalCommitRequestCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalCommitResponseCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalLockQueryRequestCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalLockQueryResponseCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalReportRequestCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalReportResponseCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalRollbackRequestCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalRollbackResponseCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalStatusRequestCodec; -import io.seata.serializer.seata.protocol.transaction.GlobalStatusResponseCodec; -import io.seata.serializer.seata.protocol.transaction.UndoLogDeleteRequestCodec; +import io.seata.serializer.seata.protocol.v1.BatchResultMessageCodec; +import io.seata.serializer.seata.protocol.v1.MergeResultMessageCodec; +import io.seata.serializer.seata.protocol.v1.MergedWarpMessageCodec; +import io.seata.serializer.seata.protocol.v1.RegisterRMRequestCodec; +import io.seata.serializer.seata.protocol.v1.RegisterRMResponseCodec; +import io.seata.serializer.seata.protocol.v1.RegisterTMRequestCodec; +import io.seata.serializer.seata.protocol.v1.RegisterTMResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchCommitRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchCommitResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchRegisterRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchRegisterResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchReportRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchReportResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchRollbackRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchRollbackResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalBeginRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalBeginResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalCommitRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalCommitResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalLockQueryRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalLockQueryResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalReportRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalReportResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalRollbackRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalRollbackResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalStatusRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalStatusResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.UndoLogDeleteRequestCodec; import io.seata.core.protocol.AbstractMessage; import io.seata.core.protocol.BatchResultMessage; import io.seata.core.protocol.MergeResultMessage; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/old/package-info.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/old/package-info.java new file mode 100644 index 00000000000..07dbe9823ea --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/old/package-info.java @@ -0,0 +1 @@ +package io.seata.serializer.seata.protocol.old; \ No newline at end of file diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractIdentifyRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java similarity index 98% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractIdentifyRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java index 0ec122e075c..663bdf9f55a 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractIdentifyRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractIdentifyResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyResponseCodec.java similarity index 97% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractIdentifyResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyResponseCodec.java index 29e1fb7cfbb..152a8c36625 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractIdentifyResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractMessageCodec.java similarity index 97% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractMessageCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractMessageCodec.java index efdb2dcad80..7810dcaae22 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractMessageCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import io.seata.serializer.seata.MessageSeataCodec; import org.slf4j.Logger; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractResultMessageCodec.java similarity index 98% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractResultMessageCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractResultMessageCodec.java index dbd1bc9a320..57319124e2c 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/AbstractResultMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractResultMessageCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/BatchResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/BatchResultMessageCodec.java similarity index 98% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/BatchResultMessageCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/BatchResultMessageCodec.java index f2f211d7439..ccbf67f5742 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/BatchResultMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/BatchResultMessageCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import java.nio.ByteBuffer; import java.util.ArrayList; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/MergeResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergeResultMessageCodec.java similarity index 98% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/MergeResultMessageCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergeResultMessageCodec.java index 9290d5da986..074b2d3a095 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/MergeResultMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergeResultMessageCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/MergedWarpMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergedWarpMessageCodec.java similarity index 98% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/MergedWarpMessageCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergedWarpMessageCodec.java index d8e97d88e11..0bd7b184caa 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/MergedWarpMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergedWarpMessageCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import java.nio.ByteBuffer; import java.util.ArrayList; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterRMRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterRMRequestCodec.java similarity index 98% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterRMRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterRMRequestCodec.java index ea098161094..5fd9094d4dd 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterRMRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterRMRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterRMResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterRMResponseCodec.java similarity index 95% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterRMResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterRMResponseCodec.java index 6f34f10e6a7..5d90d4a3fb3 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterRMResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterRMResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import io.seata.core.protocol.RegisterRMResponse; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterTMRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterTMRequestCodec.java similarity index 95% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterTMRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterTMRequestCodec.java index b3c8796b9fc..9490cb10099 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterTMRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterTMRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import io.seata.core.protocol.RegisterTMRequest; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterTMResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterTMResponseCodec.java similarity index 95% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterTMResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterTMResponseCodec.java index 118c42f7648..686423bcc61 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/RegisterTMResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/RegisterTMResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol; +package io.seata.serializer.seata.protocol.v1; import io.seata.core.protocol.RegisterTMResponse; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractBranchEndRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractBranchEndRequestCodec.java similarity index 98% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractBranchEndRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractBranchEndRequestCodec.java index 9cb19b2e4ea..12ac865fcc1 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractBranchEndRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractBranchEndRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractBranchEndResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractBranchEndResponseCodec.java similarity index 97% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractBranchEndResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractBranchEndResponseCodec.java index 7f23a015c9a..261cdd43ebd 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractBranchEndResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractBranchEndResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractGlobalEndRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractGlobalEndRequestCodec.java similarity index 97% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractGlobalEndRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractGlobalEndRequestCodec.java index 4c1457c3dd6..5346e89519e 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractGlobalEndRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractGlobalEndRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractGlobalEndResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractGlobalEndResponseCodec.java similarity index 96% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractGlobalEndResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractGlobalEndResponseCodec.java index 3f79c29905f..50b8621dd79 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractGlobalEndResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractGlobalEndResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionRequestCodec.java similarity index 88% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionRequestCodec.java index c79f77d868a..6a52893ce6c 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionRequestCodec.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; -import io.seata.serializer.seata.protocol.AbstractMessageCodec; +import io.seata.serializer.seata.protocol.v1.AbstractMessageCodec; import io.seata.core.protocol.transaction.AbstractTransactionRequest; /** diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionRequestToRMCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionRequestToRMCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionRequestToRMCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionRequestToRMCodec.java index 87bf909c7ef..652828a27fe 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionRequestToRMCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionRequestToRMCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.AbstractTransactionRequestToRM; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionRequestToTCCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionRequestToTCCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionRequestToTCCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionRequestToTCCodec.java index ef5a12bdb69..b39068fc6dd 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionRequestToTCCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionRequestToTCCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.AbstractTransactionRequestToTC; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionResponseCodec.java similarity index 93% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionResponseCodec.java index e1fda9343ec..cece8b784de 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/AbstractTransactionResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/AbstractTransactionResponseCodec.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; import io.netty.buffer.ByteBuf; -import io.seata.serializer.seata.protocol.AbstractResultMessageCodec; +import io.seata.serializer.seata.protocol.v1.AbstractResultMessageCodec; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.transaction.AbstractTransactionResponse; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchCommitRequestCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchCommitRequestCodec.java index 8e10f199a35..04548e33eb7 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchCommitRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.BranchCommitRequest; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchCommitResponseCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchCommitResponseCodec.java index b65c6957b56..6130463d9d4 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchCommitResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.BranchCommitResponse; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRegisterRequestCodec.java similarity index 98% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRegisterRequestCodec.java index 0741a45a7aa..d07664aa768 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRegisterRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRegisterResponseCodec.java similarity index 96% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRegisterResponseCodec.java index cade2a78a50..498c7faa408 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRegisterResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.io.Serializable; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchReportRequestCodec.java similarity index 98% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchReportRequestCodec.java index 0b34a38ce2c..aef03edb12b 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchReportRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchReportResponseCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchReportResponseCodec.java index 4fbaa6c4f4a..de5bc324267 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchReportResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.BranchReportResponse; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRollbackRequestCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRollbackRequestCodec.java index 801b1da6f0d..a041676c478 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRollbackRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.BranchRollbackRequest; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRollbackResponseCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRollbackResponseCodec.java index 31b0b86c5d9..6d20ebc2261 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/BranchRollbackResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.BranchRollbackResponse; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalBeginRequestCodec.java similarity index 97% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalBeginRequestCodec.java index 3f84a3967f8..f36c14b28f9 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalBeginRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalBeginResponseCodec.java similarity index 97% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalBeginResponseCodec.java index ce2fdeeec78..2cb33bcbc35 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalBeginResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalCommitRequestCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalCommitRequestCodec.java index 38fb5305dd6..ad29c7cdf40 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalCommitRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.GlobalCommitRequest; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalCommitResponseCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalCommitResponseCodec.java index 783f1f4bf49..22d949fde45 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalCommitResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.GlobalCommitResponse; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalLockQueryRequestCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalLockQueryRequestCodec.java index 0f5ff42e221..975ecf7f699 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalLockQueryRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.GlobalLockQueryRequest; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalLockQueryResponseCodec.java similarity index 96% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalLockQueryResponseCodec.java index 83d8b31847d..75e89648e90 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalLockQueryResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalReportRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalReportRequestCodec.java similarity index 96% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalReportRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalReportRequestCodec.java index ce972a8d758..74317213d5f 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalReportRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalReportRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.netty.buffer.ByteBuf; import io.seata.core.model.GlobalStatus; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalReportResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalReportResponseCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalReportResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalReportResponseCodec.java index 8e0e8979b99..3b2914d8657 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalReportResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalReportResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.GlobalReportResponse; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalRollbackRequestCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalRollbackRequestCodec.java index f867bfa88cf..799b940af2f 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalRollbackRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.GlobalRollbackRequest; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalRollbackResponseCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalRollbackResponseCodec.java index d8d07b3ec52..01435f6fca5 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalRollbackResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.GlobalRollbackResponse; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalStatusRequestCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalStatusRequestCodec.java index 905e5c23923..1ccbb1def21 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalStatusRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.GlobalStatusRequest; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalStatusResponseCodec.java similarity index 94% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalStatusResponseCodec.java index d4320693e26..edb4a639bcd 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/GlobalStatusResponseCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import io.seata.core.protocol.transaction.GlobalStatusResponse; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/UndoLogDeleteRequestCodec.java similarity index 97% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestCodec.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/UndoLogDeleteRequestCodec.java index 7da2df6d58d..e09c8f13434 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/transaction/UndoLogDeleteRequestCodec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.serializer.seata.protocol.transaction; +package io.seata.serializer.seata.protocol.v1.transaction; import java.nio.ByteBuffer; diff --git a/test/src/test/java/io/seata/core/rpc/netty/v1/ProtocolV1Client.java b/test/src/test/java/io/seata/core/rpc/netty/v1/ProtocolV1Client.java index 3b3c8c39894..ab61be1aa26 100644 --- a/test/src/test/java/io/seata/core/rpc/netty/v1/ProtocolV1Client.java +++ b/test/src/test/java/io/seata/core/rpc/netty/v1/ProtocolV1Client.java @@ -30,6 +30,8 @@ import io.netty.util.concurrent.DefaultPromise; import io.seata.common.thread.NamedThreadFactory; import io.seata.common.thread.PositiveAtomicCounter; +import io.seata.core.rpc.netty.CompatibleProtocolDecoder; +import io.seata.core.rpc.netty.CompatibleProtocolEncoder; import io.seata.core.serializer.SerializerType; import io.seata.core.model.BranchType; import io.seata.core.protocol.ProtocolConstants; @@ -80,8 +82,8 @@ public void connect(String host, int port, int connectTimeout) { @Override protected void initChannel(Channel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); - pipeline.addLast(new ProtocolV1Encoder()); - pipeline.addLast(new ProtocolV1Decoder(8 * 1024 * 1024)); + pipeline.addLast(new CompatibleProtocolEncoder()); + pipeline.addLast(new CompatibleProtocolDecoder(8 * 1024 * 1024)); pipeline.addLast(new ClientChannelHandler(ProtocolV1Client.this)); } }); diff --git a/test/src/test/java/io/seata/core/rpc/netty/v1/ProtocolV1Server.java b/test/src/test/java/io/seata/core/rpc/netty/v1/ProtocolV1Server.java index ed359183e88..2d150bbe9a9 100644 --- a/test/src/test/java/io/seata/core/rpc/netty/v1/ProtocolV1Server.java +++ b/test/src/test/java/io/seata/core/rpc/netty/v1/ProtocolV1Server.java @@ -31,6 +31,8 @@ import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; import io.seata.common.thread.NamedThreadFactory; +import io.seata.core.rpc.netty.CompatibleProtocolDecoder; +import io.seata.core.rpc.netty.CompatibleProtocolEncoder; import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; @@ -67,8 +69,8 @@ public void start() { @Override protected void initChannel(Channel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); - pipeline.addLast(new ProtocolV1Decoder(8 * 1024 * 1024)); - pipeline.addLast(new ProtocolV1Encoder()); + pipeline.addLast(new CompatibleProtocolDecoder(8 * 1024 * 1024)); + pipeline.addLast(new CompatibleProtocolEncoder()); pipeline.addLast(new ServerChannelHandler()); } }); From ed03135f52f65aee92191dbba2f1749d21434d45 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 19 Jul 2023 16:33:47 +0800 Subject: [PATCH 03/22] protocol --- .../rpc/netty/old/MessageCodecHandler.java | 221 ++++++++++++++++++ .../rpc/netty/old/ProtocolOldDecoder.java | 16 +- 2 files changed, 228 insertions(+), 9 deletions(-) create mode 100644 core/src/main/java/io/seata/core/rpc/netty/old/MessageCodecHandler.java diff --git a/core/src/main/java/io/seata/core/rpc/netty/old/MessageCodecHandler.java b/core/src/main/java/io/seata/core/rpc/netty/old/MessageCodecHandler.java new file mode 100644 index 00000000000..b74e9c724f4 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/old/MessageCodecHandler.java @@ -0,0 +1,221 @@ +///* +// * Copyright 1999-2019 Seata.io Group. +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// */ +//package io.seata.core.rpc.netty.old; +// +//import io.netty.buffer.ByteBuf; +//import io.netty.channel.ChannelHandlerContext; +//import io.netty.handler.codec.ByteToMessageCodec; +//import io.seata.core.protocol.AbstractMessage; +//import io.seata.core.protocol.HeartbeatMessage; +//import io.seata.core.protocol.RpcMessage; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +// +//import java.nio.ByteBuffer; +//import java.util.List; +////todo 协议 +// +///** +// * The type Message codec handler. +// * RpcMessage protocol +// * 0 1 2 3 4 6 8 10 12 14 16 +// * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ +// * | 0xdada | flag | typecode/ | requestid | | +// * | | | bodylength| | | +// * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+ + +// * | ... ... | +// * + + +// * | body | +// * + + +// * | ... ... | +// * +-----------------------------------------------------------------------------------------------+ +// * +// * @author jimin.jm @alibaba-inc.com +// * @date 2018 /9/14 +// */ +//public class MessageCodecHandler extends ByteToMessageCodec { +// +// private static final Logger LOGGER = LoggerFactory.getLogger(MessageCodecHandler.class); +// private static short MAGIC = (short)0xdada; +// private static int HEAD_LENGTH = 14; +// private static final int FLAG_REQUEST = 0x80; +// private static final int FLAG_ASYNC = 0x40; +// private static final int FLAG_HEARTBEAT = 0x20; +// private static final int FLAG_SEATA_CODEC = 0x10; +// private static final int MAGIC_HALF = -38; +// private static final int NOT_FOUND_INDEX = -1; +// +// @Override +// protected void encode(ChannelHandlerContext ctx, RpcMessage msg, ByteBuf out) throws Exception { +// MessageCodec msgCodec = null; +// ByteBuffer byteBuffer = ByteBuffer.allocate(128); +// if (msg.getBody() instanceof MessageCodec) { +// msgCodec = (MessageCodec)msg.getBody(); +// } +// byteBuffer.putShort(MAGIC); +// int flag = (msg.isAsync() ? FLAG_ASYNC : 0) +// | (msg.isHeartbeat() ? FLAG_HEARTBEAT : 0) +// | (msg.isRequest() ? FLAG_REQUEST : 0) +// | (msgCodec != null ? FLAG_SEATA_CODEC : 0); +// +// byteBuffer.putShort((short)flag); +// +// if (msg.getBody() instanceof HeartbeatMessage) { +// byteBuffer.putShort((short)0); +// byteBuffer.putLong(msg.getId()); +// byteBuffer.flip(); +// out.writeBytes(byteBuffer); +// return; +// } +// +// try { +// if (null != msgCodec) { +// byteBuffer.putShort(msgCodec.getTypeCode()); +// byteBuffer.putLong(msg.getId()); +// +// byteBuffer.flip(); +// out.writeBytes(byteBuffer); +// out.writeBytes(msgCodec.encode()); +// } else { +// if (LOGGER.isInfoEnabled()) { +// LOGGER.info("msg:" + msg.getBody().toString()); +// } +// byte[] body = hessianSerialize(msg.getBody()); +// byteBuffer.putShort((short)body.length); +// byteBuffer.putLong(msg.getId()); +// byteBuffer.put(body); +// +// byteBuffer.flip(); +// out.writeBytes(byteBuffer); +// } +// } catch (Exception e) { +// LOGGER.error(msg.getBody() + " encode error", "", e); +// throw e; +// } +// if (LOGGER.isDebugEnabled()) { +// LOGGER.debug("Send:" + msg.getBody()); +// } +// } +// +// @Override +// protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { +// +// if (in.readableBytes() < HEAD_LENGTH) { +// return; +// } +// in.markReaderIndex(); +// short protocol = in.readShort(); +// if (protocol != MAGIC) { +// String emsg = "decode error,Unknown protocol: " + protocol + ",will close channel:" + ctx.channel(); +// LOGGER.error(emsg); +// ctx.channel().close(); +// return; +// } +// +// int flag = (int)in.readShort(); +// +// boolean isHeartbeat = (FLAG_HEARTBEAT & flag) > 0; +// boolean isRequest = (FLAG_REQUEST & flag) > 0; +// boolean isSeataCodec = (FLAG_SEATA_CODEC & flag) > 0; +// +// short bodyLength = 0; +// short typeCode = 0; +// if (!isSeataCodec) { bodyLength = in.readShort(); } else { typeCode = in.readShort(); } +// long msgId = in.readLong(); +// if (isHeartbeat) { +// RpcMessage rpcMessage = new RpcMessage(); +// rpcMessage.setId(msgId); +// rpcMessage.setAsync(true); +// rpcMessage.setHeartbeat(isHeartbeat); +// rpcMessage.setRequest(isRequest); +// if (isRequest) { +// rpcMessage.setBody(HeartbeatMessage.PING); +// } else { +// rpcMessage.setBody(HeartbeatMessage.PONG); +// } +// out.add(rpcMessage); +// return; +// } +// +// if (bodyLength > 0 && in.readableBytes() < bodyLength) { +// in.resetReaderIndex(); +// return; +// } +// +// RpcMessage rpcMessage = new RpcMessage(); +// rpcMessage.setId(msgId); +// rpcMessage.setAsync((FLAG_ASYNC & flag) > 0); +// rpcMessage.setHeartbeat(false); +// rpcMessage.setRequest(isRequest); +// +// try { +// if (isSeataCodec) { +// MessageCodec msgCodec = AbstractMessage.getMsgInstanceByCode(typeCode); +// if (!msgCodec.decode(in)) { +// in.resetReaderIndex(); +// return; +// } +// rpcMessage.setBody(msgCodec); +// } else { +// byte[] body = new byte[bodyLength]; +// in.readBytes(body); +// Object bodyObject = hessianDeserialize(body); +// rpcMessage.setBody(bodyObject); +// } +// } catch (Exception e) { +// LOGGER.error("decode error", "", e); +// throw e; +// } +// out.add(rpcMessage); +// if (LOGGER.isDebugEnabled()) { +// LOGGER.debug("Receive:" + rpcMessage.getBody() + ",messageId:" +// + msgId); +// } +// +// } +// +// /** +// * Hessian serialize byte [ ]. +// * +// * @param object the object +// * @return the byte [ ] +// * @throws Exception the exception +// */ +// private static byte[] hessianSerialize(Object object) throws Exception { +// if (object == null) { +// throw new NullPointerException(); +// } +// //todo user defined exx +// throw new RuntimeException("hessianSerialize not support"); +// +// } +// +// /** +// * Hessian deserialize object. +// * +// * @param bytes the bytes +// * @return the object +// * @throws Exception the exception +// */ +// private static Object hessianDeserialize(byte[] bytes) throws Exception { +// if (bytes == null) { +// throw new NullPointerException(); +// } +// //todo user defined exx +// throw new RuntimeException("hessianDeserialize not support"); +// +// } +//} diff --git a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java index 179e4331859..3f161bc341b 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java @@ -96,7 +96,11 @@ public static RpcMessage decodeFrame(ByteBuf frame) { short bodyLength = 0; short typeCode = 0; - if (!isSeataCodec) { bodyLength = frame.readShort(); } else { typeCode = frame.readShort(); } + if (!isSeataCodec) { + bodyLength = frame.readShort(); + } else { + typeCode = frame.readShort(); + } long msgId = frame.readLong(); RpcMessage rpcMessage = new RpcMessage(); rpcMessage.setCompressor(CompressorType.NONE.getCode()); @@ -121,19 +125,13 @@ public static RpcMessage decodeFrame(ByteBuf frame) { return rpcMessage; } - // TODO 怎样知道是不是one way + // todo 怎样知道是不是one way rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESQUEST_SYNC); rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY); + // todo 暂时新旧的都按这样写,应该要剥离开来(用typeCode判断序列化方式) rpcMessage.setBody(CompatibleProtocolDecoder.getBody(frame, rpcMessage.getMessageType(), rpcMessage.getCompressor(),rpcMessage.getCodec(),bodyLength)); return rpcMessage; } - - private static short getShort(byte b0, byte b1) { - ByteBuffer byteBufferX = ByteBuffer.allocate(128); - byteBufferX.put(b0); - byteBufferX.put(b1); - return byteBufferX.getShort(0); - } } From 53a98ea2d82fdd9d6040d7d9e0023325542627b6 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 19 Jul 2023 16:50:49 +0800 Subject: [PATCH 04/22] protocol --- .../rpc/netty/CompatibleProtocolDecoder.java | 3 +- .../rpc/netty/CompatibleProtocolEncoder.java | 2 +- .../core/rpc/netty/v2/ProtocolV2Decoder.java | 63 ++++++++++++++++++ .../core/rpc/netty/v2/ProtocolV2Encoder.java | 66 +++++++++++++++++++ .../seata/protocol/v2/package-info.java | 1 + 5 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Decoder.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Encoder.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v2/package-info.java diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java index 5a92b9afe8b..67d5401dede 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java @@ -56,7 +56,7 @@ *

    * https://github.com/seata/seata/issues/893 * - * @author minghua.xie + * @author Bughue * @since 2.0.0 */ public class CompatibleProtocolDecoder extends LengthFieldBasedFrameDecoder { @@ -91,6 +91,7 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception if(version == ProtocolConstants.OLD_VERSION){ return ProtocolOldDecoder.decodeFrame(frame); }else if(version == ProtocolConstants.VERSION){ + // todo spi? return ProtocolV1Decoder.decodeFrame(frame); }else { throw new IllegalArgumentException("Unknown version: " + version ); diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java index b129072ef6c..f1482cee564 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java @@ -32,7 +32,7 @@ *

    * https://github.com/seata/seata/issues/893 * - * @author minghua.xie + * @author Bughue * @since 2.0.0 */ public class CompatibleProtocolEncoder extends MessageToByteEncoder { diff --git a/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Decoder.java new file mode 100644 index 00000000000..78f35c3bb82 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Decoder.java @@ -0,0 +1,63 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty.v2; + +import io.netty.buffer.ByteBuf; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.CompatibleProtocolDecoder; +import io.seata.core.rpc.netty.v1.HeadMapSerializer; +import io.seata.core.rpc.netty.v1.ProtocolV1Encoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +/** + *
    + * 0     1     2     3     4     5     6     7     8     9    10     11    12    13    14    15    16
    + * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    + * |   magic   |Proto|     Full length       |    Head   | Msg |Seria|Compr|     RequestId         |
    + * |   code    |colVer|    (head+body)      |   Length  |Type |lizer|ess  |                       |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    + * |                                                                                               |
    + * |                                   Head Map [Optional]                                         |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    + * |                                                                                               |
    + * |                                         body                                                  |
    + * |                                                                                               |
    + * |                                        ... ...                                                |
    + * +-----------------------------------------------------------------------------------------------+
    + * 
    + *

    + *

  • Full Length: include all data
  • + *
  • Head Length: include head data from magic code to head map.
  • + *
  • Body Length: Full Length - Head Length
  • + *

    + * https://github.com/seata/seata/issues/893 + * + * @author Bughue + */ +public class ProtocolV2Decoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV2Decoder.class); + + public static Object decodeFrame(ByteBuf frame) { + // todo + return null; + } + +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Encoder.java new file mode 100644 index 00000000000..3ca8ba28276 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Encoder.java @@ -0,0 +1,66 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty.v2; + +import io.netty.buffer.ByteBuf; +import io.seata.core.compressor.Compressor; +import io.seata.core.compressor.CompressorFactory; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.old.ProtocolOldEncoder; +import io.seata.core.rpc.netty.v1.HeadMapSerializer; +import io.seata.core.rpc.netty.v1.ProtocolV1Decoder; +import io.seata.core.serializer.Serializer; +import io.seata.core.serializer.SerializerServiceLoader; +import io.seata.core.serializer.SerializerType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +/** + *
    + * 0     1     2     3     4     5     6     7     8     9    10     11    12    13    14    15    16
    + * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    + * |   magic   |Proto|     Full length       |    Head   | Msg |Seria|Compr|     RequestId         |
    + * |   code    |colVer|    (head+body)      |   Length  |Type |lizer|ess  |                       |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    + * |                                                                                               |
    + * |                                   Head Map [Optional]                                         |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    + * |                                                                                               |
    + * |                                         body                                                  |
    + * |                                                                                               |
    + * |                                        ... ...                                                |
    + * +-----------------------------------------------------------------------------------------------+
    + * 
    + *

    + *

  • Full Length: include all data
  • + *
  • Head Length: include head data from magic code to head map.
  • + *
  • Body Length: Full Length - Head Length
  • + *

    + * https://github.com/seata/seata/issues/893 + * + * @author Bughue + */ +public class ProtocolV2Encoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolOldEncoder.class); + + public static void encode(RpcMessage rpcMessage, ByteBuf out) { + // todo + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v2/package-info.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v2/package-info.java new file mode 100644 index 00000000000..7ae085eae2c --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v2/package-info.java @@ -0,0 +1 @@ +package io.seata.serializer.seata.protocol.v2; \ No newline at end of file From b909ddee7c22f8de798aacdb6997fbda47b5c53f Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Thu, 17 Aug 2023 13:38:44 +0800 Subject: [PATCH 05/22] protocol --- .../common/loader/EnhancedServiceLoader.java | 25 +- .../common/loader/ExtensionDefinition.java | 10 +- .../io/seata/common/loader/LoadLevel.java | 7 + .../core/protocol/ProtocolConstants.java | 4 +- .../netty/AbstractNettyRemotingClient.java | 15 +- .../netty/AbstractNettyRemotingServer.java | 17 +- .../rpc/netty/CompatibleProtocolDecoder.java | 50 +--- .../seata/core/rpc/netty/ProtocolDecoder.java | 10 + .../seata/core/rpc/netty/ProtocolEncoder.java | 4 + .../core/rpc/netty/ProtocolRpcMessage.java | 13 + .../rpc/netty/old/MessageCodecHandler.java | 221 -------------- .../rpc/netty/old/ProtocolOldConstants.java | 16 -- .../rpc/netty/old/ProtocolOldDecoder.java | 137 --------- .../core/rpc/netty/v0/MessageCodecV0.java | 48 ++++ .../rpc/netty/v0/ProtocolV0Constants.java | 31 ++ .../core/rpc/netty/v0/ProtocolV0Decoder.java | 138 +++++++++ .../ProtocolV0Encoder.java} | 12 +- .../rpc/netty/v0/ProtocolV0RpcMessage.java | 179 ++++++++++++ .../seata/core/rpc/netty/v0/SerializerV0.java | 6 + .../core/rpc/netty/v1/ProtocolV1Decoder.java | 28 +- .../core/rpc/netty/v1/ProtocolV1Encoder.java | 13 +- .../rpc/netty/v1/ProtocolV1RpcMessage.java | 187 ++++++++++++ .../core/rpc/netty/v2/ProtocolV2Decoder.java | 63 ---- .../core/rpc/netty/v2/ProtocolV2Encoder.java | 66 ----- .../serializer/SerializerServiceLoader.java | 4 +- ...izer.java => SeataAbstractSerializer.java} | 53 +++- .../seata/protocol/old/package-info.java | 1 - .../protocol/v0/AbstractIdentifyRequest.java | 271 ++++++++++++++++++ .../protocol/v0/AbstractIdentifyResponse.java | 144 ++++++++++ .../seata/protocol/v0/AbstractMessageV0.java | 86 ++++++ .../protocol/v0/AbstractResultMessageV0.java | 155 ++++++++++ .../seata/protocol/v0/MergedMessageV0.java | 33 +++ .../seata/protocol/v0/RegisterRMRequest.java | 174 +++++++++++ .../seata/protocol/v0/RegisterRMResponse.java | 53 ++++ .../seata/protocol/v0/RegisterTMRequest.java | 73 +++++ .../seata/protocol/v0/RegisterTMResponse.java | 53 ++++ .../seata/protocol/v0/SeataV0Serializer.java | 139 +++++++++ .../seata/protocol/v1/SeataV1Serializer.java | 47 +++ .../seata/protocol/v2/package-info.java | 1 - .../io.seata.core.serializer.Serializer | 3 +- .../BatchResultMessageSerializerTest.java | 4 +- .../MergeResultMessageSerializerTest.java | 4 +- .../MergedWarpMessageSerializerTest.java | 4 +- .../RegisterRMRequestSerializerTest.java | 4 +- .../RegisterRMResponseSerializerTest.java | 4 +- .../RegisterTMRequestSerializerTest.java | 4 +- .../RegisterTMResponseSerializerTest.java | 4 +- .../BranchCommitRequestSerializerTest.java | 4 +- .../BranchCommitResponseSerializerTest.java | 4 +- .../BranchRegisterRequestSerializerTest.java | 4 +- .../BranchRegisterResponseSerializerTest.java | 4 +- .../BranchReportRequestSerializerTest.java | 4 +- .../BranchReportResponseSerializerTest.java | 4 +- .../BranchRollbackRequestSerializerTest.java | 4 +- .../BranchRollbackResponseSerializerTest.java | 4 +- .../GlobalBeginRequestSerializerTest.java | 4 +- .../GlobalBeginResponseSerializerTest.java | 4 +- .../GlobalCommitRequestCodecTest.java | 4 +- .../GlobalCommitResponseSerializerTest.java | 4 +- .../GlobalLockQueryRequestSerializerTest.java | 4 +- ...GlobalLockQueryResponseSerializerTest.java | 4 +- .../GlobalRollbackRequestCodecTest.java | 4 +- .../GlobalRollbackResponseSerializerTest.java | 4 +- .../GlobalStatusRequestCodecTest.java | 4 +- .../GlobalStatusResponseSerializerTest.java | 4 +- .../UndoLogDeleteRequestSerializerTest.java | 4 +- 66 files changed, 2059 insertions(+), 635 deletions(-) create mode 100644 core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java delete mode 100644 core/src/main/java/io/seata/core/rpc/netty/old/MessageCodecHandler.java delete mode 100644 core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldConstants.java delete mode 100644 core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java rename core/src/main/java/io/seata/core/rpc/netty/{old/ProtocolOldEncoder.java => v0/ProtocolV0Encoder.java} (90%) create mode 100644 core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/v0/SerializerV0.java create mode 100644 core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java delete mode 100644 core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Decoder.java delete mode 100644 core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Encoder.java rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/{SeataSerializer.java => SeataAbstractSerializer.java} (58%) delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/old/package-info.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequest.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponse.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageV0.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageV0.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedMessageV0.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMRequest.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMResponse.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequest.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponse.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/SeataV1Serializer.java delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v2/package-info.java diff --git a/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java b/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java index dc56d50f76c..344f555d6c6 100644 --- a/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java +++ b/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.stream.Collectors; @@ -88,6 +89,11 @@ public static S load(Class service, String activateName) throws EnhancedS return InnerEnhancedServiceLoader.getServiceLoader(service).load(activateName, findClassLoader()); } + + public static S load(Class service, String activateName,int version) throws EnhancedServiceNotFoundException { + return InnerEnhancedServiceLoader.getServiceLoader(service).loadExtension(activateName, findClassLoader(), null, null, version); + } + /** * Specify classLoader to load the service provider * @@ -407,13 +413,13 @@ private S loadExtension(ClassLoader loader, Class[] argTypes, Object[] args) @SuppressWarnings("rawtypes") private S loadExtension(String activateName, ClassLoader loader, Class[] argTypes, - Object[] args) { + Object[] args, int version) { if (StringUtils.isEmpty(activateName)) { throw new IllegalArgumentException("the name of service provider for [" + type.getName() + "] name is null"); } try { loadAllExtensionClass(loader); - ExtensionDefinition cachedExtensionDefinition = getCachedExtensionDefinition(activateName); + ExtensionDefinition cachedExtensionDefinition = getCachedExtensionDefinition(activateName, version); return getExtensionInstance(cachedExtensionDefinition, loader, argTypes, args); } catch (Throwable e) { if (e instanceof EnhancedServiceNotFoundException) { @@ -426,6 +432,13 @@ private S loadExtension(String activateName, ClassLoader loader, Class[] argType } } + + @SuppressWarnings("rawtypes") + private S loadExtension(String activateName, ClassLoader loader, Class[] argTypes, + Object[] args) { + return loadExtension(activateName,loader,argTypes,args, -1); + } + private S getExtensionInstance(ExtensionDefinition definition, ClassLoader loader, Class[] argTypes, Object[] args) { if (definition == null) { @@ -615,8 +628,14 @@ private ExtensionDefinition getDefaultExtensionDefinition() { return CollectionUtils.getLast(currentDefinitions); } - private ExtensionDefinition getCachedExtensionDefinition(String activateName) { + private ExtensionDefinition getCachedExtensionDefinition(String activateName, int version) { List> definitions = nameToDefinitionsMap.get(activateName); + if (version < 0) { + Optional> first = definitions.stream().filter(d -> d.getVersion() == version).findFirst(); + if (first.isPresent()) { + return first.get(); + } + } return CollectionUtils.getLast(definitions); } diff --git a/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java b/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java index ea8b4790c1a..2a6c4fe0394 100644 --- a/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java +++ b/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java @@ -28,11 +28,15 @@ final class ExtensionDefinition { private final String name; private final Class serviceClass; private final Integer order; + private final Integer version; private final Scope scope; public Integer getOrder() { return this.order; } + public Integer getVersion() { + return this.version; + } public Class getServiceClass() { return this.serviceClass; @@ -43,12 +47,16 @@ public Scope getScope() { } public ExtensionDefinition(String name, Integer order, Scope scope, Class clazz) { + this(name,order,scope,clazz,0); + } + + public ExtensionDefinition(String name, Integer order, Scope scope, Class clazz,int version) { this.name = name; this.order = order; + this.version = version; this.scope = scope; this.serviceClass = clazz; } - @Override public int hashCode() { final int prime = 31; diff --git a/common/src/main/java/io/seata/common/loader/LoadLevel.java b/common/src/main/java/io/seata/common/loader/LoadLevel.java index 1c974a6a03f..cdc08eed059 100644 --- a/common/src/main/java/io/seata/common/loader/LoadLevel.java +++ b/common/src/main/java/io/seata/common/loader/LoadLevel.java @@ -44,6 +44,13 @@ */ int order() default 0; + /** + * version int. + * + * @return the int + */ + byte version() default -1; + /** * Scope enum. */ diff --git a/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java b/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java index 6684f3c980a..769887fe6a0 100644 --- a/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java +++ b/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java @@ -34,12 +34,12 @@ public interface ProtocolConstants { /** * Old protocol version */ - byte OLD_VERSION = 0; + byte VERSION_0 = 0; /** * Protocol version */ - byte VERSION = 1; + byte VERSION_1 = 1; /** * Max frame length diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java index 8766cde4873..3bab93615d6 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java @@ -56,6 +56,8 @@ import io.seata.core.protocol.transaction.GlobalBeginRequest; import io.seata.core.rpc.RemotingClient; import io.seata.core.rpc.TransactionMessageHandler; +import io.seata.core.rpc.netty.v0.ProtocolV0RpcMessage; +import io.seata.core.rpc.netty.v1.ProtocolV1RpcMessage; import io.seata.core.rpc.processor.Pair; import io.seata.core.rpc.processor.RemotingProcessor; import io.seata.discovery.loadbalance.LoadBalanceFactory; @@ -413,10 +415,17 @@ class ClientHandler extends ChannelDuplexHandler { @Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { - if (!(msg instanceof RpcMessage)) { - return; + RpcMessage rpcMessage = null; + if (msg instanceof ProtocolRpcMessage) { + rpcMessage = ((ProtocolRpcMessage) msg).convert2RpcMsg(); + } + + if (rpcMessage != null) { + processMessage(ctx, rpcMessage); + } else { + //todo 会有这种情况吗??【特殊】 + //打日志? } - processMessage(ctx, (RpcMessage) msg); } @Override diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java index 4e67446b547..32a1e76e436 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java @@ -33,6 +33,8 @@ import io.seata.core.protocol.RpcMessage; import io.seata.core.rpc.RemotingServer; import io.seata.core.rpc.RpcContext; +import io.seata.core.rpc.netty.v0.ProtocolV0RpcMessage; +import io.seata.core.rpc.netty.v1.ProtocolV1RpcMessage; import io.seata.core.rpc.processor.Pair; import io.seata.core.rpc.processor.RemotingProcessor; import org.slf4j.Logger; @@ -163,10 +165,19 @@ class ServerHandler extends ChannelDuplexHandler { */ @Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { - if (!(msg instanceof RpcMessage)) { - return; + RpcMessage rpcMessage= convert(msg); + if (rpcMessage != null) { + processMessage(ctx, rpcMessage); + } else { + //todo 正常会有这种情况吗?打日志还是抛异常? + } + } + + private RpcMessage convert(Object msg) { + if(msg instanceof ProtocolRpcMessage){ + return ((ProtocolRpcMessage) msg).convert2RpcMsg(); } - processMessage(ctx, (RpcMessage) msg); + return null; } @Override diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java index 67d5401dede..efec66ad187 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java @@ -15,23 +15,19 @@ */ package io.seata.core.rpc.netty; +import com.google.common.collect.ImmutableMap; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.LengthFieldBasedFrameDecoder; -import io.seata.core.compressor.Compressor; -import io.seata.core.compressor.CompressorFactory; import io.seata.core.exception.DecodeException; -import io.seata.core.protocol.HeartbeatMessage; import io.seata.core.protocol.ProtocolConstants; -import io.seata.core.protocol.RpcMessage; -import io.seata.core.rpc.netty.old.ProtocolOldDecoder; +import io.seata.core.rpc.netty.v0.ProtocolV0Decoder; import io.seata.core.rpc.netty.v1.ProtocolV1Decoder; -import io.seata.core.serializer.Serializer; -import io.seata.core.serializer.SerializerServiceLoader; -import io.seata.core.serializer.SerializerType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Map; + /** *
      * (> 0.7.0)
    @@ -62,10 +58,15 @@
     public class CompatibleProtocolDecoder extends LengthFieldBasedFrameDecoder {
     
         private static final Logger LOGGER = LoggerFactory.getLogger(CompatibleProtocolDecoder.class);
    +    private static Map protocolDecoderMap;
     
         public CompatibleProtocolDecoder() {
             // default is 8M
             this(ProtocolConstants.MAX_FRAME_LENGTH);
    +        protocolDecoderMap = ImmutableMap.builder()
    +                .put(ProtocolConstants.VERSION_0, new ProtocolV0Decoder())
    +                .put(ProtocolConstants.VERSION_1, new ProtocolV1Decoder())
    +                .build();
         }
     
         public CompatibleProtocolDecoder(int maxFrameLength) {
    @@ -85,18 +86,15 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
             try {
                 decoded = super.decode(ctx, in);
                 if (decoded instanceof ByteBuf) {
    -                ByteBuf frame = (ByteBuf)decoded;
    +                ByteBuf frame = (ByteBuf) decoded;
                     try {
                         byte version = decideVersion(frame);
    -                    if(version == ProtocolConstants.OLD_VERSION){
    -                        return ProtocolOldDecoder.decodeFrame(frame);
    -                    }else if(version == ProtocolConstants.VERSION){
    -                        // todo spi?
    -                        return ProtocolV1Decoder.decodeFrame(frame);
    -                    }else {
    -                        throw new IllegalArgumentException("Unknown version: " + version );
    +                    ProtocolDecoder decoder = protocolDecoderMap.get(version);
    +                    if (decoder == null) {
    +                        // todo 要不要适配当前版本?
    +                        throw new IllegalArgumentException("Unknown version: " + version);
                         }
    -
    +                    return decoder.decodeFrame(frame);
                     } finally {
                         frame.release();
                     }
    @@ -123,22 +121,4 @@ protected byte decideVersion(ByteBuf frame) {
         }
     
     
    -    public static Object getBody(ByteBuf frame, byte messageType, byte compressorType, byte codecType, int bodyLength) {
    -        Object body = null;
    -        if (messageType == ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST) {
    -            body = HeartbeatMessage.PING;
    -        } else if (messageType == ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) {
    -            body = HeartbeatMessage.PONG;
    -        } else {
    -            if (bodyLength > 0) {
    -                byte[] bs = new byte[bodyLength];
    -                frame.readBytes(bs);
    -                Compressor compressor = CompressorFactory.getCompressor(compressorType);
    -                bs = compressor.decompress(bs);
    -                Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codecType));
    -                body = serializer.deserialize(bs);
    -            }
    -        }
    -        return body;
    -    }
     }
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java
    new file mode 100644
    index 00000000000..5f1fc6a90dd
    --- /dev/null
    +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java
    @@ -0,0 +1,10 @@
    +package io.seata.core.rpc.netty;
    +
    +import io.netty.buffer.ByteBuf;
    +import io.seata.core.rpc.netty.v0.ProtocolV0RpcMessage;
    +
    +public interface ProtocolDecoder {
    +
    +    ProtocolRpcMessage decodeFrame(ByteBuf in);
    +
    +}
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java
    new file mode 100644
    index 00000000000..ceca3e9bd7f
    --- /dev/null
    +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java
    @@ -0,0 +1,4 @@
    +package io.seata.core.rpc.netty;
    +
    +public interface ProtocolEncoder {
    +}
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java
    new file mode 100644
    index 00000000000..13c60b59900
    --- /dev/null
    +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java
    @@ -0,0 +1,13 @@
    +package io.seata.core.rpc.netty;
    +
    +import io.seata.core.protocol.RpcMessage;
    +
    +/**
    + * The protocol RPC message.
    + *
    + * @author Bughue
    + */
    +public interface ProtocolRpcMessage {
    +    RpcMessage convert2RpcMsg();
    +
    +}
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/old/MessageCodecHandler.java b/core/src/main/java/io/seata/core/rpc/netty/old/MessageCodecHandler.java
    deleted file mode 100644
    index b74e9c724f4..00000000000
    --- a/core/src/main/java/io/seata/core/rpc/netty/old/MessageCodecHandler.java
    +++ /dev/null
    @@ -1,221 +0,0 @@
    -///*
    -// *  Copyright 1999-2019 Seata.io Group.
    -// *
    -// *  Licensed under the Apache License, Version 2.0 (the "License");
    -// *  you may not use this file except in compliance with the License.
    -// *  You may obtain a copy of the License at
    -// *
    -// *       http://www.apache.org/licenses/LICENSE-2.0
    -// *
    -// *  Unless required by applicable law or agreed to in writing, software
    -// *  distributed under the License is distributed on an "AS IS" BASIS,
    -// *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    -// *  See the License for the specific language governing permissions and
    -// *  limitations under the License.
    -// */
    -//package io.seata.core.rpc.netty.old;
    -//
    -//import io.netty.buffer.ByteBuf;
    -//import io.netty.channel.ChannelHandlerContext;
    -//import io.netty.handler.codec.ByteToMessageCodec;
    -//import io.seata.core.protocol.AbstractMessage;
    -//import io.seata.core.protocol.HeartbeatMessage;
    -//import io.seata.core.protocol.RpcMessage;
    -//import org.slf4j.Logger;
    -//import org.slf4j.LoggerFactory;
    -//
    -//import java.nio.ByteBuffer;
    -//import java.util.List;
    -////todo 协议
    -//
    -///**
    -// * The type Message codec handler.
    -// * RpcMessage protocol
    -// * 0     1     2     3     4           6           8          10           12          14         16
    -// * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    -// * |   0xdada  |   flag    | typecode/ |                 requestid                     |           |
    -// * |           |           | bodylength|                                               |           |
    -// * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+           +
    -// * |                                    ... ...                                                    |
    -// * +                                                                                               +
    -// * |                                     body                                                      |
    -// * +                                                                                               +
    -// * |                                    ... ...                                                    |
    -// * +-----------------------------------------------------------------------------------------------+
    -// *
    -// * @author jimin.jm @alibaba-inc.com
    -// * @date 2018 /9/14
    -// */
    -//public class MessageCodecHandler extends ByteToMessageCodec {
    -//
    -//    private static final Logger LOGGER = LoggerFactory.getLogger(MessageCodecHandler.class);
    -//    private static short MAGIC = (short)0xdada;
    -//    private static int HEAD_LENGTH = 14;
    -//    private static final int FLAG_REQUEST = 0x80;
    -//    private static final int FLAG_ASYNC = 0x40;
    -//    private static final int FLAG_HEARTBEAT = 0x20;
    -//    private static final int FLAG_SEATA_CODEC = 0x10;
    -//    private static final int MAGIC_HALF = -38;
    -//    private static final int NOT_FOUND_INDEX = -1;
    -//
    -//    @Override
    -//    protected void encode(ChannelHandlerContext ctx, RpcMessage msg, ByteBuf out) throws Exception {
    -//        MessageCodec msgCodec = null;
    -//        ByteBuffer byteBuffer = ByteBuffer.allocate(128);
    -//        if (msg.getBody() instanceof MessageCodec) {
    -//            msgCodec = (MessageCodec)msg.getBody();
    -//        }
    -//        byteBuffer.putShort(MAGIC);
    -//        int flag = (msg.isAsync() ? FLAG_ASYNC : 0)
    -//            | (msg.isHeartbeat() ? FLAG_HEARTBEAT : 0)
    -//            | (msg.isRequest() ? FLAG_REQUEST : 0)
    -//            | (msgCodec != null ? FLAG_SEATA_CODEC : 0);
    -//
    -//        byteBuffer.putShort((short)flag);
    -//
    -//        if (msg.getBody() instanceof HeartbeatMessage) {
    -//            byteBuffer.putShort((short)0);
    -//            byteBuffer.putLong(msg.getId());
    -//            byteBuffer.flip();
    -//            out.writeBytes(byteBuffer);
    -//            return;
    -//        }
    -//
    -//        try {
    -//            if (null != msgCodec) {
    -//                byteBuffer.putShort(msgCodec.getTypeCode());
    -//                byteBuffer.putLong(msg.getId());
    -//
    -//                byteBuffer.flip();
    -//                out.writeBytes(byteBuffer);
    -//                out.writeBytes(msgCodec.encode());
    -//            } else {
    -//                if (LOGGER.isInfoEnabled()) {
    -//                    LOGGER.info("msg:" + msg.getBody().toString());
    -//                }
    -//                byte[] body = hessianSerialize(msg.getBody());
    -//                byteBuffer.putShort((short)body.length);
    -//                byteBuffer.putLong(msg.getId());
    -//                byteBuffer.put(body);
    -//
    -//                byteBuffer.flip();
    -//                out.writeBytes(byteBuffer);
    -//            }
    -//        } catch (Exception e) {
    -//            LOGGER.error(msg.getBody() + " encode error", "", e);
    -//            throw e;
    -//        }
    -//        if (LOGGER.isDebugEnabled()) {
    -//            LOGGER.debug("Send:" + msg.getBody());
    -//        }
    -//    }
    -//
    -//    @Override
    -//    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception {
    -//
    -//        if (in.readableBytes() < HEAD_LENGTH) {
    -//            return;
    -//        }
    -//        in.markReaderIndex();
    -//        short protocol = in.readShort();
    -//        if (protocol != MAGIC) {
    -//            String emsg = "decode error,Unknown protocol: " + protocol + ",will close channel:" + ctx.channel();
    -//            LOGGER.error(emsg);
    -//            ctx.channel().close();
    -//            return;
    -//        }
    -//
    -//        int flag = (int)in.readShort();
    -//
    -//        boolean isHeartbeat = (FLAG_HEARTBEAT & flag) > 0;
    -//        boolean isRequest = (FLAG_REQUEST & flag) > 0;
    -//        boolean isSeataCodec = (FLAG_SEATA_CODEC & flag) > 0;
    -//
    -//        short bodyLength = 0;
    -//        short typeCode = 0;
    -//        if (!isSeataCodec) { bodyLength = in.readShort(); } else { typeCode = in.readShort(); }
    -//        long msgId = in.readLong();
    -//        if (isHeartbeat) {
    -//            RpcMessage rpcMessage = new RpcMessage();
    -//            rpcMessage.setId(msgId);
    -//            rpcMessage.setAsync(true);
    -//            rpcMessage.setHeartbeat(isHeartbeat);
    -//            rpcMessage.setRequest(isRequest);
    -//            if (isRequest) {
    -//                rpcMessage.setBody(HeartbeatMessage.PING);
    -//            } else {
    -//                rpcMessage.setBody(HeartbeatMessage.PONG);
    -//            }
    -//            out.add(rpcMessage);
    -//            return;
    -//        }
    -//
    -//        if (bodyLength > 0 && in.readableBytes() < bodyLength) {
    -//            in.resetReaderIndex();
    -//            return;
    -//        }
    -//
    -//        RpcMessage rpcMessage = new RpcMessage();
    -//        rpcMessage.setId(msgId);
    -//        rpcMessage.setAsync((FLAG_ASYNC & flag) > 0);
    -//        rpcMessage.setHeartbeat(false);
    -//        rpcMessage.setRequest(isRequest);
    -//
    -//        try {
    -//            if (isSeataCodec) {
    -//                MessageCodec msgCodec = AbstractMessage.getMsgInstanceByCode(typeCode);
    -//                if (!msgCodec.decode(in)) {
    -//                    in.resetReaderIndex();
    -//                    return;
    -//                }
    -//                rpcMessage.setBody(msgCodec);
    -//            } else {
    -//                byte[] body = new byte[bodyLength];
    -//                in.readBytes(body);
    -//                Object bodyObject = hessianDeserialize(body);
    -//                rpcMessage.setBody(bodyObject);
    -//            }
    -//        } catch (Exception e) {
    -//            LOGGER.error("decode error", "", e);
    -//            throw e;
    -//        }
    -//        out.add(rpcMessage);
    -//        if (LOGGER.isDebugEnabled()) {
    -//            LOGGER.debug("Receive:" + rpcMessage.getBody() + ",messageId:"
    -//                + msgId);
    -//        }
    -//
    -//    }
    -//
    -//    /**
    -//     * Hessian serialize byte [ ].
    -//     *
    -//     * @param object the object
    -//     * @return the byte [ ]
    -//     * @throws Exception the exception
    -//     */
    -//    private static byte[] hessianSerialize(Object object) throws Exception {
    -//        if (object == null) {
    -//            throw new NullPointerException();
    -//        }
    -//        //todo user defined exx
    -//        throw new RuntimeException("hessianSerialize not support");
    -//
    -//    }
    -//
    -//    /**
    -//     * Hessian deserialize object.
    -//     *
    -//     * @param bytes the bytes
    -//     * @return the object
    -//     * @throws Exception the exception
    -//     */
    -//    private static Object hessianDeserialize(byte[] bytes) throws Exception {
    -//        if (bytes == null) {
    -//            throw new NullPointerException();
    -//        }
    -//        //todo user defined exx
    -//        throw new RuntimeException("hessianDeserialize not support");
    -//
    -//    }
    -//}
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldConstants.java b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldConstants.java
    deleted file mode 100644
    index 9317cbd391b..00000000000
    --- a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldConstants.java
    +++ /dev/null
    @@ -1,16 +0,0 @@
    -package io.seata.core.rpc.netty.old;
    -
    -/**
    - * ?
    - *
    - * @author minghua.xie
    - * @date 2023/7/18
    - **/
    -public class ProtocolOldConstants {
    -
    -    public static int HEAD_LENGTH = 14;
    -    public static final int FLAG_REQUEST = 0x80;
    -    public static final int FLAG_ASYNC = 0x40;
    -    public static final int FLAG_HEARTBEAT = 0x20;
    -    public static final int FLAG_SEATA_CODEC = 0x10;
    -}
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java
    deleted file mode 100644
    index 3f161bc341b..00000000000
    --- a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldDecoder.java
    +++ /dev/null
    @@ -1,137 +0,0 @@
    -/*
    - *  Copyright 1999-2019 Seata.io Group.
    - *
    - *  Licensed under the Apache License, Version 2.0 (the "License");
    - *  you may not use this file except in compliance with the License.
    - *  You may obtain a copy of the License at
    - *
    - *       http://www.apache.org/licenses/LICENSE-2.0
    - *
    - *  Unless required by applicable law or agreed to in writing, software
    - *  distributed under the License is distributed on an "AS IS" BASIS,
    - *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    - *  See the License for the specific language governing permissions and
    - *  limitations under the License.
    - */
    -package io.seata.core.rpc.netty.old;
    -
    -import io.netty.buffer.ByteBuf;
    -import io.netty.channel.ChannelHandlerContext;
    -import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
    -import io.seata.core.compressor.Compressor;
    -import io.seata.core.compressor.CompressorFactory;
    -import io.seata.core.compressor.CompressorType;
    -import io.seata.core.exception.DecodeException;
    -import io.seata.core.protocol.AbstractMessage;
    -import io.seata.core.protocol.HeartbeatMessage;
    -import io.seata.core.protocol.ProtocolConstants;
    -import io.seata.core.protocol.RpcMessage;
    -import io.seata.core.rpc.netty.CompatibleProtocolDecoder;
    -import io.seata.core.rpc.netty.v1.HeadMapSerializer;
    -import io.seata.core.rpc.netty.v1.ProtocolV1Encoder;
    -import io.seata.core.serializer.Serializer;
    -import io.seata.core.serializer.SerializerServiceLoader;
    -import io.seata.core.serializer.SerializerType;
    -import org.slf4j.Logger;
    -import org.slf4j.LoggerFactory;
    -
    -import java.nio.ByteBuffer;
    -import java.util.Map;
    -
    -/**
    - * 
    - *  seata-version < 0.7
    - *  Only used in TC receives a request from RM/TM.
    - * 0     1     2     3     4           6           8          10           12          14         16
    - * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    - * |   0xdada  |   flag    | typecode/ |                 requestid                     |           |
    - * |           |           | bodylength|                                               |           |
    - * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+           +
    - * |                                    ... ...                                                    |
    - * +                                                                                               +
    - * |                                     body                                                      |
    - * +                                                                                               +
    - * |                                    ... ...                                                    |
    - * +-----------------------------------------------------------------------------------------------+
    - *
    - * 
    - *

    - *

  • flag: msg type
  • - *
  • typecode: action type code
  • - *
  • bodylength: body Length
  • - *
  • requestid: request id
  • - *

    - * - * @author minghua.xie - * @see ProtocolOldEncoder - * @since 2.0.0 - */ -public class ProtocolOldDecoder { - - - - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolOldDecoder.class); - - - public static RpcMessage decodeFrame(ByteBuf frame) { - // todo 旧版本是直接返回跳过了,我们需要保留这个逻辑? -// if (frame.readableBytes() < HEAD_LENGTH) { -// return; -// } - - // todo 这里是为了bodyLength不满足要求时reset,意义是什么? - frame.markReaderIndex(); - - // todo 外层已经判断过了,这里可以跳过 - short protocol = frame.readShort(); - - int flag = (int)frame.readShort(); - - boolean isHeartbeat = (ProtocolOldConstants.FLAG_HEARTBEAT & flag) > 0; - boolean isRequest = (ProtocolOldConstants.FLAG_REQUEST & flag) > 0; - boolean isSeataCodec = (ProtocolOldConstants.FLAG_SEATA_CODEC & flag) > 0; - - // todo 目前看来,旧协议不是seata就是hessian - byte codecType = isSeataCodec?SerializerType.SEATA.getCode():SerializerType.HESSIAN.getCode(); - - short bodyLength = 0; - short typeCode = 0; - if (!isSeataCodec) { - bodyLength = frame.readShort(); - } else { - typeCode = frame.readShort(); - } - long msgId = frame.readLong(); - RpcMessage rpcMessage = new RpcMessage(); - rpcMessage.setCompressor(CompressorType.NONE.getCode()); - rpcMessage.setCodec(codecType); - - // todo reqid之前是long的,设置不进去,要把rpcMessage也隔离成两套吗? -// rpcMessage.setId(msgId); - if (isHeartbeat) { - // todo MessageType是新字段,以前其实分了两个字段,一个是isHeartbeat,一个是isRequest - if (isRequest) { - rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST); - rpcMessage.setBody(HeartbeatMessage.PING); - } else { - rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE); - rpcMessage.setBody(HeartbeatMessage.PONG); - } - return rpcMessage; - } - - if (bodyLength > 0 && frame.readableBytes() < bodyLength) { - frame.resetReaderIndex(); - return rpcMessage; - } - - // todo 怎样知道是不是one way - rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESQUEST_SYNC); - rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY); - - // todo 暂时新旧的都按这样写,应该要剥离开来(用typeCode判断序列化方式) - rpcMessage.setBody(CompatibleProtocolDecoder.getBody(frame, rpcMessage.getMessageType(), - rpcMessage.getCompressor(),rpcMessage.getCodec(),bodyLength)); - return rpcMessage; - } -} diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java b/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java new file mode 100644 index 00000000000..2aa97266097 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java @@ -0,0 +1,48 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty.v0; + +import io.netty.buffer.ByteBuf; + +/** + * The interface Message codec. + * + * @author jimin.jm @alibaba-inc.com + * @date 2018 /9/14 + */ +public interface MessageCodecV0 { + /** + * Gets type code. + * + * @return the type code + */ + short getTypeCode(); + + /** + * Encode byte [ ]. + * + * @return the byte [ ] + */ + byte[] encode(); + + /** + * Decode boolean. + * + * @param in the in + * @return the boolean + */ + boolean decode(ByteBuf in); +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java new file mode 100644 index 00000000000..2a01f35e6c0 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java @@ -0,0 +1,31 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty.v0; + +/** + * ? + * + * @author Bughue + * @date 2023/7/18 + **/ +public class ProtocolV0Constants { + + public static int HEAD_LENGTH = 14; + public static final int FLAG_REQUEST = 0x80; + public static final int FLAG_ASYNC = 0x40; + public static final int FLAG_HEARTBEAT = 0x20; + public static final int FLAG_SEATA_CODEC = 0x10; +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java new file mode 100644 index 00000000000..33b26e09186 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java @@ -0,0 +1,138 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty.v0; + +import io.netty.buffer.ByteBuf; +import io.seata.common.loader.EnhancedServiceLoader; +import io.seata.core.protocol.HeartbeatMessage; + +import io.seata.core.rpc.RegisterCheckAuthHandler; +import io.seata.core.rpc.netty.ProtocolDecoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Iterator; +import java.util.ServiceLoader; + +/** + *
    + *  seata-version < 0.7
    + *  Only used in TC receives a request from RM/TM.
    + * 0     1     2     3     4           6           8          10           12          14         16
    + * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    + * |   0xdada  |   flag    | typecode/ |                 requestid                     |           |
    + * |           |           | bodylength|                                               |           |
    + * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+           +
    + * |                                    ... ...                                                    |
    + * +                                                                                               +
    + * |                                     body                                                      |
    + * +                                                                                               +
    + * |                                    ... ...                                                    |
    + * +-----------------------------------------------------------------------------------------------+
    + *
    + * 
    + *

    + *

  • flag: msg type
  • + *
  • typecode: action type code
  • + *
  • bodylength: body Length
  • + *
  • requestid: request id
  • + *

    + * + * @author Bughue + * @see ProtocolV0Encoder + * @since 2.0.0 + */ +public class ProtocolV0Decoder implements ProtocolDecoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV0Decoder.class); + + private static final SerializerV0 serializer = EnhancedServiceLoader.load(SerializerV0.class);; + + @Override + public ProtocolV0RpcMessage decodeFrame(ByteBuf in) { + // todo 旧版本是直接返回跳过了,我们需要保留这个逻辑?【特殊】 + if (in.readableBytes() < ProtocolV0Constants.HEAD_LENGTH) { + throw new IllegalArgumentException("Nothing to decode."); + } + + // todo 这里是为了bodyLength不满足要求时reset,意义是什么?【特殊】 + in.markReaderIndex(); + + // todo 外层已经判断过了,这里可以跳过 + short protocol = in.readShort(); + + int flag = (int) in.readShort(); + + boolean isHeartbeat = (ProtocolV0Constants.FLAG_HEARTBEAT & flag) > 0; + boolean isRequest = (ProtocolV0Constants.FLAG_REQUEST & flag) > 0; + boolean isSeataCodec = (ProtocolV0Constants.FLAG_SEATA_CODEC & flag) > 0; + + + short bodyLength = 0; + short typeCode = 0; + if (!isSeataCodec) { + bodyLength = in.readShort(); + } else { + typeCode = in.readShort(); + } + long msgId = in.readLong(); + if (isHeartbeat) { + ProtocolV0RpcMessage rpcMessage = new ProtocolV0RpcMessage(); + rpcMessage.setId(msgId); + rpcMessage.setAsync(true); + rpcMessage.setHeartbeat(isHeartbeat); + rpcMessage.setRequest(isRequest); + if (isRequest) { + rpcMessage.setBody(HeartbeatMessage.PING); + } else { + rpcMessage.setBody(HeartbeatMessage.PONG); + } + + return rpcMessage; + } + + if (bodyLength > 0 && in.readableBytes() < bodyLength) { + // todo 【特殊】 + in.resetReaderIndex(); + throw new IllegalArgumentException("readableBytes < bodyLength"); + } + + ProtocolV0RpcMessage rpcMessage = new ProtocolV0RpcMessage(); + rpcMessage.setId(msgId); + rpcMessage.setAsync((ProtocolV0Constants.FLAG_ASYNC & flag) > 0); + rpcMessage.setHeartbeat(false); + rpcMessage.setRequest(isRequest); + + try { + // todo serializer==null + MessageCodecV0 msgCodec = serializer.getMsgInstanceByCode(typeCode); + if (!msgCodec.decode(in)) { + throw new IllegalArgumentException("decode fail."); + } + rpcMessage.setBody(msgCodec); + } catch (Exception e) { + LOGGER.error("decode error", "", e); + throw e; + } + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Receive:" + rpcMessage.getBody() + ",messageId:" + + msgId); + } + return rpcMessage; + } + + +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java similarity index 90% rename from core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java rename to core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java index 689f03ad38c..c32aa507388 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/old/ProtocolOldEncoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.core.rpc.netty.old; +package io.seata.core.rpc.netty.v0; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; @@ -45,15 +45,15 @@ *
  • requestid: request id
  • *

    * - * @author minghua.xie - * @see ProtocolOldDecoder + * @author Bughue + * @see ProtocolV0Decoder * @since 2.0.0 */ -public class ProtocolOldEncoder { +public class ProtocolV0Encoder { - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolOldEncoder.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV0Encoder.class); - public static void encode(ChannelHandlerContext ctx, RpcMessage rpcMessage, ByteBuf out) { + public static void encode(ChannelHandlerContext ctx, ProtocolV0RpcMessage rpcMessage, ByteBuf out) { try { // todo 按照旧协议方式encode } catch (Throwable e) { diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java new file mode 100644 index 00000000000..c9c78644186 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java @@ -0,0 +1,179 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty.v0; + +import io.seata.common.util.StringUtils; +import io.seata.core.compressor.CompressorType; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.ProtocolRpcMessage; +import io.seata.core.serializer.SerializerType; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + +/** + * ? + * + * @author minghua.xie + * @date 2023/8/1 + **/ +public class ProtocolV0RpcMessage implements ProtocolRpcMessage { + + private static AtomicLong NEXT_ID = new AtomicLong(0); + + /** + * Gets next message id. + * + * @return the next message id + */ + public static long getNextMessageId() { + return NEXT_ID.incrementAndGet(); + } + + private long id; + private boolean isAsync; + private boolean isRequest; + private boolean isHeartbeat; + private Object body; + + private boolean isSeataCodec; + + /** + * Gets id. + * + * @return the id + */ + public long getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(long id) { + this.id = id; + } + + /** + * Is async boolean. + * + * @return the boolean + */ + public boolean isAsync() { + return isAsync; + } + + /** + * Sets async. + * + * @param async the async + */ + public void setAsync(boolean async) { + isAsync = async; + } + + /** + * Is request boolean. + * + * @return the boolean + */ + public boolean isRequest() { + return isRequest; + } + + /** + * Sets request. + * + * @param request the request + */ + public void setRequest(boolean request) { + isRequest = request; + } + + /** + * Is heartbeat boolean. + * + * @return the boolean + */ + public boolean isHeartbeat() { + return isHeartbeat; + } + + /** + * Sets heartbeat. + * + * @param heartbeat the heartbeat + */ + public void setHeartbeat(boolean heartbeat) { + isHeartbeat = heartbeat; + } + + /** + * Gets body. + * + * @return the body + */ + public Object getBody() { + return body; + } + + /** + * Sets body. + * + * @param body the body + */ + public void setBody(Object body) { + this.body = body; + } + + public boolean isSeataCodec() { + return isSeataCodec; + } + + public void setSeataCodec(boolean seataCodec) { + isSeataCodec = seataCodec; + } + + @Override + public RpcMessage convert2RpcMsg(){ + RpcMessage rpcMessage = new RpcMessage(); + // todo 基础配置 + rpcMessage.setCompressor(CompressorType.NONE.getCode()); + + byte codecType = isSeataCodec? SerializerType.SEATA.getCode():SerializerType.HESSIAN.getCode(); + rpcMessage.setCodec(codecType); + + if(isHeartbeat){ + if(isRequest){ + rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST); + }else { + rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE); + } + }else { + if(isRequest){ + rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY); + }else { + rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESPONSE); + } + } + + return rpcMessage; + } +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/SerializerV0.java b/core/src/main/java/io/seata/core/rpc/netty/v0/SerializerV0.java new file mode 100644 index 00000000000..90246ff4fa8 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/SerializerV0.java @@ -0,0 +1,6 @@ +package io.seata.core.rpc.netty.v0; + +public interface SerializerV0 { + + MessageCodecV0 getMsgInstanceByCode(short typeCode); +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java index 2c3ba775216..4b6bad758a8 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java @@ -16,13 +16,14 @@ package io.seata.core.rpc.netty.v1; import io.netty.buffer.ByteBuf; -import io.seata.core.rpc.netty.CompatibleProtocolDecoder; -import io.seata.core.serializer.Serializer; import io.seata.core.compressor.Compressor; import io.seata.core.compressor.CompressorFactory; import io.seata.core.protocol.HeartbeatMessage; +import io.seata.core.rpc.netty.CompatibleProtocolDecoder; import io.seata.core.protocol.ProtocolConstants; -import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.ProtocolDecoder; +import io.seata.core.rpc.netty.ProtocolRpcMessage; +import io.seata.core.serializer.Serializer; import io.seata.core.serializer.SerializerServiceLoader; import io.seata.core.serializer.SerializerType; import org.slf4j.Logger; @@ -57,11 +58,12 @@ * @see ProtocolV1Encoder * @since 0.7.0 */ -public class ProtocolV1Decoder{ +public class ProtocolV1Decoder implements ProtocolDecoder { private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV1Decoder.class); - public static Object decodeFrame(ByteBuf frame) { + @Override + public ProtocolRpcMessage decodeFrame(ByteBuf frame) { byte b0 = frame.readByte(); byte b1 = frame.readByte(); if (ProtocolConstants.MAGIC_CODE_BYTES[0] != b0 @@ -70,7 +72,6 @@ public static Object decodeFrame(ByteBuf frame) { } byte version = frame.readByte(); - // TODO check version compatible here int fullLength = frame.readInt(); short headLength = frame.readShort(); @@ -79,7 +80,7 @@ public static Object decodeFrame(ByteBuf frame) { byte compressorType = frame.readByte(); int requestId = frame.readInt(); - RpcMessage rpcMessage = new RpcMessage(); + ProtocolV1RpcMessage rpcMessage = new ProtocolV1RpcMessage(); rpcMessage.setCodec(codecType); rpcMessage.setId(requestId); rpcMessage.setCompressor(compressorType); @@ -94,7 +95,18 @@ public static Object decodeFrame(ByteBuf frame) { // read body int bodyLength = fullLength - headLength; - rpcMessage.setBody(CompatibleProtocolDecoder.getBody(frame, messageType, compressorType, codecType, bodyLength)); + if (messageType == ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST) { + rpcMessage.setBody(HeartbeatMessage.PING); + } else if (messageType == ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) { + rpcMessage.setBody(HeartbeatMessage.PONG); + } else if (bodyLength > 0) { + byte[] bs = new byte[bodyLength]; + frame.readBytes(bs); + Compressor compressor = CompressorFactory.getCompressor(compressorType); + bs = compressor.decompress(bs); + Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codecType),version); + return serializer.deserialize(bs); + } return rpcMessage; } diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java index 522ff8835d8..95c0348c3c3 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java @@ -16,14 +16,11 @@ package io.seata.core.rpc.netty.v1; import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.seata.core.rpc.netty.CompatibleProtocolEncoder; -import io.seata.core.rpc.netty.old.ProtocolOldEncoder; +import io.seata.core.rpc.netty.v0.ProtocolV0Encoder; import io.seata.core.serializer.Serializer; import io.seata.core.compressor.Compressor; import io.seata.core.compressor.CompressorFactory; import io.seata.core.protocol.ProtocolConstants; -import io.seata.core.protocol.RpcMessage; import io.seata.core.serializer.SerializerServiceLoader; import io.seata.core.serializer.SerializerType; import org.slf4j.Logger; @@ -60,9 +57,9 @@ */ public class ProtocolV1Encoder{ - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolOldEncoder.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV0Encoder.class); - public static void encode(RpcMessage rpcMessage, ByteBuf out) { + public static void encode(ProtocolV1RpcMessage rpcMessage, ByteBuf out) { try { // todo 外层已经判断好,可以去掉 // if (msg instanceof RpcMessage) { @@ -73,7 +70,7 @@ public static void encode(RpcMessage rpcMessage, ByteBuf out) { byte messageType = rpcMessage.getMessageType(); out.writeBytes(ProtocolConstants.MAGIC_CODE_BYTES); - out.writeByte(ProtocolConstants.VERSION); + out.writeByte(ProtocolConstants.VERSION_1); // full Length(4B) and head length(2B) will fix in the end. out.writerIndex(out.writerIndex() + 6); out.writeByte(messageType); @@ -93,7 +90,7 @@ public static void encode(RpcMessage rpcMessage, ByteBuf out) { if (messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST && messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) { // heartbeat has no body - Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec())); + Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec()), ProtocolConstants.VERSION_1); bodyBytes = serializer.serialize(rpcMessage.getBody()); Compressor compressor = CompressorFactory.getCompressor(rpcMessage.getCompressor()); bodyBytes = compressor.compress(bodyBytes); diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java new file mode 100644 index 00000000000..47d51504908 --- /dev/null +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java @@ -0,0 +1,187 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty.v1; + +import io.seata.common.util.StringUtils; +import io.seata.core.compressor.CompressorType; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.ProtocolRpcMessage; +import io.seata.core.serializer.SerializerType; + +import java.util.HashMap; +import java.util.Map; + +/** + * ? + * + * @author minghua.xie + * @date 2023/8/1 + **/ +public class ProtocolV1RpcMessage implements ProtocolRpcMessage { + + private int id; + private byte messageType; + private byte codec; + private byte compressor; + private Map headMap = new HashMap<>(); + private Object body; + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + */ + public void setId(int id) { + this.id = id; + } + + /** + * Gets body. + * + * @return the body + */ + public Object getBody() { + return body; + } + + /** + * Sets body. + * + * @param body the body + */ + public void setBody(Object body) { + this.body = body; + } + + /** + * Gets codec. + * + * @return the codec + */ + public byte getCodec() { + return codec; + } + + /** + * Sets codec. + * + * @param codec the codec + * @return the codec + */ + public void setCodec(byte codec) { + this.codec = codec; + } + + /** + * Gets compressor. + * + * @return the compressor + */ + public byte getCompressor() { + return compressor; + } + + /** + * Sets compressor. + * + * @param compressor the compressor + * @return the compressor + */ + public void setCompressor(byte compressor) { + this.compressor = compressor; + } + + /** + * Gets head map. + * + * @return the head map + */ + public Map getHeadMap() { + return headMap; + } + + /** + * Sets head map. + * + * @param headMap the head map + * @return the head map + */ + public void setHeadMap(Map headMap) { + this.headMap = headMap; + } + + /** + * Gets head. + * + * @param headKey the head key + * @return the head + */ + public String getHead(String headKey) { + return headMap.get(headKey); + } + + /** + * Put head. + * + * @param headKey the head key + * @param headValue the head value + */ + public void putHead(String headKey, String headValue) { + headMap.put(headKey, headValue); + } + + /** + * Gets message type. + * + * @return the message type + */ + public byte getMessageType() { + return messageType; + } + + /** + * Sets message type. + * + * @param messageType the message type + */ + public void setMessageType(byte messageType) { + this.messageType = messageType; + } + + @Override + public String toString() { + return StringUtils.toString(this); + } + + @Override + public RpcMessage convert2RpcMsg(){ + RpcMessage rpcMessage = new RpcMessage(); + // todo + + + return rpcMessage; + } +} diff --git a/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Decoder.java deleted file mode 100644 index 78f35c3bb82..00000000000 --- a/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Decoder.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.core.rpc.netty.v2; - -import io.netty.buffer.ByteBuf; -import io.seata.core.protocol.ProtocolConstants; -import io.seata.core.protocol.RpcMessage; -import io.seata.core.rpc.netty.CompatibleProtocolDecoder; -import io.seata.core.rpc.netty.v1.HeadMapSerializer; -import io.seata.core.rpc.netty.v1.ProtocolV1Encoder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; - -/** - *
    - * 0     1     2     3     4     5     6     7     8     9    10     11    12    13    14    15    16
    - * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    - * |   magic   |Proto|     Full length       |    Head   | Msg |Seria|Compr|     RequestId         |
    - * |   code    |colVer|    (head+body)      |   Length  |Type |lizer|ess  |                       |
    - * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    - * |                                                                                               |
    - * |                                   Head Map [Optional]                                         |
    - * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    - * |                                                                                               |
    - * |                                         body                                                  |
    - * |                                                                                               |
    - * |                                        ... ...                                                |
    - * +-----------------------------------------------------------------------------------------------+
    - * 
    - *

    - *

  • Full Length: include all data
  • - *
  • Head Length: include head data from magic code to head map.
  • - *
  • Body Length: Full Length - Head Length
  • - *

    - * https://github.com/seata/seata/issues/893 - * - * @author Bughue - */ -public class ProtocolV2Decoder { - - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV2Decoder.class); - - public static Object decodeFrame(ByteBuf frame) { - // todo - return null; - } - -} diff --git a/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Encoder.java deleted file mode 100644 index 3ca8ba28276..00000000000 --- a/core/src/main/java/io/seata/core/rpc/netty/v2/ProtocolV2Encoder.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.core.rpc.netty.v2; - -import io.netty.buffer.ByteBuf; -import io.seata.core.compressor.Compressor; -import io.seata.core.compressor.CompressorFactory; -import io.seata.core.protocol.ProtocolConstants; -import io.seata.core.protocol.RpcMessage; -import io.seata.core.rpc.netty.old.ProtocolOldEncoder; -import io.seata.core.rpc.netty.v1.HeadMapSerializer; -import io.seata.core.rpc.netty.v1.ProtocolV1Decoder; -import io.seata.core.serializer.Serializer; -import io.seata.core.serializer.SerializerServiceLoader; -import io.seata.core.serializer.SerializerType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; - -/** - *
    - * 0     1     2     3     4     5     6     7     8     9    10     11    12    13    14    15    16
    - * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    - * |   magic   |Proto|     Full length       |    Head   | Msg |Seria|Compr|     RequestId         |
    - * |   code    |colVer|    (head+body)      |   Length  |Type |lizer|ess  |                       |
    - * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    - * |                                                                                               |
    - * |                                   Head Map [Optional]                                         |
    - * +-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    - * |                                                                                               |
    - * |                                         body                                                  |
    - * |                                                                                               |
    - * |                                        ... ...                                                |
    - * +-----------------------------------------------------------------------------------------------+
    - * 
    - *

    - *

  • Full Length: include all data
  • - *
  • Head Length: include head data from magic code to head map.
  • - *
  • Body Length: Full Length - Head Length
  • - *

    - * https://github.com/seata/seata/issues/893 - * - * @author Bughue - */ -public class ProtocolV2Encoder { - - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolOldEncoder.class); - - public static void encode(RpcMessage rpcMessage, ByteBuf out) { - // todo - } -} diff --git a/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java b/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java index e602567d444..c2d1b3ab9c1 100644 --- a/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java +++ b/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java @@ -39,7 +39,7 @@ private SerializerServiceLoader() { * @return the service of {@link Serializer} * @throws EnhancedServiceNotFoundException the enhanced service not found exception */ - public static Serializer load(SerializerType type) throws EnhancedServiceNotFoundException { + public static Serializer load(SerializerType type,int version) throws EnhancedServiceNotFoundException { if (type == SerializerType.PROTOBUF) { try { ReflectionUtil.getClassByName(PROTOBUF_SERIALIZER_CLASS_NAME); @@ -48,6 +48,6 @@ public static Serializer load(SerializerType type) throws EnhancedServiceNotFoun "Please manually reference 'io.seata:seata-serializer-protobuf' dependency ", e); } } - return EnhancedServiceLoader.load(Serializer.class, type.name()); + return EnhancedServiceLoader.load(Serializer.class, type.name(), version); } } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java similarity index 58% rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java index d53a96accd7..762692afc93 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java @@ -15,21 +15,42 @@ */ package io.seata.serializer.seata; +import com.sun.tools.javac.util.Pair; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import io.seata.common.loader.LoadLevel; import io.seata.core.protocol.AbstractMessage; import io.seata.core.serializer.Serializer; import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; /** * The Seata codec. * * @author zhangsen */ -@LoadLevel(name = "SEATA") -public class SeataSerializer implements Serializer { +public abstract class SeataAbstractSerializer implements Serializer { + + protected Map,Class>> classMap = new HashMap(); + + public Class getCodecClass(short typeCode){ + Pair, Class> pair = classMap.get(typeCode); + if(pair !=null && pair.fst !=null){ + return pair.fst; + }else { + return null; + } + } + + public Class getMessageClass(short typeCode){ + Pair, Class> pair = classMap.get(typeCode); + if(pair !=null && pair.snd !=null){ + return pair.snd; + }else { + return null; + } + } @Override public byte[] serialize(T t) { @@ -40,7 +61,7 @@ public byte[] serialize(T t) { //typecode short typecode = abstractMessage.getTypeCode(); //msg codec - MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typecode); + MessageSeataCodec messageCodec = getCodecByType(typecode); //get empty ByteBuffer ByteBuf out = Unpooled.buffer(1024); //msg encode @@ -75,12 +96,32 @@ public T deserialize(byte[] bytes) { byteBuffer.get(body); ByteBuffer in = ByteBuffer.wrap(body); //new Messgae - AbstractMessage abstractMessage = MessageCodecFactory.getMessage(typecode); + AbstractMessage abstractMessage = getMessageByType(typecode); //get messageCodec - MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typecode); + MessageSeataCodec messageCodec = getCodecByType(typecode); //decode messageCodec.decode(abstractMessage, in); return (T)abstractMessage; } + private AbstractMessage getMessageByType(short typecode) { + try { + return getMessageClass(typecode).newInstance(); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + private MessageSeataCodec getCodecByType(short typecode) { + try { + return getCodecClass(typecode).newInstance(); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/old/package-info.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/old/package-info.java deleted file mode 100644 index 07dbe9823ea..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/old/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package io.seata.serializer.seata.protocol.old; \ No newline at end of file diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequest.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequest.java new file mode 100644 index 00000000000..ccb27bfd8b7 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequest.java @@ -0,0 +1,271 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + +import io.netty.buffer.ByteBuf; +import io.seata.core.protocol.Version; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.ByteBuffer; + +/** + * The type Abstract identify request. + * + * @author sharajava + */ +public abstract class AbstractIdentifyRequest extends AbstractMessageV0 { + + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractIdentifyRequest.class); + + /** + * The Version. + */ + protected String version = Version.getCurrent(); + + /** + * The Application id. + */ + protected String applicationId; + + /** + * The Transaction service group. + */ + protected String transactionServiceGroup; + + /** + * The Extra data. + */ + protected String extraData; + + /** + * Instantiates a new Abstract identify request. + * + * @param applicationId the application id + * @param transactionServiceGroup the transaction service group + */ + public AbstractIdentifyRequest(String applicationId, String transactionServiceGroup) { + this.applicationId = applicationId; + this.transactionServiceGroup = transactionServiceGroup; + } + + /** + * Instantiates a new Abstract identify request. + * + * @param applicationId the application id + * @param transactionServiceGroup the transaction service group + * @param extraData the extra data + */ + public AbstractIdentifyRequest(String applicationId, String transactionServiceGroup, String extraData) { + this.applicationId = applicationId; + this.transactionServiceGroup = transactionServiceGroup; + this.extraData = extraData; + } + + /** + * Gets version. + * + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * Sets version. + * + * @param version the version + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * Gets application id. + * + * @return the application id + */ + public String getApplicationId() { + return applicationId; + } + + /** + * Sets application id. + * + * @param applicationId the application id + */ + public void setApplicationId(String applicationId) { + this.applicationId = applicationId; + } + + /** + * Gets transaction service group. + * + * @return the transaction service group + */ + public String getTransactionServiceGroup() { + return transactionServiceGroup; + } + + /** + * Sets transaction service group. + * + * @param transactionServiceGroup the transaction service group + */ + public void setTransactionServiceGroup(String transactionServiceGroup) { + this.transactionServiceGroup = transactionServiceGroup; + } + + /** + * Gets extra data. + * + * @return the extra data + */ + public String getExtraData() { + return extraData; + } + + /** + * Sets extra data. + * + * @param extraData the extra data + */ + public void setExtraData(String extraData) { + this.extraData = extraData; + } + + /** + * The Byte buffer. + */ + public ByteBuffer byteBuffer = ByteBuffer.allocate(10 * 1024); + + /** + * Do encode. + */ + protected void doEncode() { + byteBuffer.clear(); + if (this.version != null) { + byte[] bs = version.getBytes(UTF8); + byteBuffer.putShort((short)bs.length); + if (bs.length > 0) { + byteBuffer.put(bs); + } + } else { + byteBuffer.putShort((short)0); + } + + if (this.applicationId != null) { + byte[] bs = applicationId.getBytes(UTF8); + byteBuffer.putShort((short)bs.length); + if (bs.length > 0) { + byteBuffer.put(bs); + } + } else { + byteBuffer.putShort((short)0); + } + + if (this.transactionServiceGroup != null) { + byte[] bs = transactionServiceGroup.getBytes(UTF8); + byteBuffer.putShort((short)bs.length); + if (bs.length > 0) { + byteBuffer.put(bs); + } + } else { + byteBuffer.putShort((short)0); + } + + if (this.extraData != null) { + byte[] bs = extraData.getBytes(UTF8); + byteBuffer.putShort((short)bs.length); + if (bs.length > 0) { + byteBuffer.put(bs); + } + } else { + byteBuffer.putShort((short)0); + } + + } + + private final byte[] flushEncode() { + byteBuffer.flip(); + byte[] content = new byte[byteBuffer.limit()]; + byteBuffer.get(content); + byteBuffer.clear(); // >? + return content; + } + + @Override + public final byte[] encode() { + doEncode(); + return flushEncode(); + } + + @Override + public boolean decode(ByteBuf in) { + + short len; + if (in.readableBytes() < 2) { + return false; + } + len = in.readShort(); + + if (in.readableBytes() < len) { + return false; + } + byte[] bs = new byte[len]; + in.readBytes(bs); + this.setVersion(new String(bs, UTF8)); + + if (in.readableBytes() < 2) { + return false; + } + len = in.readShort(); + + if (in.readableBytes() < len) { + return false; + } + bs = new byte[len]; + in.readBytes(bs); + this.setApplicationId(new String(bs, UTF8)); + + if (in.readableBytes() < 2) { + return false; + } + len = in.readShort(); + + if (in.readableBytes() < len) { + return false; + } + bs = new byte[len]; + in.readBytes(bs); + this.setTransactionServiceGroup(new String(bs, UTF8)); + + if (in.readableBytes() < 2) { + return false; + } + len = in.readShort(); + + if (in.readableBytes() >= len) { + bs = new byte[len]; + in.readBytes(bs); + this.setExtraData(new String(bs, UTF8)); + } else { + //maybe null + } + + return true; + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponse.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponse.java new file mode 100644 index 00000000000..2021906967f --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponse.java @@ -0,0 +1,144 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + +import io.netty.buffer.ByteBuf; +import io.seata.core.protocol.Version; + +/** + * The type Abstract identify response. + * + * @author sharajava + */ +public abstract class AbstractIdentifyResponse extends AbstractResultMessageV0 { + + protected String version = Version.getCurrent(); + + private String extraData; + + private boolean identified; + + /** + * Gets version. + * + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * Sets version. + * + * @param version the version + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * Gets extra data. + * + * @return the extra data + */ + public String getExtraData() { + return extraData; + } + + /** + * Sets extra data. + * + * @param extraData the extra data + */ + public void setExtraData(String extraData) { + this.extraData = extraData; + } + + /** + * Is identified boolean. + * + * @return the boolean + */ + public boolean isIdentified() { + return identified; + } + + /** + * Sets identified. + * + * @param identified the identified + */ + public void setIdentified(boolean identified) { + this.identified = identified; + } + + @Override + public void doEncode() { + // super.doEncode(); + byteBuffer.put(this.identified ? (byte)1 : (byte)0); + if (this.version != null) { + byte[] bs = version.getBytes(UTF8); + byteBuffer.putShort((short)bs.length); + if (bs.length > 0) { + byteBuffer.put(bs); + } + } else { + byteBuffer.putShort((short)0); + } + + } + + @Override + public boolean decode(ByteBuf in) { + if (in.readableBytes() < 3) { + return false; + } + this.identified = in.readByte() == 1; + short len = in.readShort(); + if (len <= 0) { + return false; + } + if (in.readableBytes() < len) { + return false; + } + byte[] bs = new byte[len]; + in.readBytes(bs); + this.setVersion(new String(bs, UTF8)); + return true; + + } + + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + result.append("version="); + result.append(version); + result.append(","); + result.append("extraData="); + result.append(extraData); + result.append(","); + result.append("identified="); + result.append(identified); + result.append(","); + result.append("resultCode="); + result.append(getResultCode()); + result.append(","); + result.append("msg="); + result.append(getMsg()); + + return result.toString(); + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageV0.java new file mode 100644 index 00000000000..f8e95691539 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageV0.java @@ -0,0 +1,86 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.seata.common.Constants; +import io.seata.core.rpc.netty.v0.MessageCodecV0; + +import java.io.Serializable; +import java.nio.charset.Charset; + +/** + * The type Abstract message. + * + * @author jimin.jm @alibaba-inc.com + * @date 2018 /9/14 + */ +public abstract class AbstractMessageV0 implements MessageCodecV0, Serializable { + private static final long serialVersionUID = -1441020418526899889L; + + /** + * The constant UTF8. + */ + protected static final Charset UTF8 = Constants.DEFAULT_CHARSET; + /** + * The Ctx. + */ + protected ChannelHandlerContext ctx; + + /** + * Bytes to int int. + * + * @param bytes the bytes + * @param offset the offset + * @return the int + */ + public static int bytesToInt(byte[] bytes, int offset) { + int ret = 0; + for (int i = 0; i < 4 && i + offset < bytes.length; i++) { + ret <<= 8; + ret |= (int)bytes[i + offset] & 0xFF; + } + return ret; + } + + /** + * Int to bytes. + * + * @param i the + * @param bytes the bytes + * @param offset the offset + */ + public static void intToBytes(int i, byte[] bytes, int offset) { + bytes[offset] = (byte)((i >> 24) & 0xFF); + bytes[offset + 1] = (byte)((i >> 16) & 0xFF); + bytes[offset + 2] = (byte)((i >> 8) & 0xFF); + bytes[offset + 3] = (byte)(i & 0xFF); + } + + @Override + public boolean decode(ByteBuf in) { + return false; + } + + /** + * Gets msg instance by code. + * + * @param typeCode the type code + * @return the msg instance by code + */ + +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageV0.java new file mode 100644 index 00000000000..aeed3c6b15c --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageV0.java @@ -0,0 +1,155 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + +import io.netty.buffer.ByteBuf; +import io.seata.core.protocol.AbstractMessage; +import io.seata.core.protocol.ResultCode; + +import java.nio.ByteBuffer; + +/** + * The type Abstract result message. + * + * @author jimin.jm @alibaba-inc.com + * @date 2018 /9/14 + */ +public abstract class AbstractResultMessageV0 extends AbstractMessageV0 implements MergedMessageV0 { + private static final long serialVersionUID = 6540352050650203313L; + + private ResultCode resultCode; + + /** + * The Byte buffer. + */ + public ByteBuffer byteBuffer = ByteBuffer.allocate(512); + + /** + * Gets result code. + * + * @return the result code + */ + public ResultCode getResultCode() { + return resultCode; + } + + /** + * Sets result code. + * + * @param resultCode the result code + */ + public void setResultCode(ResultCode resultCode) { + this.resultCode = resultCode; + } + + private String msg; + + /** + * Gets msg. + * + * @return the msg + */ + public String getMsg() { + return msg; + } + + /** + * Sets msg. + * + * @param msg the msg + */ + public void setMsg(String msg) { + this.msg = msg; + } + + /** + * Do encode. + */ + protected void doEncode() { + byteBuffer.put((byte)resultCode.ordinal()); + if (resultCode == ResultCode.Failed) { + if (getMsg() != null) { + String msg; + if (getMsg().length() > 128) { + msg = getMsg().substring(0, 128); + } else { + msg = getMsg(); + } + byte[] bs = msg.getBytes(UTF8); + if (bs.length > 400 && getMsg().length() > 64) { + msg = getMsg().substring(0, 64); + bs = msg.getBytes(UTF8); + } + byteBuffer.putShort((short)bs.length); + if (bs.length > 0) { + byteBuffer.put(bs); + } + } else { + byteBuffer.putShort((short)0); + } + } + } + + private final byte[] flushEncode() { + byteBuffer.flip(); + byte[] content = new byte[byteBuffer.limit()]; + byteBuffer.get(content); + byteBuffer.clear(); // >? + return content; + } + + @Override + public final byte[] encode() { + doEncode(); + return flushEncode(); + } + + @Override + public void decode(ByteBuffer byteBuffer) { + setResultCode(ResultCode.get(byteBuffer.get())); + if (resultCode == ResultCode.Failed) { + short len = byteBuffer.getShort(); + if (len > 0) { + byte[] msg = new byte[len]; + byteBuffer.get(msg); + this.setMsg(new String(msg, UTF8)); + } + } + } + + @Override + public boolean decode(ByteBuf in) { + if (in.readableBytes() < 1) { + return false; + } + setResultCode(ResultCode.get(in.readByte())); + if (resultCode == ResultCode.Failed) { + if (in.readableBytes() < 2) { + return false; + } + short len = in.readShort(); + if (in.readableBytes() < len) { + return false; + } + if (len > 0) { + byte[] msg = new byte[len]; + in.readBytes(msg); + this.setMsg(new String(msg, UTF8)); + } + } + return true; + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedMessageV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedMessageV0.java new file mode 100644 index 00000000000..04e8913d9c8 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedMessageV0.java @@ -0,0 +1,33 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + +import java.nio.ByteBuffer; + +/** + * The interface Merged message. + * + * @author jimin.jm @alibaba-inc.com + * @date 2018 /9/17 + */ +public interface MergedMessageV0 { + /** + * Decode. + * + * @param byteBuffer the byte buffer + */ + void decode(ByteBuffer byteBuffer); +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMRequest.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMRequest.java new file mode 100644 index 00000000000..7e61d460ae2 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMRequest.java @@ -0,0 +1,174 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + +import io.netty.buffer.ByteBuf; + +import java.io.Serializable; + +import static io.seata.core.protocol.MessageType.TYPE_REG_RM; + +/** + * The type Register rm request. + * + * @author jimin.jm @alibaba-inc.com + * @date 2018 /10/10 + */ +public class RegisterRMRequest extends AbstractIdentifyRequest implements Serializable { + private static final long serialVersionUID = 7539732523682335742L; + + private String resourceIds; + + /** + * Instantiates a new Register rm request. + */ + public RegisterRMRequest() { + this(null, null); + } + + /** + * Instantiates a new Register rm request. + * + * @param applicationId the application id + * @param transactionServiceGroup the transaction service group + */ + public RegisterRMRequest(String applicationId, String transactionServiceGroup) { + super(applicationId, transactionServiceGroup); + } + + /** + * Gets resource ids. + * + * @return the resource ids + */ + public String getResourceIds() { + return resourceIds; + } + + /** + * Sets resource ids. + * + * @param resourceIds the resource ids + */ + public void setResourceIds(String resourceIds) { + this.resourceIds = resourceIds; + } + + @Override + public short getTypeCode() { + return TYPE_REG_RM; + } + + @Override + protected void doEncode() { + super.doEncode(); + if (this.resourceIds != null) { + byte[] bs = resourceIds.getBytes(UTF8); + byteBuffer.putInt(bs.length); + if (bs.length > 0) { + byteBuffer.put(bs); + } + } else { + byteBuffer.putInt(0); + } + } + + @Override + public boolean decode(ByteBuf in) { + + if (in.readableBytes() < 2) { + return false; + } + short len = in.readShort(); + if (len > 0) { + if (in.readableBytes() < len) { + return false; + } + byte[] bs = new byte[len]; + in.readBytes(bs); + this.setVersion(new String(bs, UTF8)); + } else { + return false; + } + if (in.readableBytes() < 2) { + return false; + } + len = in.readShort(); + + if (len > 0) { + if (in.readableBytes() < len) { + return false; + } + byte[] bs = new byte[len]; + in.readBytes(bs); + this.setApplicationId(new String(bs, UTF8)); + } + + if (in.readableBytes() < 2) { + return false; + } + len = in.readShort(); + + if (in.readableBytes() < len) { + return false; + } + byte[] bs = new byte[len]; + in.readBytes(bs); + this.setTransactionServiceGroup(new String(bs, UTF8)); + + if (in.readableBytes() < 2) { + return false; + } + len = in.readShort(); + + if (len > 0) { + if (in.readableBytes() < len) { + return false; + } + bs = new byte[len]; + in.readBytes(bs); + this.setExtraData(new String(bs, UTF8)); + } + + int iLen; + if (in.readableBytes() < 4) { + return false; + } + iLen = in.readInt(); + + if (iLen > 0) { + if (in.readableBytes() < iLen) { + return false; + } + bs = new byte[iLen]; + in.readBytes(bs); + this.setResourceIds(new String(bs, UTF8)); + return true; + } + //maybe null + + return true; + } + + @Override + public String toString() { + return "RegisterRMRequest{" + + "resourceIds='" + resourceIds + '\'' + + ", applicationId='" + applicationId + '\'' + + ", transactionServiceGroup='" + transactionServiceGroup + '\'' + + '}'; + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMResponse.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMResponse.java new file mode 100644 index 00000000000..7375bf5e720 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMResponse.java @@ -0,0 +1,53 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + + +import io.seata.core.protocol.MessageType; + +import java.io.Serializable; + +/** + * The type Register rm response. + * + * @author jimin.jm @alibaba-inc.com + * @date 2018 /10/10 + */ +public class RegisterRMResponse extends AbstractIdentifyResponse implements Serializable { + private static final long serialVersionUID = 6391375605848221420L; + + /** + * Instantiates a new Register rm response. + */ + public RegisterRMResponse() { + this(true); + } + + /** + * Instantiates a new Register rm response. + * + * @param result the result + */ + public RegisterRMResponse(boolean result) { + super(); + setIdentified(result); + } + + @Override + public short getTypeCode() { + return MessageType.TYPE_REG_RM_RESULT; + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequest.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequest.java new file mode 100644 index 00000000000..2b1a70c8497 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequest.java @@ -0,0 +1,73 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + + +import io.seata.core.protocol.MessageType; + +import java.io.Serializable; + +/** + * The type Register tm request. + * + * @author jimin.jm @alibaba-inc.com + * @date 2018 /10/15 + */ +public class RegisterTMRequest extends AbstractIdentifyRequest implements Serializable { + private static final long serialVersionUID = -5929081344190543690L; + + /** + * Instantiates a new Register tm request. + */ + public RegisterTMRequest() { + this(null, null); + } + + /** + * Instantiates a new Register tm request. + * + * @param applicationId the application id + * @param transactionServiceGroup the transaction service group + * @param extraData the extra data + */ + public RegisterTMRequest(String applicationId, String transactionServiceGroup, String extraData) { + super(applicationId, transactionServiceGroup, extraData); + + } + + /** + * Instantiates a new Register tm request. + * + * @param applicationId the application id + * @param transactionServiceGroup the transaction service group + */ + public RegisterTMRequest(String applicationId, String transactionServiceGroup) { + super(applicationId, transactionServiceGroup); + } + + @Override + public short getTypeCode() { + return MessageType.TYPE_REG_CLT; + } + + @Override + public String toString() { + return "RegisterTMRequest{" + + "applicationId='" + applicationId + '\'' + + ", transactionServiceGroup='" + transactionServiceGroup + '\'' + + '}'; + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponse.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponse.java new file mode 100644 index 00000000000..4db675e596a --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponse.java @@ -0,0 +1,53 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + + +import io.seata.core.protocol.MessageType; + +import java.io.Serializable; + +/** + * The type Register tm response. + * + * @author jimin.jm @alibaba-inc.com + * @date 2018 /10/15 + */ +public class RegisterTMResponse extends AbstractIdentifyResponse implements Serializable { + private static final long serialVersionUID = 3629846050062228749L; + + /** + * Instantiates a new Register tm response. + */ + public RegisterTMResponse() { + this(true); + } + + /** + * Instantiates a new Register tm response. + * + * @param result the result + */ + public RegisterTMResponse(boolean result) { + super(); + setIdentified(result); + } + + @Override + public short getTypeCode() { + return MessageType.TYPE_REG_CLT_RESULT; + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java new file mode 100644 index 00000000000..72109429694 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java @@ -0,0 +1,139 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + +import io.seata.core.protocol.MessageType; +import io.seata.core.rpc.netty.v0.MessageCodecV0; +import io.seata.core.rpc.netty.v0.SerializerV0; + +/** + * The Seata codec v0. + * + * @author Bughue + */ +public class SeataV0Serializer implements SerializerV0 { + + public SeataV0Serializer() { + + } + + + @Override + public MessageCodecV0 getMsgInstanceByCode(short typeCode) { + MessageCodecV0 msgCodec = null; + switch (typeCode) { +// case MessageType.TYPE_SEATA_MERGE: +// msgCodec = new MergedWarpMessage(); +// break; +// case MessageType.TYPE_SEATA_MERGE_RESULT: +// msgCodec = new MergeResultMessage(); +// break; + case MessageType.TYPE_REG_CLT: + msgCodec = new RegisterTMRequest(); + break; + case MessageType.TYPE_REG_CLT_RESULT: + msgCodec = new RegisterTMResponse(); + break; + case MessageType.TYPE_REG_RM: + msgCodec = new RegisterRMRequest(); + break; + case MessageType.TYPE_REG_RM_RESULT: + msgCodec = new RegisterRMResponse(); + break; +// case MessageType.TYPE_BRANCH_COMMIT: +// msgCodec = new BranchCommitRequest(); +// break; +// case MessageType.TYPE_BRANCH_ROLLBACK: +// msgCodec = new BranchRollbackRequest(); +// break; + default: + break; + } + + if (null != msgCodec) { + return msgCodec; + } + + try { + msgCodec = (MessageCodecV0) getMergeRequestInstanceByCode(typeCode); + } catch (Exception exx) { + + } + if (null != msgCodec) { + return msgCodec; + } + + return (MessageCodecV0)getMergeResponseInstanceByCode(typeCode); + } + + /** + * Gets merge request instance by code. + * + * @param typeCode the type code + * @return the merge request instance by code + */ + public static MergedMessageV0 getMergeRequestInstanceByCode(int typeCode) { + switch (typeCode) { +// case MessageType.TYPE_GLOBAL_BEGIN: +// return new GlobalBeginRequest(); +// case MessageType.TYPE_GLOBAL_COMMIT: +// return new GlobalCommitRequest(); +// case MessageType.TYPE_GLOBAL_ROLLBACK: +// return new GlobalRollbackRequest(); +// case MessageType.TYPE_GLOBAL_STATUS: +// return new GlobalStatusRequest(); +// case MessageType.TYPE_GLOBAL_LOCK_QUERY: +// return new GlobalLockQueryRequest(); +// case MessageType.TYPE_BRANCH_REGISTER: +// return new BranchRegisterRequest(); +// case MessageType.TYPE_BRANCH_STATUS_REPORT: +// return new BranchReportRequest(); + default: + throw new IllegalArgumentException("not support typeCode," + typeCode); + } + } + + /** + * Gets merge response instance by code. + * + * @param typeCode the type code + * @return the merge response instance by code + */ + public static MergedMessageV0 getMergeResponseInstanceByCode(int typeCode) { + switch (typeCode) { +// case MessageType.TYPE_GLOBAL_BEGIN_RESULT: +// return new GlobalBeginResponse(); +// case MessageType.TYPE_GLOBAL_COMMIT_RESULT: +// return new GlobalCommitResponse(); +// case MessageType.TYPE_GLOBAL_ROLLBACK_RESULT: +// return new GlobalRollbackResponse(); +// case MessageType.TYPE_GLOBAL_STATUS_RESULT: +// return new GlobalStatusResponse(); +// case MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT: +// return new GlobalLockQueryResponse(); +// case MessageType.TYPE_BRANCH_REGISTER_RESULT: +// return new BranchRegisterResponse(); +// case MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT: +// return new BranchReportResponse(); +// case MessageType.TYPE_BRANCH_COMMIT_RESULT: +// return new BranchCommitResponse(); +// case MessageType.TYPE_BRANCH_ROLLBACK_RESULT: +// return new BranchRollbackResponse(); + default: + throw new IllegalArgumentException("not support typeCode," + typeCode); + } + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/SeataV1Serializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/SeataV1Serializer.java new file mode 100644 index 00000000000..b2e46218984 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/SeataV1Serializer.java @@ -0,0 +1,47 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v1; + +import com.sun.tools.javac.util.Pair; +import io.seata.common.loader.LoadLevel; +import io.seata.core.protocol.MessageType; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.protocol.RegisterRMRequest; +import io.seata.core.protocol.RegisterRMResponse; +import io.seata.core.protocol.RegisterTMRequest; +import io.seata.core.protocol.RegisterTMResponse; +import io.seata.serializer.seata.SeataAbstractSerializer; + +/** + * The Seata codec v1. + * + * @author Bughue + */ +@LoadLevel(name = "SEATA", version = ProtocolConstants.VERSION_1) +public class SeataV1Serializer extends SeataAbstractSerializer { + + public SeataV1Serializer() { + classMap.put(MessageType.TYPE_REG_CLT, new Pair<>(RegisterTMRequestCodec.class, RegisterTMRequest.class)); + classMap.put(MessageType.TYPE_REG_CLT_RESULT, new Pair<>(RegisterTMResponseCodec.class, RegisterTMResponse.class)); + classMap.put(MessageType.TYPE_REG_RM, new Pair<>(RegisterRMRequestCodec.class, RegisterRMRequest.class)); + classMap.put(MessageType.TYPE_REG_RM_RESULT, new Pair<>(RegisterRMResponseCodec.class, RegisterRMResponse.class)); + + } + + + + +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v2/package-info.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v2/package-info.java deleted file mode 100644 index 7ae085eae2c..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v2/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package io.seata.serializer.seata.protocol.v2; \ No newline at end of file diff --git a/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer b/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer index 0d76176a84c..e127901cc83 100644 --- a/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer +++ b/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer @@ -1 +1,2 @@ -io.seata.serializer.seata.SeataSerializer \ No newline at end of file +io.seata.serializer.seata.protocol.v1.SeataV1Serializer +io.seata.serializer.seata.protocol.v0.SeataV0Serializer \ No newline at end of file diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java index c102342f71a..1d8219991db 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java @@ -23,7 +23,7 @@ import io.seata.core.protocol.BatchResultMessage; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.BranchCommitResponse; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -39,7 +39,7 @@ public class BatchResultMessageSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); @Test diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java index 5e9fff4a211..891f602147e 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java @@ -15,12 +15,12 @@ */ package io.seata.serializer.seata.protocol; -import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.AbstractResultMessage; import io.seata.core.protocol.MergeResultMessage; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.GlobalBeginResponse; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -35,7 +35,7 @@ public class MergeResultMessageSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java index 3e0fc3b7994..546ead2fdc5 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java @@ -21,7 +21,7 @@ import io.seata.core.protocol.AbstractMessage; import io.seata.core.protocol.MergedWarpMessage; import io.seata.core.protocol.transaction.GlobalBeginRequest; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -37,7 +37,7 @@ public class MergedWarpMessageSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java index c2c27b06228..13d3182aadc 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java @@ -15,8 +15,8 @@ */ package io.seata.serializer.seata.protocol; -import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.RegisterRMRequest; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -31,7 +31,7 @@ public class RegisterRMRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java index 8b58f9f44e9..b82e58f84e6 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java @@ -15,9 +15,9 @@ */ package io.seata.serializer.seata.protocol; -import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.RegisterRMResponse; import io.seata.core.protocol.ResultCode; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -33,7 +33,7 @@ public class RegisterRMResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java index 99ed2a61374..672c946aafe 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java @@ -16,9 +16,9 @@ package io.seata.serializer.seata.protocol; import io.netty.buffer.ByteBuf; -import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.AbstractIdentifyRequest; import io.seata.core.protocol.RegisterTMRequest; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -37,7 +37,7 @@ public class RegisterTMRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); private static RegisterTMRequest registerTMRequest; private static AbstractIdentifyRequest air; diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java index a2a968e296c..d018d4f03b2 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java @@ -15,9 +15,9 @@ */ package io.seata.serializer.seata.protocol; -import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.RegisterTMResponse; import io.seata.core.protocol.ResultCode; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +32,7 @@ public class RegisterTMResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java index 8cadec8fb41..bc6cc7a97ba 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchCommitRequest; import org.junit.jupiter.api.Test; @@ -32,7 +32,7 @@ public class BranchCommitRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java index 7ed87e201b3..9645ca36bde 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.BranchStatus; import io.seata.core.protocol.ResultCode; @@ -34,7 +34,7 @@ public class BranchCommitResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java index 81e844f4d8b..f8897b984ab 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchRegisterRequest; import org.junit.jupiter.api.Test; @@ -32,7 +32,7 @@ public class BranchRegisterRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java index 23a277daa9c..a239420fa3b 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.BranchRegisterResponse; @@ -33,7 +33,7 @@ public class BranchRegisterResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java index fb8fcd00c82..8ff6bbfa7e2 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.model.BranchStatus; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchReportRequest; @@ -33,7 +33,7 @@ public class BranchReportRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java index 41140639c5a..1f810655a58 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.BranchReportResponse; @@ -33,7 +33,7 @@ public class BranchReportResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java index 41ad6db2cdf..f49b14c7bc2 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchRollbackRequest; import org.junit.jupiter.api.Test; @@ -32,7 +32,7 @@ public class BranchRollbackRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java index 8276be9dad6..3a75972cb1c 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.BranchStatus; import io.seata.core.protocol.ResultCode; @@ -34,7 +34,7 @@ public class BranchRollbackResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java index 4167ed2a929..0f9f4badced 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.protocol.transaction.GlobalBeginRequest; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public class GlobalBeginRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java index cc2ec27675c..c5a6efabd24 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.GlobalBeginResponse; @@ -32,7 +32,7 @@ public class GlobalBeginResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java index 885568ff46b..cbfc8eb0582 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.protocol.transaction.GlobalCommitRequest; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public class GlobalCommitRequestCodecTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java index 310a5cfc52f..d54ca92de56 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.GlobalStatus; import io.seata.core.protocol.ResultCode; @@ -33,7 +33,7 @@ public class GlobalCommitResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java index 2a1ac53e925..446746644c3 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.GlobalLockQueryRequest; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public class GlobalLockQueryRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java index 706197808b5..9456b6dd58b 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.GlobalLockQueryResponse; @@ -33,7 +33,7 @@ public class GlobalLockQueryResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java index 06a54065855..1b493c99796 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.protocol.transaction.GlobalRollbackRequest; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public class GlobalRollbackRequestCodecTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java index cd8849e6f41..2ac992dd8ff 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.GlobalStatus; import io.seata.core.protocol.ResultCode; @@ -34,7 +34,7 @@ public class GlobalRollbackResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java index 37f52de98e3..d3b0804f89b 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.protocol.transaction.GlobalStatusRequest; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public class GlobalStatusRequestCodecTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java index cc2cba4f460..2d67d80ff7e 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.GlobalStatus; import io.seata.core.protocol.ResultCode; @@ -33,7 +33,7 @@ public class GlobalStatusResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java index 742efe229cc..444f3281115 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.SeataSerializer; +import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.UndoLogDeleteRequest; import org.junit.jupiter.api.Test; @@ -32,7 +32,7 @@ public class UndoLogDeleteRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataV1Serializer seataSerializer = new SeataV1Serializer(); /** * Test codec. From 6c0898291d2f3daf8c77a6596f0c65c2ed51fd25 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 21 Aug 2023 17:23:08 +0800 Subject: [PATCH 06/22] protocol --- .../common/loader/EnhancedServiceLoader.java | 6 +- .../core/protocol/ProtocolConstants.java | 2 + .../io/seata/core/protocol/RpcMessage.java | 10 ++ .../java/io/seata/core/protocol/Version.java | 4 +- .../rpc/DefaultServerMessageListenerImpl.java | 4 +- .../java/io/seata/core/rpc/RpcContext.java | 10 ++ .../core/rpc/netty/AbstractNettyRemoting.java | 1 + .../netty/AbstractNettyRemotingClient.java | 4 +- .../netty/AbstractNettyRemotingServer.java | 35 ++-- .../seata/core/rpc/netty/ChannelManager.java | 6 +- .../rpc/netty/CompatibleProtocolDecoder.java | 76 ++++++--- .../rpc/netty/CompatibleProtocolEncoder.java | 30 +++- .../seata/core/rpc/netty/ProtocolDecoder.java | 15 ++ .../seata/core/rpc/netty/ProtocolEncoder.java | 19 +++ .../core/rpc/netty/ProtocolRpcMessage.java | 3 +- .../core/rpc/netty/TmNettyRemotingClient.java | 3 +- .../core/rpc/netty/v0/MessageCodecV0.java | 13 +- .../rpc/netty/v0/ProtocolV0Constants.java | 9 +- .../core/rpc/netty/v0/ProtocolV0Decoder.java | 36 ++-- .../core/rpc/netty/v0/ProtocolV0Encoder.java | 64 ++++++- .../rpc/netty/v0/ProtocolV0RpcMessage.java | 43 ++++- .../core/rpc/netty/v1/ProtocolV1Decoder.java | 3 +- .../core/rpc/netty/v1/ProtocolV1Encoder.java | 94 +++++----- .../rpc/netty/v1/ProtocolV1RpcMessage.java | 24 ++- .../rpc/processor/server/RegRmProcessor.java | 2 +- .../rpc/processor/server/RegTmProcessor.java | 6 +- .../seata/SeataAbstractSerializer.java | 4 +- .../v0/AbstractIdentifyRequestCodec.java | 154 +++++++++++++++++ .../v0/AbstractIdentifyResponseCodec.java | 70 ++++++++ .../protocol/v0/AbstractMessageCodec.java | 72 ++++++++ .../v0/AbstractResultMessageCodec.java | 77 +++++++++ .../protocol/v0/RegisterTMRequestCodec.java | 33 ++++ .../protocol/v0/RegisterTMResponseCodec.java | 34 ++++ .../seata/protocol/v0/SeataV0Serializer.java | 161 +++++++----------- .../AbstractIdentifyRequestV0.java} | 70 +++++++- .../AbstractIdentifyResponseV0.java} | 4 +- .../{v0 => v0_1}/AbstractMessageV0.java | 8 +- .../{v0 => v0_1}/AbstractResultMessageV0.java | 12 +- .../{v0 => v0_1}/MergedMessageV0.java | 2 +- .../RegisterRMRequestV0.java} | 8 +- .../RegisterRMResponseV0.java} | 8 +- .../RegisterTMRequestV0.java} | 10 +- .../RegisterTMResponseV0.java} | 8 +- .../protocol/v0_1/SeataV0Serializer.java | 139 +++++++++++++++ .../io.seata.core.rpc.netty.v0.SerializerV0 | 1 + .../io.seata.core.serializer.Serializer | 2 +- .../core/rpc/netty/TmNettyClientTest.java | 38 +++++ 47 files changed, 1168 insertions(+), 269 deletions(-) create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponseCodec.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageCodec.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageCodec.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{v0/AbstractIdentifyRequest.java => v0_1/AbstractIdentifyRequestV0.java} (78%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{v0/AbstractIdentifyResponse.java => v0_1/AbstractIdentifyResponseV0.java} (96%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{v0 => v0_1}/AbstractMessageV0.java (88%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{v0 => v0_1}/AbstractResultMessageV0.java (91%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{v0 => v0_1}/MergedMessageV0.java (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{v0/RegisterRMRequest.java => v0_1/RegisterRMRequestV0.java} (94%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{v0/RegisterRMResponse.java => v0_1/RegisterRMResponseV0.java} (84%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{v0/RegisterTMRequest.java => v0_1/RegisterTMRequestV0.java} (83%) rename serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/{v0/RegisterTMResponse.java => v0_1/RegisterTMResponseV0.java} (84%) create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/SeataV0Serializer.java create mode 100644 serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.rpc.netty.v0.SerializerV0 diff --git a/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java b/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java index 344f555d6c6..c8e4f9e04c3 100644 --- a/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java +++ b/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java @@ -594,13 +594,15 @@ private ExtensionDefinition getUnloadedExtensionDefinition(String className, String serviceName = null; int priority = 0; Scope scope = Scope.SINGLETON; + byte version = -1; LoadLevel loadLevel = clazz.getAnnotation(LoadLevel.class); if (loadLevel != null) { serviceName = loadLevel.name(); priority = loadLevel.order(); scope = loadLevel.scope(); + version = loadLevel.version(); } - ExtensionDefinition result = new ExtensionDefinition<>(serviceName, priority, scope, enhancedServiceClass); + ExtensionDefinition result = new ExtensionDefinition<>(serviceName, priority, scope, enhancedServiceClass, version); classToDefinitionMap.put(clazz, result); if (serviceName != null) { CollectionUtils.computeIfAbsent(nameToDefinitionsMap, serviceName, e -> new ArrayList<>()) @@ -630,7 +632,7 @@ private ExtensionDefinition getDefaultExtensionDefinition() { private ExtensionDefinition getCachedExtensionDefinition(String activateName, int version) { List> definitions = nameToDefinitionsMap.get(activateName); - if (version < 0) { + if (version >= 0) { Optional> first = definitions.stream().filter(d -> d.getVersion() == version).findFirst(); if (first.isPresent()) { return first.get(); diff --git a/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java b/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java index 769887fe6a0..500f77d8ace 100644 --- a/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java +++ b/core/src/main/java/io/seata/core/protocol/ProtocolConstants.java @@ -41,6 +41,8 @@ public interface ProtocolConstants { */ byte VERSION_1 = 1; + byte VERSION_CURRENT = VERSION_1; + /** * Max frame length */ diff --git a/core/src/main/java/io/seata/core/protocol/RpcMessage.java b/core/src/main/java/io/seata/core/protocol/RpcMessage.java index 02d611ce242..7f1f91d1ebb 100644 --- a/core/src/main/java/io/seata/core/protocol/RpcMessage.java +++ b/core/src/main/java/io/seata/core/protocol/RpcMessage.java @@ -34,6 +34,8 @@ public class RpcMessage { private Map headMap = new HashMap<>(); private Object body; + private byte protocolVersion; + /** * Gets id. * @@ -168,6 +170,14 @@ public void setMessageType(byte messageType) { this.messageType = messageType; } + public byte getProtocolVersion() { + return protocolVersion; + } + + public void setProtocolVersion(byte protocolVersion) { + this.protocolVersion = protocolVersion; + } + @Override public String toString() { return StringUtils.toString(this); diff --git a/core/src/main/java/io/seata/core/protocol/Version.java b/core/src/main/java/io/seata/core/protocol/Version.java index 2d17156c02c..96b47df8d8b 100644 --- a/core/src/main/java/io/seata/core/protocol/Version.java +++ b/core/src/main/java/io/seata/core/protocol/Version.java @@ -89,7 +89,9 @@ public static void checkVersion(String version) throws IncompatibleVersionExcept long current = convertVersion(CURRENT); long clientVersion = convertVersion(version); long divideVersion = convertVersion(VERSION_0_7_1); - if ((current > divideVersion && clientVersion < divideVersion) || (current < divideVersion && clientVersion > divideVersion)) { + if ( +// (current > divideVersion && clientVersion < divideVersion) || + (current < divideVersion && clientVersion > divideVersion)) { throw new IncompatibleVersionException("incompatible client version:" + version); } } diff --git a/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java b/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java index c81f78fb5d4..40499d1d80d 100644 --- a/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java +++ b/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java @@ -113,7 +113,7 @@ public void onRegRmMessage(RpcMessage request, ChannelHandlerContext ctx, Regist String errorInfo = StringUtils.EMPTY; try { if (checkAuthHandler == null || checkAuthHandler.regResourceManagerCheckAuth(message)) { - ChannelManager.registerRMChannel(message, ctx.channel()); + ChannelManager.registerRMChannel(message, ctx.channel(), request.getProtocolVersion()); Version.putChannelVersion(ctx.channel(), message.getVersion()); isSuccess = true; if (LOGGER.isDebugEnabled()) { @@ -145,7 +145,7 @@ public void onRegTmMessage(RpcMessage request, ChannelHandlerContext ctx, Regist String errorInfo = StringUtils.EMPTY; try { if (checkAuthHandler == null || checkAuthHandler.regTransactionManagerCheckAuth(message)) { - ChannelManager.registerTMChannel(message, ctx.channel()); + ChannelManager.registerTMChannel(message, ctx.channel(), request.getProtocolVersion()); Version.putChannelVersion(ctx.channel(), message.getVersion()); isSuccess = true; if (LOGGER.isDebugEnabled()) { diff --git a/core/src/main/java/io/seata/core/rpc/RpcContext.java b/core/src/main/java/io/seata/core/rpc/RpcContext.java index 2fe3cca0769..6a86b088126 100644 --- a/core/src/main/java/io/seata/core/rpc/RpcContext.java +++ b/core/src/main/java/io/seata/core/rpc/RpcContext.java @@ -42,6 +42,8 @@ public class RpcContext { private String version; + private byte protocolVersion; + private String applicationId; private String transactionServiceGroup; @@ -320,6 +322,14 @@ public void setClientId(String clientId) { this.clientId = clientId; } + public byte getProtocolVersion() { + return protocolVersion; + } + + public void setProtocolVersion(byte protocolVersion) { + this.protocolVersion = protocolVersion; + } + @Override public String toString() { return "RpcContext{" + diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java index 5b9cd51ae3e..1fa623e0302 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java @@ -239,6 +239,7 @@ protected RpcMessage buildRequestMessage(Object msg, byte messageType) { rpcMessage.setCodec(ProtocolConstants.CONFIGURED_CODEC); rpcMessage.setCompressor(ProtocolConstants.CONFIGURED_COMPRESSOR); rpcMessage.setBody(msg); + rpcMessage.setProtocolVersion(ProtocolConstants.VERSION_CURRENT); return rpcMessage; } diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java index 3bab93615d6..3c638bf12e3 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java @@ -56,8 +56,6 @@ import io.seata.core.protocol.transaction.GlobalBeginRequest; import io.seata.core.rpc.RemotingClient; import io.seata.core.rpc.TransactionMessageHandler; -import io.seata.core.rpc.netty.v0.ProtocolV0RpcMessage; -import io.seata.core.rpc.netty.v1.ProtocolV1RpcMessage; import io.seata.core.rpc.processor.Pair; import io.seata.core.rpc.processor.RemotingProcessor; import io.seata.discovery.loadbalance.LoadBalanceFactory; @@ -417,7 +415,7 @@ class ClientHandler extends ChannelDuplexHandler { public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { RpcMessage rpcMessage = null; if (msg instanceof ProtocolRpcMessage) { - rpcMessage = ((ProtocolRpcMessage) msg).convert2RpcMsg(); + rpcMessage = ((ProtocolRpcMessage) msg).protocolMsg2RpcMsg(); } if (rpcMessage != null) { diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java index 32a1e76e436..f8509e5ae31 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java @@ -33,8 +33,6 @@ import io.seata.core.protocol.RpcMessage; import io.seata.core.rpc.RemotingServer; import io.seata.core.rpc.RpcContext; -import io.seata.core.rpc.netty.v0.ProtocolV0RpcMessage; -import io.seata.core.rpc.netty.v1.ProtocolV1RpcMessage; import io.seata.core.rpc.processor.Pair; import io.seata.core.rpc.processor.RemotingProcessor; import org.slf4j.Logger; @@ -72,6 +70,20 @@ public Object sendSyncRequest(String resourceId, String clientId, Object msg, bo throw new RuntimeException("rm client is not connected. dbkey:" + resourceId + ",clientId:" + clientId); } RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC); + return superSendSync(channel, rpcMessage); + } + + private void superSendAsync(Channel channel, RpcMessage rpcMessage) { + //todo 优化,是否为空 + RpcContext rpcContext = ChannelManager.getContextFromIdentified(channel); + rpcMessage.setProtocolVersion(rpcContext.getProtocolVersion()); + super.sendAsync(channel, rpcMessage); + } + + private Object superSendSync(Channel channel, RpcMessage rpcMessage) throws TimeoutException { + //todo 优化,是否为空 + RpcContext rpcContext = ChannelManager.getContextFromIdentified(channel); + rpcMessage.setProtocolVersion(rpcContext.getProtocolVersion()); return super.sendSync(channel, rpcMessage, NettyServerConfig.getRpcRequestTimeout()); } @@ -81,7 +93,7 @@ public Object sendSyncRequest(Channel channel, Object msg) throws TimeoutExcepti throw new RuntimeException("client is not connected"); } RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC); - return super.sendSync(channel, rpcMessage, NettyServerConfig.getRpcRequestTimeout()); + return superSendSync(channel, rpcMessage); } @Override @@ -90,9 +102,11 @@ public void sendAsyncRequest(Channel channel, Object msg) { throw new RuntimeException("client is not connected"); } RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY); - super.sendAsync(channel, rpcMessage); + superSendAsync(channel, rpcMessage); } + + @Override public void sendAsyncResponse(RpcMessage rpcMessage, Channel channel, Object msg) { Channel clientChannel = channel; @@ -103,7 +117,7 @@ public void sendAsyncResponse(RpcMessage rpcMessage, Channel channel, Object msg RpcMessage rpcMsg = buildResponseMessage(rpcMessage, msg, msg instanceof HeartbeatMessage ? ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE : ProtocolConstants.MSGTYPE_RESPONSE); - super.sendAsync(clientChannel, rpcMsg); + superSendAsync(clientChannel, rpcMsg); } else { throw new RuntimeException("channel is error."); } @@ -165,7 +179,10 @@ class ServerHandler extends ChannelDuplexHandler { */ @Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { - RpcMessage rpcMessage= convert(msg); + RpcMessage rpcMessage = null; + if (msg instanceof ProtocolRpcMessage) { + rpcMessage = ((ProtocolRpcMessage) msg).protocolMsg2RpcMsg(); + } if (rpcMessage != null) { processMessage(ctx, rpcMessage); } else { @@ -173,12 +190,6 @@ public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exce } } - private RpcMessage convert(Object msg) { - if(msg instanceof ProtocolRpcMessage){ - return ((ProtocolRpcMessage) msg).convert2RpcMsg(); - } - return null; - } @Override public void channelWritabilityChanged(ChannelHandlerContext ctx) { diff --git a/core/src/main/java/io/seata/core/rpc/netty/ChannelManager.java b/core/src/main/java/io/seata/core/rpc/netty/ChannelManager.java index 33e39033e95..b946815045e 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/ChannelManager.java +++ b/core/src/main/java/io/seata/core/rpc/netty/ChannelManager.java @@ -120,7 +120,7 @@ private static RpcContext buildChannelHolder(NettyPoolKey.TransactionRole client * @param channel the channel * @throws IncompatibleVersionException the incompatible version exception */ - public static void registerTMChannel(RegisterTMRequest request, Channel channel) + public static void registerTMChannel(RegisterTMRequest request, Channel channel, byte protocolVersion) throws IncompatibleVersionException { Version.checkVersion(request.getVersion()); RpcContext rpcContext = buildChannelHolder(NettyPoolKey.TransactionRole.TMROLE, request.getVersion(), @@ -133,6 +133,7 @@ public static void registerTMChannel(RegisterTMRequest request, Channel channel) ConcurrentMap clientIdentifiedMap = CollectionUtils.computeIfAbsent(TM_CHANNELS, clientIdentified, key -> new ConcurrentHashMap<>()); rpcContext.holdInClientChannels(clientIdentifiedMap); + rpcContext.setProtocolVersion(protocolVersion); } /** @@ -142,7 +143,7 @@ public static void registerTMChannel(RegisterTMRequest request, Channel channel) * @param channel the channel * @throws IncompatibleVersionException the incompatible version exception */ - public static void registerRMChannel(RegisterRMRequest resourceManagerRequest, Channel channel) + public static void registerRMChannel(RegisterRMRequest resourceManagerRequest, Channel channel, byte protocolVersion) throws IncompatibleVersionException { Version.checkVersion(resourceManagerRequest.getVersion()); Set dbkeySet = dbKeytoSet(resourceManagerRequest.getResourceIds()); @@ -166,6 +167,7 @@ public static void registerRMChannel(RegisterRMRequest resourceManagerRequest, C rpcContext.holdInResourceManagerChannels(resourceId, portMap); updateChannelsResource(resourceId, clientIp, resourceManagerRequest.getApplicationId()); } + rpcContext.setProtocolVersion(protocolVersion); } private static void updateChannelsResource(String resourceId, String clientIp, String applicationId) { diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java index efec66ad187..e8528a24ba0 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java @@ -63,10 +63,6 @@ public class CompatibleProtocolDecoder extends LengthFieldBasedFrameDecoder { public CompatibleProtocolDecoder() { // default is 8M this(ProtocolConstants.MAX_FRAME_LENGTH); - protocolDecoderMap = ImmutableMap.builder() - .put(ProtocolConstants.VERSION_0, new ProtocolV0Decoder()) - .put(ProtocolConstants.VERSION_1, new ProtocolV1Decoder()) - .build(); } public CompatibleProtocolDecoder(int maxFrameLength) { @@ -78,17 +74,29 @@ int lengthFieldLength, FullLength is int(4B). so values is 4 int initialBytesToStrip we will check magic code and version self, so do not strip any bytes. so values is 0 */ super(maxFrameLength, 3, 4, -7, 0); + protocolDecoderMap = ImmutableMap.builder() + .put(ProtocolConstants.VERSION_0, new ProtocolV0Decoder()) + .put(ProtocolConstants.VERSION_1, new ProtocolV1Decoder()) + .build(); } @Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { + ByteBuf frame; Object decoded; + byte version; try { - decoded = super.decode(ctx, in); + if (isV0(in)) { + decoded = in; + version = ProtocolConstants.VERSION_0; + } else { + decoded = super.decode(ctx, in); + version = decideVersion(decoded); + } + if (decoded instanceof ByteBuf) { - ByteBuf frame = (ByteBuf) decoded; + frame = (ByteBuf) decoded; try { - byte version = decideVersion(frame); ProtocolDecoder decoder = protocolDecoderMap.get(version); if (decoder == null) { // todo 要不要适配当前版本? @@ -96,29 +104,57 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception } return decoder.decodeFrame(frame); } finally { - frame.release(); + if(!isV0(version)){ + frame.release(); + } } } } catch (Exception exx) { LOGGER.error("Decode frame error, cause: {}", exx.getMessage()); + //todo + exx.printStackTrace(); throw new DecodeException(exx); } return decoded; } - protected byte decideVersion(ByteBuf frame) { - frame.markReaderIndex(); - byte b0 = frame.readByte(); - byte b1 = frame.readByte(); - if (ProtocolConstants.MAGIC_CODE_BYTES[0] != b0 - || ProtocolConstants.MAGIC_CODE_BYTES[1] != b1) { - throw new IllegalArgumentException("Unknown magic code: " + b0 + ", " + b1); - } + protected byte decideVersion(Object in) { + if (in instanceof ByteBuf) { + ByteBuf frame = (ByteBuf) in; + frame.markReaderIndex(); + byte b0 = frame.readByte(); + byte b1 = frame.readByte(); + if (ProtocolConstants.MAGIC_CODE_BYTES[0] != b0 + || ProtocolConstants.MAGIC_CODE_BYTES[1] != b1) { + throw new IllegalArgumentException("Unknown magic code: " + b0 + ", " + b1); + } - byte version = frame.readByte(); - frame.resetReaderIndex(); - return version; + byte version = frame.readByte(); + frame.resetReaderIndex(); + return version; + } + // todo + return -1; } -} + protected boolean isV0(ByteBuf in) { + boolean isV0 = false; + in.markReaderIndex(); + byte b0 = in.readByte(); + byte b1 = in.readByte(); + byte version = in.readByte(); + if (ProtocolConstants.MAGIC_CODE_BYTES[0] == b0 + && ProtocolConstants.MAGIC_CODE_BYTES[1] == b1 + && isV0(version)) { + isV0 = true; + } + + in.resetReaderIndex(); + return isV0; + } + + protected boolean isV0(byte version) { + return version == ProtocolConstants.VERSION_0; + } +} \ No newline at end of file diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java index f1482cee564..20c637730bf 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java @@ -15,13 +15,22 @@ */ package io.seata.core.rpc.netty; +import com.google.common.collect.ImmutableMap; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.v0.ProtocolV0Decoder; +import io.seata.core.rpc.netty.v0.ProtocolV0Encoder; +import io.seata.core.rpc.netty.v1.ProtocolV1Decoder; +import io.seata.core.rpc.netty.v1.ProtocolV1Encoder; +import io.seata.core.rpc.netty.v1.ProtocolV1RpcMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Map; + /** *
      * 
    @@ -39,11 +48,30 @@ public class CompatibleProtocolEncoder extends MessageToByteEncoder { private static final Logger LOGGER = LoggerFactory.getLogger(CompatibleProtocolEncoder.class); + private static Map protocolEncoderMap; + + public CompatibleProtocolEncoder(){ + super(); + protocolEncoderMap = ImmutableMap.builder() + .put(ProtocolConstants.VERSION_0, new ProtocolV0Encoder()) + .put(ProtocolConstants.VERSION_1, new ProtocolV1Encoder()) + .build(); + } + @Override public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) { try { if (msg instanceof RpcMessage) { - // todo 调用子类进行encode,公共逻辑现在没有抽取 + RpcMessage rpcMessage = (RpcMessage) msg; + byte version = rpcMessage.getProtocolVersion(); + ProtocolEncoder encoder = protocolEncoderMap.get(version); + if (encoder == null) { + // todo 要不要适配当前版本? + throw new IllegalArgumentException("Unknown version: " + version); + } + + encoder.encode(rpcMessage,out); + } else { throw new UnsupportedOperationException("Not support this class:" + msg.getClass()); } diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java index 5f1fc6a90dd..d6ebb3f6974 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.seata.core.rpc.netty; import io.netty.buffer.ByteBuf; diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java index ceca3e9bd7f..74bf1b1b2d7 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java @@ -1,4 +1,23 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.seata.core.rpc.netty; +import io.netty.buffer.ByteBuf; +import io.seata.core.protocol.RpcMessage; + public interface ProtocolEncoder { + void encode(RpcMessage rpcMessage, ByteBuf out); } diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java index 13c60b59900..5ce758d7d50 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java @@ -8,6 +8,7 @@ * @author Bughue */ public interface ProtocolRpcMessage { - RpcMessage convert2RpcMsg(); + RpcMessage protocolMsg2RpcMsg(); + void rpcMsg2ProtocolMsg(RpcMessage rpcMessage); } diff --git a/core/src/main/java/io/seata/core/rpc/netty/TmNettyRemotingClient.java b/core/src/main/java/io/seata/core/rpc/netty/TmNettyRemotingClient.java index e2a238b61df..c90db35f386 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/TmNettyRemotingClient.java +++ b/core/src/main/java/io/seata/core/rpc/netty/TmNettyRemotingClient.java @@ -221,7 +221,8 @@ public void onRegisterMsgSuccess(String serverAddress, Channel channel, Object r RegisterTMRequest registerTMRequest = (RegisterTMRequest) requestMessage; RegisterTMResponse registerTMResponse = (RegisterTMResponse) response; if (LOGGER.isInfoEnabled()) { - LOGGER.info("register TM success. client version:{}, server version:{},channel:{}", registerTMRequest.getVersion(), registerTMResponse.getVersion(), channel); + LOGGER.info("register TM success. client version:{}, server version:{},channel:{}", + registerTMRequest.getVersion(), registerTMResponse.getVersion(), channel); } getClientChannelManager().registerChannel(serverAddress, channel); } diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java b/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java index 2aa97266097..da241f2666a 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java @@ -16,6 +16,9 @@ package io.seata.core.rpc.netty.v0; import io.netty.buffer.ByteBuf; +import io.seata.core.protocol.AbstractIdentifyRequest; +import io.seata.core.protocol.AbstractMessage; +import io.seata.core.protocol.MessageTypeAware; /** * The interface Message codec. @@ -23,13 +26,7 @@ * @author jimin.jm @alibaba-inc.com * @date 2018 /9/14 */ -public interface MessageCodecV0 { - /** - * Gets type code. - * - * @return the type code - */ - short getTypeCode(); +public interface MessageCodecV0 extends MessageTypeAware { /** * Encode byte [ ]. @@ -45,4 +42,6 @@ public interface MessageCodecV0 { * @return the boolean */ boolean decode(ByteBuf in); + + boolean decode(ByteBuf in, T req); } diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java index 2a01f35e6c0..be761391727 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java @@ -22,10 +22,11 @@ * @date 2023/7/18 **/ public class ProtocolV0Constants { + public static short MAGIC = (short)0xdada; public static int HEAD_LENGTH = 14; - public static final int FLAG_REQUEST = 0x80; - public static final int FLAG_ASYNC = 0x40; - public static final int FLAG_HEARTBEAT = 0x20; - public static final int FLAG_SEATA_CODEC = 0x10; + public static final short FLAG_REQUEST = 0x80; + public static final short FLAG_ASYNC = 0x40; + public static final short FLAG_HEARTBEAT = 0x20; + public static final short FLAG_SEATA_CODEC = 0x10; } diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java index 33b26e09186..979dcd66e13 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java @@ -19,8 +19,12 @@ import io.seata.common.loader.EnhancedServiceLoader; import io.seata.core.protocol.HeartbeatMessage; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.rpc.RegisterCheckAuthHandler; import io.seata.core.rpc.netty.ProtocolDecoder; +import io.seata.core.serializer.Serializer; +import io.seata.core.serializer.SerializerServiceLoader; +import io.seata.core.serializer.SerializerType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,6 +67,7 @@ public class ProtocolV0Decoder implements ProtocolDecoder { @Override public ProtocolV0RpcMessage decodeFrame(ByteBuf in) { + ProtocolV0RpcMessage rpcMessage = new ProtocolV0RpcMessage(); // todo 旧版本是直接返回跳过了,我们需要保留这个逻辑?【特殊】 if (in.readableBytes() < ProtocolV0Constants.HEAD_LENGTH) { throw new IllegalArgumentException("Nothing to decode."); @@ -79,7 +84,7 @@ public ProtocolV0RpcMessage decodeFrame(ByteBuf in) { boolean isHeartbeat = (ProtocolV0Constants.FLAG_HEARTBEAT & flag) > 0; boolean isRequest = (ProtocolV0Constants.FLAG_REQUEST & flag) > 0; boolean isSeataCodec = (ProtocolV0Constants.FLAG_SEATA_CODEC & flag) > 0; - + rpcMessage.setSeataCodec(isSeataCodec); short bodyLength = 0; short typeCode = 0; @@ -89,9 +94,8 @@ public ProtocolV0RpcMessage decodeFrame(ByteBuf in) { typeCode = in.readShort(); } long msgId = in.readLong(); + rpcMessage.setId(msgId); if (isHeartbeat) { - ProtocolV0RpcMessage rpcMessage = new ProtocolV0RpcMessage(); - rpcMessage.setId(msgId); rpcMessage.setAsync(true); rpcMessage.setHeartbeat(isHeartbeat); rpcMessage.setRequest(isRequest); @@ -110,19 +114,31 @@ public ProtocolV0RpcMessage decodeFrame(ByteBuf in) { throw new IllegalArgumentException("readableBytes < bodyLength"); } - ProtocolV0RpcMessage rpcMessage = new ProtocolV0RpcMessage(); - rpcMessage.setId(msgId); rpcMessage.setAsync((ProtocolV0Constants.FLAG_ASYNC & flag) > 0); rpcMessage.setHeartbeat(false); rpcMessage.setRequest(isRequest); try { + // v0_1 // todo serializer==null - MessageCodecV0 msgCodec = serializer.getMsgInstanceByCode(typeCode); - if (!msgCodec.decode(in)) { - throw new IllegalArgumentException("decode fail."); - } - rpcMessage.setBody(msgCodec); +// MessageCodecV0 msgCodec = serializer.getMsgInstanceByCode(typeCode); +// if (!msgCodec.decode(in)) { +// throw new IllegalArgumentException("decode fail."); +// } +// rpcMessage.setBody(msgCodec); + + // v0_2 + int length = in.readableBytes(); + byte[] bs = new byte[length]; + in.readBytes(bs); + byte[] bs2 = new byte[2 + length]; + bs2[0] = (byte) (0x00FF & (typeCode>>8)); + bs2[1] = (byte) (0x00FF & typeCode); + System.arraycopy(bs,0,bs2,2, length); + byte codecType = isSeataCodec? SerializerType.SEATA.getCode():SerializerType.HESSIAN.getCode(); + Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codecType), ProtocolConstants.VERSION_0); + rpcMessage.setBody(serializer.deserialize(bs2)); + } catch (Exception e) { LOGGER.error("decode error", "", e); throw e; diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java index c32aa507388..8e1cfc4a599 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java @@ -17,10 +17,23 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +import io.seata.core.compressor.Compressor; +import io.seata.core.compressor.CompressorFactory; +import io.seata.core.protocol.HeartbeatMessage; +import io.seata.core.protocol.MessageTypeAware; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.netty.ProtocolEncoder; +import io.seata.core.rpc.netty.ProtocolRpcMessage; +import io.seata.core.rpc.netty.v1.ProtocolV1RpcMessage; +import io.seata.core.serializer.Serializer; +import io.seata.core.serializer.SerializerServiceLoader; +import io.seata.core.serializer.SerializerType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.nio.ByteBuffer; + /** *
      *  seata-version < 0.7
    @@ -49,13 +62,62 @@
      * @see ProtocolV0Decoder
      * @since 2.0.0
      */
    -public class ProtocolV0Encoder {
    +public class ProtocolV0Encoder implements ProtocolEncoder {
     
         private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV0Encoder.class);
     
         public static void encode(ChannelHandlerContext ctx, ProtocolV0RpcMessage rpcMessage, ByteBuf out) {
             try {
                 // todo 按照旧协议方式encode
    +            System.out.println();
    +        } catch (Throwable e) {
    +            LOGGER.error("Encode request error!", e);
    +        }
    +    }
    +
    +    @Override
    +    public void encode(RpcMessage message, ByteBuf out) {
    +        try {
    +            byte codec = message.getCodec();
    +            ProtocolV0RpcMessage msg = new ProtocolV0RpcMessage();
    +            msg.rpcMsg2ProtocolMsg(message);
    +
    +            out.writeShort(ProtocolV0Constants.MAGIC);
    +            int flag = (msg.isAsync() ? ProtocolV0Constants.FLAG_ASYNC : 0)
    +                    | (msg.isHeartbeat() ? ProtocolV0Constants.FLAG_HEARTBEAT : 0)
    +                    | (msg.isRequest() ? ProtocolV0Constants.FLAG_REQUEST : 0)
    +                    | (msg.isSeataCodec() ? ProtocolV0Constants.FLAG_SEATA_CODEC : 0);
    +
    +            out.writeShort((short) flag);
    +
    +            if (msg.getBody() instanceof HeartbeatMessage) {
    +                out.writeShort((short) 0);
    +                out.writeLong(msg.getId());
    +                return;
    +            }
    +
    +
    +
    +            byte[] bodyBytes = null;
    +            Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codec), ProtocolConstants.VERSION_0);
    +            bodyBytes = serializer.serialize(msg.getBody());
    +
    +            if(msg.isSeataCodec()){
    +                if(msg.getBody() instanceof MessageTypeAware){
    +                    short typeCode = ((MessageTypeAware) msg.getBody()).getTypeCode();
    +                    out.writeShort(typeCode);
    +                }
    +            }else {
    +                out.writeShort(bodyBytes.length);
    +            }
    +            out.writeLong(msg.getId());
    +            if (bodyBytes != null) {
    +                out.writeBytes(bodyBytes);
    +            }
    +
    +            if (LOGGER.isDebugEnabled()) {
    +                LOGGER.debug("Send:" + msg.getBody());
    +            }
             } catch (Throwable e) {
                 LOGGER.error("Encode request error!", e);
             }
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java
    index c9c78644186..3ed60fb8167 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java
    @@ -50,7 +50,7 @@ public static long getNextMessageId() {
         private boolean isRequest;
         private boolean isHeartbeat;
         private Object body;
    -
    +    private byte messageType;
         private boolean isSeataCodec;
     
         /**
    @@ -151,29 +151,58 @@ public void setSeataCodec(boolean seataCodec) {
             isSeataCodec = seataCodec;
         }
     
    +    public byte getMessageType() {
    +        return messageType;
    +    }
    +
    +    public void setMessageType(byte messageType) {
    +        this.messageType = messageType;
    +    }
    +
         @Override
    -    public RpcMessage convert2RpcMsg(){
    +    public RpcMessage protocolMsg2RpcMsg(){
             RpcMessage rpcMessage = new RpcMessage();
    +        rpcMessage.setMessageType(this.messageType);
             // todo 基础配置
             rpcMessage.setCompressor(CompressorType.NONE.getCode());
     
    -        byte codecType = isSeataCodec? SerializerType.SEATA.getCode():SerializerType.HESSIAN.getCode();
    +        byte codecType = this.isSeataCodec? SerializerType.SEATA.getCode():SerializerType.HESSIAN.getCode();
             rpcMessage.setCodec(codecType);
     
    -        if(isHeartbeat){
    -            if(isRequest){
    +        if(this.isHeartbeat){
    +            if(this.isRequest){
                     rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST);
                 }else {
                     rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE);
                 }
             }else {
    -            if(isRequest){
    +            if(this.isRequest){
                     rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY);
                 }else {
                     rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESPONSE);
                 }
             }
    -
    +        rpcMessage.setBody(this.body);
    +        rpcMessage.setId((int) this.id);
             return rpcMessage;
         }
    +
    +    @Override
    +    public void rpcMsg2ProtocolMsg(RpcMessage rpcMessage) {
    +        this.body = rpcMessage.getBody();
    +        this.id = rpcMessage.getId();
    +        this.isRequest = isRequest(rpcMessage.getMessageType());
    +        this.isHeartbeat = isHeartbeat(rpcMessage.getMessageType());
    +        this.isSeataCodec = rpcMessage.getCodec() ==SerializerType.SEATA.getCode();
    +        this.messageType = rpcMessage.getMessageType();
    +    }
    +
    +    private boolean isHeartbeat(byte msgType){
    +        return msgType==ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST
    +                || msgType ==ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE;
    +    }
    +    private boolean isRequest(byte msgType){
    +        return msgType==ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY
    +                || msgType ==ProtocolConstants.MSGTYPE_RESQUEST_SYNC;
    +    }
     }
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java
    index 4b6bad758a8..08354348547 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java
    @@ -105,7 +105,8 @@ public ProtocolRpcMessage decodeFrame(ByteBuf frame) {
                 Compressor compressor = CompressorFactory.getCompressor(compressorType);
                 bs = compressor.decompress(bs);
                 Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codecType),version);
    -            return serializer.deserialize(bs);
    +            rpcMessage.setBody(serializer.deserialize(bs));
    +            return rpcMessage;
             }
     
             return rpcMessage;
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    index 95c0348c3c3..6e22ad809db 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    @@ -16,6 +16,9 @@
     package io.seata.core.rpc.netty.v1;
     
     import io.netty.buffer.ByteBuf;
    +import io.seata.core.protocol.RpcMessage;
    +import io.seata.core.rpc.netty.ProtocolEncoder;
    +import io.seata.core.rpc.netty.ProtocolRpcMessage;
     import io.seata.core.rpc.netty.v0.ProtocolV0Encoder;
     import io.seata.core.serializer.Serializer;
     import io.seata.core.compressor.Compressor;
    @@ -55,62 +58,61 @@
      * @see ProtocolV1Decoder
      * @since 0.7.0
      */
    -public class ProtocolV1Encoder{
    +public class ProtocolV1Encoder implements ProtocolEncoder {
     
         private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV0Encoder.class);
     
    -    public static void encode(ProtocolV1RpcMessage rpcMessage, ByteBuf out) {
    +
    +    public void encode(RpcMessage message, ByteBuf out) {
             try {
    -            // todo 外层已经判断好,可以去掉
    -//            if (msg instanceof RpcMessage) {
    -//                RpcMessage rpcMessage = (RpcMessage) msg;
    +            ProtocolV1RpcMessage rpcMessage = new ProtocolV1RpcMessage();
    +            rpcMessage.rpcMsg2ProtocolMsg(message);
    +
    +            int fullLength = ProtocolConstants.V1_HEAD_LENGTH;
    +            int headLength = ProtocolConstants.V1_HEAD_LENGTH;
    +
    +            byte messageType = rpcMessage.getMessageType();
    +            out.writeBytes(ProtocolConstants.MAGIC_CODE_BYTES);
    +            out.writeByte(ProtocolConstants.VERSION_1);
    +            // full Length(4B) and head length(2B) will fix in the end.
    +            out.writerIndex(out.writerIndex() + 6);
    +            out.writeByte(messageType);
    +            out.writeByte(rpcMessage.getCodec());
    +            out.writeByte(rpcMessage.getCompressor());
    +            out.writeInt(rpcMessage.getId());
     
    -                int fullLength = ProtocolConstants.V1_HEAD_LENGTH;
    -                int headLength = ProtocolConstants.V1_HEAD_LENGTH;
    +            // direct write head with zero-copy
    +            Map headMap = rpcMessage.getHeadMap();
    +            if (headMap != null && !headMap.isEmpty()) {
    +                int headMapBytesLength = HeadMapSerializer.getInstance().encode(headMap, out);
    +                headLength += headMapBytesLength;
    +                fullLength += headMapBytesLength;
    +            }
     
    -                byte messageType = rpcMessage.getMessageType();
    -                out.writeBytes(ProtocolConstants.MAGIC_CODE_BYTES);
    -                out.writeByte(ProtocolConstants.VERSION_1);
    -                // full Length(4B) and head length(2B) will fix in the end. 
    -                out.writerIndex(out.writerIndex() + 6);
    -                out.writeByte(messageType);
    -                out.writeByte(rpcMessage.getCodec());
    -                out.writeByte(rpcMessage.getCompressor());
    -                out.writeInt(rpcMessage.getId());
    +            byte[] bodyBytes = null;
    +            if (messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST
    +                    && messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) {
    +                // heartbeat has no body
    +                Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec()), ProtocolConstants.VERSION_1);
    +                bodyBytes = serializer.serialize(rpcMessage.getBody());
    +                Compressor compressor = CompressorFactory.getCompressor(rpcMessage.getCompressor());
    +                bodyBytes = compressor.compress(bodyBytes);
    +                fullLength += bodyBytes.length;
    +            }
     
    -                // direct write head with zero-copy
    -                Map headMap = rpcMessage.getHeadMap();
    -                if (headMap != null && !headMap.isEmpty()) {
    -                    int headMapBytesLength = HeadMapSerializer.getInstance().encode(headMap, out);
    -                    headLength += headMapBytesLength;
    -                    fullLength += headMapBytesLength;
    -                }
    +            if (bodyBytes != null) {
    +                out.writeBytes(bodyBytes);
    +            }
     
    -                byte[] bodyBytes = null;
    -                if (messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST
    -                        && messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) {
    -                    // heartbeat has no body
    -                    Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec()), ProtocolConstants.VERSION_1);
    -                    bodyBytes = serializer.serialize(rpcMessage.getBody());
    -                    Compressor compressor = CompressorFactory.getCompressor(rpcMessage.getCompressor());
    -                    bodyBytes = compressor.compress(bodyBytes);
    -                    fullLength += bodyBytes.length;
    -                }
    +            // fix fullLength and headLength
    +            int writeIndex = out.writerIndex();
    +            // skip magic code(2B) + version(1B)
    +            out.writerIndex(writeIndex - fullLength + 3);
    +            out.writeInt(fullLength);
    +            out.writeShort(headLength);
    +            out.writerIndex(writeIndex);
     
    -                if (bodyBytes != null) {
    -                    out.writeBytes(bodyBytes);
    -                }
     
    -                // fix fullLength and headLength
    -                int writeIndex = out.writerIndex();
    -                // skip magic code(2B) + version(1B)
    -                out.writerIndex(writeIndex - fullLength + 3);
    -                out.writeInt(fullLength);
    -                out.writeShort(headLength);
    -                out.writerIndex(writeIndex);
    -//            } else {
    -//                throw new UnsupportedOperationException("Not support this class:" + msg.getClass());
    -//            }
             } catch (Throwable e) {
                 LOGGER.error("Encode request error!", e);
             }
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java
    index 47d51504908..60578e2be6c 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java
    @@ -16,11 +16,9 @@
     package io.seata.core.rpc.netty.v1;
     
     import io.seata.common.util.StringUtils;
    -import io.seata.core.compressor.CompressorType;
     import io.seata.core.protocol.ProtocolConstants;
     import io.seata.core.protocol.RpcMessage;
     import io.seata.core.rpc.netty.ProtocolRpcMessage;
    -import io.seata.core.serializer.SerializerType;
     
     import java.util.HashMap;
     import java.util.Map;
    @@ -177,11 +175,25 @@ public String toString() {
         }
     
         @Override
    -    public RpcMessage convert2RpcMsg(){
    +    public RpcMessage protocolMsg2RpcMsg(){
             RpcMessage rpcMessage = new RpcMessage();
    -        // todo
    -
    -
    +        rpcMessage.setId(this.id);
    +        rpcMessage.setMessageType(this.messageType);
    +        rpcMessage.setCodec(this.codec);
    +        rpcMessage.setCompressor(this.compressor);
    +        rpcMessage.setHeadMap(this.headMap);
    +        rpcMessage.setBody(this.body);
    +        rpcMessage.setProtocolVersion(ProtocolConstants.VERSION_1);
             return rpcMessage;
         }
    +
    +    @Override
    +    public void rpcMsg2ProtocolMsg(RpcMessage rpcMessage) {
    +        this.body = rpcMessage.getBody();
    +        this.headMap = rpcMessage.getHeadMap();
    +        this.id = rpcMessage.getId();
    +        this.messageType = rpcMessage.getMessageType();
    +        this.codec = rpcMessage.getCodec();
    +        this.compressor = rpcMessage.getCompressor();
    +    }
     }
    diff --git a/core/src/main/java/io/seata/core/rpc/processor/server/RegRmProcessor.java b/core/src/main/java/io/seata/core/rpc/processor/server/RegRmProcessor.java
    index 1e4767387a2..03b8af68f2e 100644
    --- a/core/src/main/java/io/seata/core/rpc/processor/server/RegRmProcessor.java
    +++ b/core/src/main/java/io/seata/core/rpc/processor/server/RegRmProcessor.java
    @@ -64,7 +64,7 @@ private void onRegRmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) {
             String errorInfo = StringUtils.EMPTY;
             try {
                 if (null == checkAuthHandler || checkAuthHandler.regResourceManagerCheckAuth(message)) {
    -                ChannelManager.registerRMChannel(message, ctx.channel());
    +                ChannelManager.registerRMChannel(message, ctx.channel(), rpcMessage.getProtocolVersion());
                     Version.putChannelVersion(ctx.channel(), message.getVersion());
                     isSuccess = true;
                     if (LOGGER.isDebugEnabled()) {
    diff --git a/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java b/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java
    index 75c4fb71755..985f7ac1cc4 100644
    --- a/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java
    +++ b/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java
    @@ -65,7 +65,7 @@ private void onRegTmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) {
             String errorInfo = StringUtils.EMPTY;
             try {
                 if (null == checkAuthHandler || checkAuthHandler.regTransactionManagerCheckAuth(message)) {
    -                ChannelManager.registerTMChannel(message, ctx.channel());
    +                ChannelManager.registerTMChannel(message, ctx.channel(), rpcMessage.getProtocolVersion());
                     Version.putChannelVersion(ctx.channel(), message.getVersion());
                     isSuccess = true;
                     if (LOGGER.isDebugEnabled()) {
    @@ -89,8 +89,8 @@ private void onRegTmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) {
             }
             remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), response);
             if (isSuccess && LOGGER.isInfoEnabled()) {
    -            LOGGER.info("TM register success,message:{},channel:{},client version:{}", message, ctx.channel(),
    -                message.getVersion());
    +            LOGGER.info("TM register success,message:{},channel:{},client version:{},client protocol-version:{}"
    +                    , message, ctx.channel(), message.getVersion(), rpcMessage.getProtocolVersion());
             }
         }
     
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java
    index 762692afc93..9c590ea0bf4 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java
    @@ -104,7 +104,7 @@ public  T deserialize(byte[] bytes) {
             return (T)abstractMessage;
         }
     
    -    private AbstractMessage getMessageByType(short typecode) {
    +    protected AbstractMessage getMessageByType(short typecode) {
             try {
                 return getMessageClass(typecode).newInstance();
             } catch (InstantiationException e) {
    @@ -114,7 +114,7 @@ private AbstractMessage getMessageByType(short typecode) {
             }
         }
     
    -    private MessageSeataCodec getCodecByType(short typecode) {
    +    protected MessageSeataCodec getCodecByType(short typecode) {
             try {
                 return getCodecClass(typecode).newInstance();
             } catch (InstantiationException e) {
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java
    new file mode 100644
    index 00000000000..6cfb8733271
    --- /dev/null
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java
    @@ -0,0 +1,154 @@
    +/*
    + *  Copyright 1999-2019 Seata.io Group.
    + *
    + *  Licensed under the Apache License, Version 2.0 (the "License");
    + *  you may not use this file except in compliance with the License.
    + *  You may obtain a copy of the License at
    + *
    + *       http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing, software
    + *  distributed under the License is distributed on an "AS IS" BASIS,
    + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  See the License for the specific language governing permissions and
    + *  limitations under the License.
    + */
    +package io.seata.serializer.seata.protocol.v0;
    +
    +import io.netty.buffer.ByteBuf;
    +import io.seata.core.protocol.AbstractIdentifyRequest;
    +
    +import java.nio.ByteBuffer;
    +
    +/**
    + * The type Abstract identify request codec.
    + */
    +public abstract class AbstractIdentifyRequestCodec extends AbstractMessageCodec {
    +
    +    @Override
    +    public Class getMessageClassType() {
    +        return AbstractIdentifyRequest.class;
    +    }
    +
    +    /**
    +     * Do encode.
    +     *
    +     * @param  the type parameter
    +     * @param t   the t
    +     * @param out the out
    +     */
    +    protected  void doEncode(T t, ByteBuf out) {
    +        AbstractIdentifyRequest abstractIdentifyRequest = (AbstractIdentifyRequest)t;
    +        String version = abstractIdentifyRequest.getVersion();
    +        String applicationId = abstractIdentifyRequest.getApplicationId();
    +        String transactionServiceGroup = abstractIdentifyRequest.getTransactionServiceGroup();
    +        String extraData = abstractIdentifyRequest.getExtraData();
    +
    +        if (version != null) {
    +            byte[] bs = version.getBytes(UTF8);
    +            out.writeShort((short)bs.length);
    +            if (bs.length > 0) {
    +                out.writeBytes(bs);
    +            }
    +        } else {
    +            out.writeShort((short)0);
    +        }
    +
    +        if (applicationId != null) {
    +            byte[] bs = applicationId.getBytes(UTF8);
    +            out.writeShort((short)bs.length);
    +            if (bs.length > 0) {
    +                out.writeBytes(bs);
    +            }
    +        } else {
    +            out.writeShort((short)0);
    +        }
    +
    +        if (transactionServiceGroup != null) {
    +            byte[] bs = transactionServiceGroup.getBytes(UTF8);
    +            out.writeShort((short)bs.length);
    +            if (bs.length > 0) {
    +                out.writeBytes(bs);
    +            }
    +        } else {
    +            out.writeShort((short)0);
    +        }
    +
    +        if (extraData != null) {
    +            byte[] bs = extraData.getBytes(UTF8);
    +            out.writeShort((short)bs.length);
    +            if (bs.length > 0) {
    +                out.writeBytes(bs);
    +            }
    +        } else {
    +            out.writeShort((short)0);
    +        }
    +
    +    }
    +
    +    @Override
    +    public  void encode(T t, ByteBuf out) {
    +        doEncode(t, out);
    +    }
    +
    +    @Override
    +    public  void decode(T t, ByteBuffer in) {
    +        AbstractIdentifyRequest abstractIdentifyRequest = (AbstractIdentifyRequest)t;
    +
    +        //version len
    +        short len = 0;
    +        if (in.remaining() < 2) {
    +            return;
    +        }
    +        len = in.getShort();
    +        //version
    +        if (in.remaining() < len) {
    +            return;
    +        }
    +        byte[] bs = new byte[len];
    +        in.get(bs);
    +        abstractIdentifyRequest.setVersion(new String(bs, UTF8));
    +
    +        //applicationId len
    +        if (in.remaining() < 2) {
    +            return;
    +        }
    +        len = in.getShort();
    +        //applicationId
    +        if (in.remaining() < len) {
    +            return;
    +        }
    +        bs = new byte[len];
    +        in.get(bs);
    +        abstractIdentifyRequest.setApplicationId(new String(bs, UTF8));
    +
    +        //transactionServiceGroup len
    +        if (in.remaining() < 2) {
    +            return;
    +        }
    +        len = in.getShort();
    +
    +        //transactionServiceGroup
    +        if (in.remaining() < len) {
    +            return;
    +        }
    +        bs = new byte[len];
    +        in.get(bs);
    +        abstractIdentifyRequest.setTransactionServiceGroup(new String(bs, UTF8));
    +
    +        //ExtraData len
    +        if (in.remaining() < 2) {
    +            return;
    +        }
    +        len = in.getShort();
    +
    +        if (in.remaining() >= len) {
    +            bs = new byte[len];
    +            in.get(bs);
    +            abstractIdentifyRequest.setExtraData(new String(bs, UTF8));
    +        } else {
    +            //maybe null
    +        }
    +    }
    +
    +}
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponseCodec.java
    new file mode 100644
    index 00000000000..aa64e57b88f
    --- /dev/null
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponseCodec.java
    @@ -0,0 +1,70 @@
    +/*
    + *  Copyright 1999-2019 Seata.io Group.
    + *
    + *  Licensed under the Apache License, Version 2.0 (the "License");
    + *  you may not use this file except in compliance with the License.
    + *  You may obtain a copy of the License at
    + *
    + *       http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing, software
    + *  distributed under the License is distributed on an "AS IS" BASIS,
    + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  See the License for the specific language governing permissions and
    + *  limitations under the License.
    + */
    +package io.seata.serializer.seata.protocol.v0;
    +
    +import io.netty.buffer.ByteBuf;
    +import io.seata.core.protocol.AbstractIdentifyResponse;
    +
    +import java.nio.ByteBuffer;
    +
    +/**
    + * The type Abstract identify response.
    + *
    + * @author sharajava
    + */
    +public abstract class AbstractIdentifyResponseCodec extends AbstractResultMessageCodec {
    +
    +    @Override
    +    public Class getMessageClassType() {
    +        return AbstractIdentifyResponse.class;
    +    }
    +
    +    @Override
    +    public  void encode(T t, ByteBuf out) {
    +        AbstractIdentifyResponse abstractIdentifyResponse = (AbstractIdentifyResponse)t;
    +        boolean identified = abstractIdentifyResponse.isIdentified();
    +        String version = abstractIdentifyResponse.getVersion();
    +
    +        out.writeByte(identified ? (byte)1 : (byte)0);
    +        if (version != null) {
    +            byte[] bs = version.getBytes(UTF8);
    +            out.writeShort((short)bs.length);
    +            if (bs.length > 0) {
    +                out.writeBytes(bs);
    +            }
    +        } else {
    +            out.writeShort((short)0);
    +        }
    +    }
    +
    +    @Override
    +    public  void decode(T t, ByteBuffer in) {
    +        AbstractIdentifyResponse abstractIdentifyResponse = (AbstractIdentifyResponse)t;
    +
    +        abstractIdentifyResponse.setIdentified(in.get() == 1);
    +        short len = in.getShort();
    +        if (len <= 0) {
    +            return;
    +        }
    +        if (in.remaining() < len) {
    +            return;
    +        }
    +        byte[] bs = new byte[len];
    +        in.get(bs);
    +        abstractIdentifyResponse.setVersion(new String(bs, UTF8));
    +    }
    +
    +}
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageCodec.java
    new file mode 100644
    index 00000000000..68d93d95efc
    --- /dev/null
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageCodec.java
    @@ -0,0 +1,72 @@
    +/*
    + *  Copyright 1999-2019 Seata.io Group.
    + *
    + *  Licensed under the Apache License, Version 2.0 (the "License");
    + *  you may not use this file except in compliance with the License.
    + *  You may obtain a copy of the License at
    + *
    + *       http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing, software
    + *  distributed under the License is distributed on an "AS IS" BASIS,
    + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  See the License for the specific language governing permissions and
    + *  limitations under the License.
    + */
    +package io.seata.serializer.seata.protocol.v0;
    +
    +import io.seata.serializer.seata.MessageSeataCodec;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.nio.charset.Charset;
    +import java.nio.charset.StandardCharsets;
    +
    +/**
    + * The type Abstract message codec.
    + *
    + * @author zhangsen
    + */
    +public abstract class AbstractMessageCodec implements MessageSeataCodec {
    +
    +    /**
    +     * The constant LOGGER.
    +     */
    +    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractMessageCodec.class);
    +
    +    /**
    +     * The constant UTF8.
    +     */
    +    protected static final Charset UTF8 = StandardCharsets.UTF_8;
    +
    +    /**
    +     * Bytes to int int.
    +     *
    +     * @param bytes  the bytes
    +     * @param offset the offset
    +     * @return the int
    +     */
    +    public static int bytesToInt(byte[] bytes, int offset) {
    +        int ret = 0;
    +        for (int i = 0; i < 4 && i + offset < bytes.length; i++) {
    +            ret <<= 8;
    +            ret |= (int)bytes[i + offset] & 0xFF;
    +        }
    +        return ret;
    +    }
    +
    +    /**
    +     * Int to bytes.
    +     *
    +     * @param i      the
    +     * @param bytes  the bytes
    +     * @param offset the offset
    +     */
    +    public static void intToBytes(int i, byte[] bytes, int offset) {
    +        bytes[offset] = (byte)((i >> 24) & 0xFF);
    +        bytes[offset + 1] = (byte)((i >> 16) & 0xFF);
    +        bytes[offset + 2] = (byte)((i >> 8) & 0xFF);
    +        bytes[offset + 3] = (byte)(i & 0xFF);
    +    }
    +
    +}
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageCodec.java
    new file mode 100644
    index 00000000000..ef36305a90e
    --- /dev/null
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageCodec.java
    @@ -0,0 +1,77 @@
    +/*
    + *  Copyright 1999-2019 Seata.io Group.
    + *
    + *  Licensed under the Apache License, Version 2.0 (the "License");
    + *  you may not use this file except in compliance with the License.
    + *  You may obtain a copy of the License at
    + *
    + *       http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing, software
    + *  distributed under the License is distributed on an "AS IS" BASIS,
    + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  See the License for the specific language governing permissions and
    + *  limitations under the License.
    + */
    +package io.seata.serializer.seata.protocol.v0;
    +
    +import io.netty.buffer.ByteBuf;
    +import io.seata.common.util.StringUtils;
    +import io.seata.core.protocol.AbstractResultMessage;
    +import io.seata.core.protocol.ResultCode;
    +
    +import java.nio.ByteBuffer;
    +
    +/**
    + * The type Abstract result message codec.
    + *
    + * @author zhangsen
    + */
    +public abstract class AbstractResultMessageCodec extends AbstractMessageCodec {
    +
    +    @Override
    +    public Class getMessageClassType() {
    +        return AbstractResultMessage.class;
    +    }
    +
    +    @Override
    +    public  void encode(T t, ByteBuf out) {
    +        AbstractResultMessage abstractResultMessage = (AbstractResultMessage)t;
    +        ResultCode resultCode = abstractResultMessage.getResultCode();
    +        String resultMsg = abstractResultMessage.getMsg();
    +
    +        out.writeByte(resultCode.ordinal());
    +        if (resultCode == ResultCode.Failed) {
    +            if (StringUtils.isNotEmpty(resultMsg)) {
    +                String msg;
    +                if (resultMsg.length() > Short.MAX_VALUE) {
    +                    msg = resultMsg.substring(0, Short.MAX_VALUE);
    +                } else {
    +                    msg = resultMsg;
    +                }
    +                byte[] bs = msg.getBytes(UTF8);
    +                out.writeShort((short)bs.length);
    +                out.writeBytes(bs);
    +            } else {
    +                out.writeShort((short)0);
    +            }
    +        }
    +    }
    +
    +    @Override
    +    public  void decode(T t, ByteBuffer in) {
    +        AbstractResultMessage abstractResultMessage = (AbstractResultMessage)t;
    +
    +        ResultCode resultCode = ResultCode.get(in.get());
    +        abstractResultMessage.setResultCode(resultCode);
    +        if (resultCode == ResultCode.Failed) {
    +            short len = in.getShort();
    +            if (len > 0) {
    +                byte[] msg = new byte[len];
    +                in.get(msg);
    +                abstractResultMessage.setMsg(new String(msg, UTF8));
    +            }
    +        }
    +    }
    +
    +}
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java
    new file mode 100644
    index 00000000000..ff2569bcf63
    --- /dev/null
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java
    @@ -0,0 +1,33 @@
    +/*
    + *  Copyright 1999-2019 Seata.io Group.
    + *
    + *  Licensed under the Apache License, Version 2.0 (the "License");
    + *  you may not use this file except in compliance with the License.
    + *  You may obtain a copy of the License at
    + *
    + *       http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing, software
    + *  distributed under the License is distributed on an "AS IS" BASIS,
    + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  See the License for the specific language governing permissions and
    + *  limitations under the License.
    + */
    +package io.seata.serializer.seata.protocol.v0;
    +
    +
    +import io.seata.core.protocol.RegisterTMRequest;
    +
    +/**
    + * The type Register tm request codec.
    + *
    + * @author zhangsen
    + */
    +public class RegisterTMRequestCodec extends AbstractIdentifyRequestCodec {
    +
    +    @Override
    +    public Class getMessageClassType() {
    +        return RegisterTMRequest.class;
    +    }
    +
    +}
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java
    new file mode 100644
    index 00000000000..ad481ed6d3b
    --- /dev/null
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java
    @@ -0,0 +1,34 @@
    +/*
    + *  Copyright 1999-2019 Seata.io Group.
    + *
    + *  Licensed under the Apache License, Version 2.0 (the "License");
    + *  you may not use this file except in compliance with the License.
    + *  You may obtain a copy of the License at
    + *
    + *       http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing, software
    + *  distributed under the License is distributed on an "AS IS" BASIS,
    + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  See the License for the specific language governing permissions and
    + *  limitations under the License.
    + */
    +package io.seata.serializer.seata.protocol.v0;
    +
    +
    +import io.seata.core.protocol.RegisterTMResponse;
    +import io.seata.serializer.seata.protocol.v1.AbstractIdentifyResponseCodec;
    +
    +/**
    + * The type Register tm response codec.
    + *
    + * @author zhangsen
    + */
    +public class RegisterTMResponseCodec extends AbstractIdentifyResponseCodec {
    +
    +    @Override
    +    public Class getMessageClassType() {
    +        return RegisterTMResponse.class;
    +    }
    +
    +}
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java
    index 72109429694..9c8b55357aa 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java
    @@ -15,125 +15,86 @@
      */
     package io.seata.serializer.seata.protocol.v0;
     
    +import com.sun.tools.javac.util.Pair;
    +import io.netty.buffer.ByteBuf;
    +import io.netty.buffer.Unpooled;
    +import io.seata.common.loader.LoadLevel;
    +import io.seata.core.protocol.AbstractMessage;
     import io.seata.core.protocol.MessageType;
    -import io.seata.core.rpc.netty.v0.MessageCodecV0;
    -import io.seata.core.rpc.netty.v0.SerializerV0;
    +import io.seata.core.protocol.ProtocolConstants;
    +import io.seata.core.protocol.RegisterTMRequest;
    +import io.seata.core.protocol.RegisterTMResponse;
    +import io.seata.serializer.seata.MessageSeataCodec;
    +import io.seata.serializer.seata.SeataAbstractSerializer;
    +
    +import java.nio.ByteBuffer;
     
     /**
    - * The Seata codec v0.
    + * The Seata codec v1.
      *
      * @author Bughue
      */
    -public class SeataV0Serializer implements SerializerV0 {
    +@LoadLevel(name = "SEATA", version = ProtocolConstants.VERSION_0)
    +public class SeataV0Serializer extends SeataAbstractSerializer {
     
         public SeataV0Serializer() {
    +        classMap.put(MessageType.TYPE_REG_CLT, new Pair<>(RegisterTMRequestCodec.class, RegisterTMRequest.class));
    +        classMap.put(MessageType.TYPE_REG_CLT_RESULT, new Pair<>(RegisterTMResponseCodec.class, RegisterTMResponse.class));
    +//        classMap.put(MessageType.TYPE_REG_RM, new Pair<>(RegisterRMRequestCodec.class, RegisterRMRequest.class));
    +//        classMap.put(MessageType.TYPE_REG_RM_RESULT, new Pair<>(RegisterRMResponseCodec.class, RegisterRMResponse.class));
     
         }
     
    -
         @Override
    -    public MessageCodecV0 getMsgInstanceByCode(short typeCode) {
    -        MessageCodecV0 msgCodec = null;
    -        switch (typeCode) {
    -//            case MessageType.TYPE_SEATA_MERGE:
    -//                msgCodec = new MergedWarpMessage();
    -//                break;
    -//            case MessageType.TYPE_SEATA_MERGE_RESULT:
    -//                msgCodec = new MergeResultMessage();
    -//                break;
    -            case MessageType.TYPE_REG_CLT:
    -                msgCodec = new RegisterTMRequest();
    -                break;
    -            case MessageType.TYPE_REG_CLT_RESULT:
    -                msgCodec = new RegisterTMResponse();
    -                break;
    -            case MessageType.TYPE_REG_RM:
    -                msgCodec = new RegisterRMRequest();
    -                break;
    -            case MessageType.TYPE_REG_RM_RESULT:
    -                msgCodec = new RegisterRMResponse();
    -                break;
    -//            case MessageType.TYPE_BRANCH_COMMIT:
    -//                msgCodec = new BranchCommitRequest();
    -//                break;
    -//            case MessageType.TYPE_BRANCH_ROLLBACK:
    -//                msgCodec = new BranchRollbackRequest();
    -//                break;
    -            default:
    -                break;
    +    public  byte[] serialize(T t) {
    +        if (t == null || !(t instanceof AbstractMessage)) {
    +            throw new IllegalArgumentException("AbstractMessage isn't available.");
             }
    +        AbstractMessage abstractMessage = (AbstractMessage)t;
    +        //typecode
    +        short typecode = abstractMessage.getTypeCode();
    +        //msg codec
    +        MessageSeataCodec messageCodec = getCodecByType(typecode);
    +        //get empty ByteBuffer
    +        ByteBuf out = Unpooled.buffer(1024);
    +        //msg encode
    +        messageCodec.encode(t, out);
    +        byte[] body = new byte[out.readableBytes()];
    +        out.readBytes(body);
     
    -        if (null != msgCodec) {
    -            return msgCodec;
    -        }
    +        //typecode + body
    +        ByteBuffer byteBuffer = ByteBuffer.allocate(body.length);
    +        byteBuffer.put(body);
     
    -        try {
    -            msgCodec = (MessageCodecV0) getMergeRequestInstanceByCode(typeCode);
    -        } catch (Exception exx) {
    +        byteBuffer.flip();
    +        byte[] content = new byte[byteBuffer.limit()];
    +        byteBuffer.get(content);
    +        return content;
    +    }
     
    +    @Override
    +    public  T deserialize(byte[] bytes) {
    +        if (bytes == null || bytes.length == 0) {
    +            throw new IllegalArgumentException("Nothing to decode.");
             }
    -        if (null != msgCodec) {
    -            return msgCodec;
    +        if (bytes.length < 2) {
    +            throw new IllegalArgumentException("The byte[] isn't available for decode.");
             }
    -
    -        return (MessageCodecV0)getMergeResponseInstanceByCode(typeCode);
    +        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
    +        //typecode
    +        short typecode = byteBuffer.getShort();
    +        //msg body
    +        byte[] body = new byte[byteBuffer.remaining()];
    +        byteBuffer.get(body);
    +        ByteBuffer in = ByteBuffer.wrap(body);
    +        //new Messgae
    +        AbstractMessage abstractMessage = getMessageByType(typecode);
    +        //get messageCodec
    +        MessageSeataCodec messageCodec = getCodecByType(typecode);
    +        //decode
    +        messageCodec.decode(abstractMessage, in);
    +        return (T)abstractMessage;
         }
     
    -    /**
    -     * Gets merge request instance by code.
    -     *
    -     * @param typeCode the type code
    -     * @return the merge request instance by code
    -     */
    -    public static MergedMessageV0 getMergeRequestInstanceByCode(int typeCode) {
    -        switch (typeCode) {
    -//            case MessageType.TYPE_GLOBAL_BEGIN:
    -//                return new GlobalBeginRequest();
    -//            case MessageType.TYPE_GLOBAL_COMMIT:
    -//                return new GlobalCommitRequest();
    -//            case MessageType.TYPE_GLOBAL_ROLLBACK:
    -//                return new GlobalRollbackRequest();
    -//            case MessageType.TYPE_GLOBAL_STATUS:
    -//                return new GlobalStatusRequest();
    -//            case MessageType.TYPE_GLOBAL_LOCK_QUERY:
    -//                return new GlobalLockQueryRequest();
    -//            case MessageType.TYPE_BRANCH_REGISTER:
    -//                return new BranchRegisterRequest();
    -//            case MessageType.TYPE_BRANCH_STATUS_REPORT:
    -//                return new BranchReportRequest();
    -            default:
    -                throw new IllegalArgumentException("not support typeCode," + typeCode);
    -        }
    -    }
     
    -    /**
    -     * Gets merge response instance by code.
    -     *
    -     * @param typeCode the type code
    -     * @return the merge response instance by code
    -     */
    -    public static MergedMessageV0 getMergeResponseInstanceByCode(int typeCode) {
    -        switch (typeCode) {
    -//            case MessageType.TYPE_GLOBAL_BEGIN_RESULT:
    -//                return new GlobalBeginResponse();
    -//            case MessageType.TYPE_GLOBAL_COMMIT_RESULT:
    -//                return new GlobalCommitResponse();
    -//            case MessageType.TYPE_GLOBAL_ROLLBACK_RESULT:
    -//                return new GlobalRollbackResponse();
    -//            case MessageType.TYPE_GLOBAL_STATUS_RESULT:
    -//                return new GlobalStatusResponse();
    -//            case MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT:
    -//                return new GlobalLockQueryResponse();
    -//            case MessageType.TYPE_BRANCH_REGISTER_RESULT:
    -//                return new BranchRegisterResponse();
    -//            case MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT:
    -//                return new BranchReportResponse();
    -//            case MessageType.TYPE_BRANCH_COMMIT_RESULT:
    -//                return new BranchCommitResponse();
    -//            case MessageType.TYPE_BRANCH_ROLLBACK_RESULT:
    -//                return new BranchRollbackResponse();
    -            default:
    -                throw new IllegalArgumentException("not support typeCode," + typeCode);
    -        }
    -    }
     }
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequest.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyRequestV0.java
    similarity index 78%
    rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequest.java
    rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyRequestV0.java
    index ccb27bfd8b7..8865cdb58a3 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequest.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyRequestV0.java
    @@ -13,9 +13,10 @@
      *  See the License for the specific language governing permissions and
      *  limitations under the License.
      */
    -package io.seata.serializer.seata.protocol.v0;
    +package io.seata.serializer.seata.protocol.v0_1;
     
     import io.netty.buffer.ByteBuf;
    +import io.seata.core.protocol.AbstractIdentifyRequest;
     import io.seata.core.protocol.Version;
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
    @@ -27,9 +28,9 @@
      *
      * @author sharajava
      */
    -public abstract class AbstractIdentifyRequest extends AbstractMessageV0 {
    +public abstract class AbstractIdentifyRequestV0 extends AbstractMessageV0 {
     
    -    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractIdentifyRequest.class);
    +    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractIdentifyRequestV0.class);
     
         /**
          * The Version.
    @@ -57,7 +58,7 @@ public abstract class AbstractIdentifyRequest extends AbstractMessageV0 {
          * @param applicationId           the application id
          * @param transactionServiceGroup the transaction service group
          */
    -    public AbstractIdentifyRequest(String applicationId, String transactionServiceGroup) {
    +    public AbstractIdentifyRequestV0(String applicationId, String transactionServiceGroup) {
             this.applicationId = applicationId;
             this.transactionServiceGroup = transactionServiceGroup;
         }
    @@ -69,7 +70,7 @@ public AbstractIdentifyRequest(String applicationId, String transactionServiceGr
          * @param transactionServiceGroup the transaction service group
          * @param extraData               the extra data
          */
    -    public AbstractIdentifyRequest(String applicationId, String transactionServiceGroup, String extraData) {
    +    public AbstractIdentifyRequestV0(String applicationId, String transactionServiceGroup, String extraData) {
             this.applicationId = applicationId;
             this.transactionServiceGroup = transactionServiceGroup;
             this.extraData = extraData;
    @@ -213,7 +214,7 @@ public final byte[] encode() {
             return flushEncode();
         }
     
    -    @Override
    +//    @Override
         public boolean decode(ByteBuf in) {
     
             short len;
    @@ -268,4 +269,61 @@ public boolean decode(ByteBuf in) {
     
             return true;
         }
    +
    +    @Override
    +    public boolean decode(ByteBuf in,AbstractIdentifyRequest req) {
    +
    +
    +        short len;
    +        if (in.readableBytes() < 2) {
    +            return false;
    +        }
    +        len = in.readShort();
    +
    +        if (in.readableBytes() < len) {
    +            return false;
    +        }
    +        byte[] bs = new byte[len];
    +        in.readBytes(bs);
    +        req.setVersion(new String(bs, UTF8));
    +
    +        if (in.readableBytes() < 2) {
    +            return false;
    +        }
    +        len = in.readShort();
    +
    +        if (in.readableBytes() < len) {
    +            return false;
    +        }
    +        bs = new byte[len];
    +        in.readBytes(bs);
    +        req.setApplicationId(new String(bs, UTF8));
    +
    +        if (in.readableBytes() < 2) {
    +            return false;
    +        }
    +        len = in.readShort();
    +
    +        if (in.readableBytes() < len) {
    +            return false;
    +        }
    +        bs = new byte[len];
    +        in.readBytes(bs);
    +        req.setTransactionServiceGroup(new String(bs, UTF8));
    +
    +        if (in.readableBytes() < 2) {
    +            return false;
    +        }
    +        len = in.readShort();
    +
    +        if (in.readableBytes() >= len) {
    +            bs = new byte[len];
    +            in.readBytes(bs);
    +            req.setExtraData(new String(bs, UTF8));
    +        } else {
    +            //maybe null
    +        }
    +
    +        return true;
    +    }
     }
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponse.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyResponseV0.java
    similarity index 96%
    rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponse.java
    rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyResponseV0.java
    index 2021906967f..e90a3f6bac6 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponse.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyResponseV0.java
    @@ -13,7 +13,7 @@
      *  See the License for the specific language governing permissions and
      *  limitations under the License.
      */
    -package io.seata.serializer.seata.protocol.v0;
    +package io.seata.serializer.seata.protocol.v0_1;
     
     import io.netty.buffer.ByteBuf;
     import io.seata.core.protocol.Version;
    @@ -23,7 +23,7 @@
      *
      * @author sharajava
      */
    -public abstract class AbstractIdentifyResponse extends AbstractResultMessageV0 {
    +public abstract class AbstractIdentifyResponseV0 extends AbstractResultMessageV0 {
     
         protected String version = Version.getCurrent();
     
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractMessageV0.java
    similarity index 88%
    rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageV0.java
    rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractMessageV0.java
    index f8e95691539..4d4d9627140 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageV0.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractMessageV0.java
    @@ -13,11 +13,13 @@
      *  See the License for the specific language governing permissions and
      *  limitations under the License.
      */
    -package io.seata.serializer.seata.protocol.v0;
    +package io.seata.serializer.seata.protocol.v0_1;
     
     import io.netty.buffer.ByteBuf;
     import io.netty.channel.ChannelHandlerContext;
     import io.seata.common.Constants;
    +import io.seata.core.protocol.AbstractIdentifyRequest;
    +import io.seata.core.protocol.AbstractMessage;
     import io.seata.core.rpc.netty.v0.MessageCodecV0;
     
     import java.io.Serializable;
    @@ -29,7 +31,7 @@
      * @author jimin.jm @alibaba-inc.com
      * @date 2018 /9/14
      */
    -public abstract class AbstractMessageV0 implements MessageCodecV0, Serializable {
    +public abstract class AbstractMessageV0 implements MessageCodecV0, Serializable {
         private static final long serialVersionUID = -1441020418526899889L;
     
         /**
    @@ -72,7 +74,7 @@ public static void intToBytes(int i, byte[] bytes, int offset) {
         }
     
         @Override
    -    public boolean decode(ByteBuf in) {
    +    public boolean decode(ByteBuf in, T req){
             return false;
         }
     
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractResultMessageV0.java
    similarity index 91%
    rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageV0.java
    rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractResultMessageV0.java
    index aeed3c6b15c..04b5a46af97 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageV0.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractResultMessageV0.java
    @@ -13,10 +13,10 @@
      *  See the License for the specific language governing permissions and
      *  limitations under the License.
      */
    -package io.seata.serializer.seata.protocol.v0;
    +package io.seata.serializer.seata.protocol.v0_1;
     
     import io.netty.buffer.ByteBuf;
    -import io.seata.core.protocol.AbstractMessage;
    +import io.seata.core.protocol.AbstractResultMessage;
     import io.seata.core.protocol.ResultCode;
     
     import java.nio.ByteBuffer;
    @@ -27,7 +27,7 @@
      * @author jimin.jm @alibaba-inc.com
      * @date 2018 /9/14
      */
    -public abstract class AbstractResultMessageV0 extends AbstractMessageV0 implements MergedMessageV0 {
    +public abstract class AbstractResultMessageV0 extends AbstractMessageV0 implements MergedMessageV0 {
         private static final long serialVersionUID = 6540352050650203313L;
     
         private ResultCode resultCode;
    @@ -131,11 +131,11 @@ public void decode(ByteBuffer byteBuffer) {
         }
     
         @Override
    -    public boolean decode(ByteBuf in) {
    +    public boolean decode(ByteBuf in,AbstractResultMessage resultMessage) {
             if (in.readableBytes() < 1) {
                 return false;
             }
    -        setResultCode(ResultCode.get(in.readByte()));
    +        resultMessage.setResultCode(ResultCode.get(in.readByte()));
             if (resultCode == ResultCode.Failed) {
                 if (in.readableBytes() < 2) {
                     return false;
    @@ -147,7 +147,7 @@ public boolean decode(ByteBuf in) {
                 if (len > 0) {
                     byte[] msg = new byte[len];
                     in.readBytes(msg);
    -                this.setMsg(new String(msg, UTF8));
    +                resultMessage.setMsg(new String(msg, UTF8));
                 }
             }
             return true;
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedMessageV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/MergedMessageV0.java
    similarity index 94%
    rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedMessageV0.java
    rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/MergedMessageV0.java
    index 04e8913d9c8..1938b8dc27f 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedMessageV0.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/MergedMessageV0.java
    @@ -13,7 +13,7 @@
      *  See the License for the specific language governing permissions and
      *  limitations under the License.
      */
    -package io.seata.serializer.seata.protocol.v0;
    +package io.seata.serializer.seata.protocol.v0_1;
     
     import java.nio.ByteBuffer;
     
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMRequest.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMRequestV0.java
    similarity index 94%
    rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMRequest.java
    rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMRequestV0.java
    index 7e61d460ae2..632fbbb7021 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMRequest.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMRequestV0.java
    @@ -13,7 +13,7 @@
      *  See the License for the specific language governing permissions and
      *  limitations under the License.
      */
    -package io.seata.serializer.seata.protocol.v0;
    +package io.seata.serializer.seata.protocol.v0_1;
     
     import io.netty.buffer.ByteBuf;
     
    @@ -27,7 +27,7 @@
      * @author jimin.jm @alibaba-inc.com
      * @date 2018 /10/10
      */
    -public class RegisterRMRequest extends AbstractIdentifyRequest implements Serializable {
    +public class RegisterRMRequestV0 extends AbstractIdentifyRequestV0 implements Serializable {
         private static final long serialVersionUID = 7539732523682335742L;
     
         private String resourceIds;
    @@ -35,7 +35,7 @@ public class RegisterRMRequest extends AbstractIdentifyRequest implements Serial
         /**
          * Instantiates a new Register rm request.
          */
    -    public RegisterRMRequest() {
    +    public RegisterRMRequestV0() {
             this(null, null);
         }
     
    @@ -45,7 +45,7 @@ public RegisterRMRequest() {
          * @param applicationId           the application id
          * @param transactionServiceGroup the transaction service group
          */
    -    public RegisterRMRequest(String applicationId, String transactionServiceGroup) {
    +    public RegisterRMRequestV0(String applicationId, String transactionServiceGroup) {
             super(applicationId, transactionServiceGroup);
         }
     
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMResponse.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMResponseV0.java
    similarity index 84%
    rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMResponse.java
    rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMResponseV0.java
    index 7375bf5e720..15b02401315 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterRMResponse.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMResponseV0.java
    @@ -13,7 +13,7 @@
      *  See the License for the specific language governing permissions and
      *  limitations under the License.
      */
    -package io.seata.serializer.seata.protocol.v0;
    +package io.seata.serializer.seata.protocol.v0_1;
     
     
     import io.seata.core.protocol.MessageType;
    @@ -26,13 +26,13 @@
      * @author jimin.jm @alibaba-inc.com
      * @date 2018 /10/10
      */
    -public class RegisterRMResponse extends AbstractIdentifyResponse implements Serializable {
    +public class RegisterRMResponseV0 extends AbstractIdentifyResponseV0 implements Serializable {
         private static final long serialVersionUID = 6391375605848221420L;
     
         /**
          * Instantiates a new Register rm response.
          */
    -    public RegisterRMResponse() {
    +    public RegisterRMResponseV0() {
             this(true);
         }
     
    @@ -41,7 +41,7 @@ public RegisterRMResponse() {
          *
          * @param result the result
          */
    -    public RegisterRMResponse(boolean result) {
    +    public RegisterRMResponseV0(boolean result) {
             super();
             setIdentified(result);
         }
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequest.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMRequestV0.java
    similarity index 83%
    rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequest.java
    rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMRequestV0.java
    index 2b1a70c8497..d2e2bfa0c5c 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequest.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMRequestV0.java
    @@ -13,7 +13,7 @@
      *  See the License for the specific language governing permissions and
      *  limitations under the License.
      */
    -package io.seata.serializer.seata.protocol.v0;
    +package io.seata.serializer.seata.protocol.v0_1;
     
     
     import io.seata.core.protocol.MessageType;
    @@ -26,13 +26,13 @@
      * @author jimin.jm @alibaba-inc.com
      * @date 2018 /10/15
      */
    -public class RegisterTMRequest extends AbstractIdentifyRequest implements Serializable {
    +public class RegisterTMRequestV0 extends AbstractIdentifyRequestV0 implements Serializable {
         private static final long serialVersionUID = -5929081344190543690L;
     
         /**
          * Instantiates a new Register tm request.
          */
    -    public RegisterTMRequest() {
    +    public RegisterTMRequestV0() {
             this(null, null);
         }
     
    @@ -43,7 +43,7 @@ public RegisterTMRequest() {
          * @param transactionServiceGroup the transaction service group
          * @param extraData               the extra data
          */
    -    public RegisterTMRequest(String applicationId, String transactionServiceGroup, String extraData) {
    +    public RegisterTMRequestV0(String applicationId, String transactionServiceGroup, String extraData) {
             super(applicationId, transactionServiceGroup, extraData);
     
         }
    @@ -54,7 +54,7 @@ public RegisterTMRequest(String applicationId, String transactionServiceGroup, S
          * @param applicationId           the application id
          * @param transactionServiceGroup the transaction service group
          */
    -    public RegisterTMRequest(String applicationId, String transactionServiceGroup) {
    +    public RegisterTMRequestV0(String applicationId, String transactionServiceGroup) {
             super(applicationId, transactionServiceGroup);
         }
     
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponse.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMResponseV0.java
    similarity index 84%
    rename from serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponse.java
    rename to serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMResponseV0.java
    index 4db675e596a..89196224514 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponse.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMResponseV0.java
    @@ -13,7 +13,7 @@
      *  See the License for the specific language governing permissions and
      *  limitations under the License.
      */
    -package io.seata.serializer.seata.protocol.v0;
    +package io.seata.serializer.seata.protocol.v0_1;
     
     
     import io.seata.core.protocol.MessageType;
    @@ -26,13 +26,13 @@
      * @author jimin.jm @alibaba-inc.com
      * @date 2018 /10/15
      */
    -public class RegisterTMResponse extends AbstractIdentifyResponse implements Serializable {
    +public class RegisterTMResponseV0 extends AbstractIdentifyResponseV0 implements Serializable {
         private static final long serialVersionUID = 3629846050062228749L;
     
         /**
          * Instantiates a new Register tm response.
          */
    -    public RegisterTMResponse() {
    +    public RegisterTMResponseV0() {
             this(true);
         }
     
    @@ -41,7 +41,7 @@ public RegisterTMResponse() {
          *
          * @param result the result
          */
    -    public RegisterTMResponse(boolean result) {
    +    public RegisterTMResponseV0(boolean result) {
             super();
             setIdentified(result);
         }
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/SeataV0Serializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/SeataV0Serializer.java
    new file mode 100644
    index 00000000000..ed35f987b1b
    --- /dev/null
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/SeataV0Serializer.java
    @@ -0,0 +1,139 @@
    +/*
    + *  Copyright 1999-2019 Seata.io Group.
    + *
    + *  Licensed under the Apache License, Version 2.0 (the "License");
    + *  you may not use this file except in compliance with the License.
    + *  You may obtain a copy of the License at
    + *
    + *       http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing, software
    + *  distributed under the License is distributed on an "AS IS" BASIS,
    + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  See the License for the specific language governing permissions and
    + *  limitations under the License.
    + */
    +package io.seata.serializer.seata.protocol.v0_1;
    +
    +import io.seata.core.protocol.MessageType;
    +import io.seata.core.rpc.netty.v0.MessageCodecV0;
    +import io.seata.core.rpc.netty.v0.SerializerV0;
    +
    +/**
    + * The Seata codec v0.
    + *
    + * @author Bughue
    + */
    +public class SeataV0Serializer implements SerializerV0 {
    +
    +    public SeataV0Serializer() {
    +
    +    }
    +
    +
    +    @Override
    +    public MessageCodecV0 getMsgInstanceByCode(short typeCode) {
    +        MessageCodecV0 msgCodec = null;
    +        switch (typeCode) {
    +//            case MessageType.TYPE_SEATA_MERGE:
    +//                msgCodec = new MergedWarpMessage();
    +//                break;
    +//            case MessageType.TYPE_SEATA_MERGE_RESULT:
    +//                msgCodec = new MergeResultMessage();
    +//                break;
    +            case MessageType.TYPE_REG_CLT:
    +                msgCodec = new RegisterTMRequestV0();
    +                break;
    +            case MessageType.TYPE_REG_CLT_RESULT:
    +                msgCodec = new RegisterTMResponseV0();
    +                break;
    +            case MessageType.TYPE_REG_RM:
    +                msgCodec = new RegisterRMRequestV0();
    +                break;
    +            case MessageType.TYPE_REG_RM_RESULT:
    +                msgCodec = new RegisterRMResponseV0();
    +                break;
    +//            case MessageType.TYPE_BRANCH_COMMIT:
    +//                msgCodec = new BranchCommitRequest();
    +//                break;
    +//            case MessageType.TYPE_BRANCH_ROLLBACK:
    +//                msgCodec = new BranchRollbackRequest();
    +//                break;
    +            default:
    +                break;
    +        }
    +
    +        if (null != msgCodec) {
    +            return msgCodec;
    +        }
    +
    +        try {
    +            msgCodec = (MessageCodecV0) getMergeRequestInstanceByCode(typeCode);
    +        } catch (Exception exx) {
    +
    +        }
    +        if (null != msgCodec) {
    +            return msgCodec;
    +        }
    +
    +        return (MessageCodecV0)getMergeResponseInstanceByCode(typeCode);
    +    }
    +
    +    /**
    +     * Gets merge request instance by code.
    +     *
    +     * @param typeCode the type code
    +     * @return the merge request instance by code
    +     */
    +    public static MergedMessageV0 getMergeRequestInstanceByCode(int typeCode) {
    +        switch (typeCode) {
    +//            case MessageType.TYPE_GLOBAL_BEGIN:
    +//                return new GlobalBeginRequest();
    +//            case MessageType.TYPE_GLOBAL_COMMIT:
    +//                return new GlobalCommitRequest();
    +//            case MessageType.TYPE_GLOBAL_ROLLBACK:
    +//                return new GlobalRollbackRequest();
    +//            case MessageType.TYPE_GLOBAL_STATUS:
    +//                return new GlobalStatusRequest();
    +//            case MessageType.TYPE_GLOBAL_LOCK_QUERY:
    +//                return new GlobalLockQueryRequest();
    +//            case MessageType.TYPE_BRANCH_REGISTER:
    +//                return new BranchRegisterRequest();
    +//            case MessageType.TYPE_BRANCH_STATUS_REPORT:
    +//                return new BranchReportRequest();
    +            default:
    +                throw new IllegalArgumentException("not support typeCode," + typeCode);
    +        }
    +    }
    +
    +    /**
    +     * Gets merge response instance by code.
    +     *
    +     * @param typeCode the type code
    +     * @return the merge response instance by code
    +     */
    +    public static MergedMessageV0 getMergeResponseInstanceByCode(int typeCode) {
    +        switch (typeCode) {
    +//            case MessageType.TYPE_GLOBAL_BEGIN_RESULT:
    +//                return new GlobalBeginResponse();
    +//            case MessageType.TYPE_GLOBAL_COMMIT_RESULT:
    +//                return new GlobalCommitResponse();
    +//            case MessageType.TYPE_GLOBAL_ROLLBACK_RESULT:
    +//                return new GlobalRollbackResponse();
    +//            case MessageType.TYPE_GLOBAL_STATUS_RESULT:
    +//                return new GlobalStatusResponse();
    +//            case MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT:
    +//                return new GlobalLockQueryResponse();
    +//            case MessageType.TYPE_BRANCH_REGISTER_RESULT:
    +//                return new BranchRegisterResponse();
    +//            case MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT:
    +//                return new BranchReportResponse();
    +//            case MessageType.TYPE_BRANCH_COMMIT_RESULT:
    +//                return new BranchCommitResponse();
    +//            case MessageType.TYPE_BRANCH_ROLLBACK_RESULT:
    +//                return new BranchRollbackResponse();
    +            default:
    +                throw new IllegalArgumentException("not support typeCode," + typeCode);
    +        }
    +    }
    +}
    diff --git a/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.rpc.netty.v0.SerializerV0 b/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.rpc.netty.v0.SerializerV0
    new file mode 100644
    index 00000000000..07bab05d194
    --- /dev/null
    +++ b/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.rpc.netty.v0.SerializerV0
    @@ -0,0 +1 @@
    +io.seata.serializer.seata.protocol.v0_1.SeataV0Serializer
    \ No newline at end of file
    diff --git a/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer b/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer
    index e127901cc83..d448c8d46fb 100644
    --- a/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer
    +++ b/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer
    @@ -1,2 +1,2 @@
     io.seata.serializer.seata.protocol.v1.SeataV1Serializer
    -io.seata.serializer.seata.protocol.v0.SeataV0Serializer
    \ No newline at end of file
    +io.seata.serializer.seata.protocol.v0.SeataV0Serializer
    diff --git a/test/src/test/java/io/seata/core/rpc/netty/TmNettyClientTest.java b/test/src/test/java/io/seata/core/rpc/netty/TmNettyClientTest.java
    index a2ac66f3a2f..c6daf3a2d86 100644
    --- a/test/src/test/java/io/seata/core/rpc/netty/TmNettyClientTest.java
    +++ b/test/src/test/java/io/seata/core/rpc/netty/TmNettyClientTest.java
    @@ -80,6 +80,44 @@ public void testDoConnect() throws Exception {
             tmNettyRemotingClient.destroy();
         }
     
    +
    +    @Test
    +    public void testDoConnectOnlyServer() throws Exception {
    +        ThreadPoolExecutor workingThreads = initMessageExecutor();
    +        NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(workingThreads);
    +        //start services server first
    +        Thread thread = new Thread(() -> {
    +            nettyRemotingServer.setHandler(DefaultCoordinator.getInstance(nettyRemotingServer));
    +            // set registry
    +            XID.setIpAddress(NetUtil.getLocalIp());
    +            XID.setPort(8091);
    +            // init snowflake for transactionId, branchId
    +            UUIDGenerator.init(1L);
    +            System.out.println("pid info: "+ ManagementFactory.getRuntimeMXBean().getName());
    +            nettyRemotingServer.init();
    +        });
    +        thread.start();
    +
    +        //then test client
    +        Thread.sleep(3000000);
    +
    +
    +    }
    +
    +    @Test
    +    public void testDoConnectOnlyClient() throws Exception {
    +
    +        String applicationId = "app 1";
    +        String transactionServiceGroup = "group A";
    +        TmNettyRemotingClient tmNettyRemotingClient = TmNettyRemotingClient.getInstance(applicationId, transactionServiceGroup);
    +
    +        tmNettyRemotingClient.init();
    +        String serverAddress = "0.0.0.0:8091";
    +        Channel channel = TmNettyRemotingClient.getInstance().getClientChannelManager().acquireChannel(serverAddress);
    +        Assertions.assertNotNull(channel);
    +        tmNettyRemotingClient.destroy();
    +    }
    +
         /**
          * Client rely on server's starting first
          *
    
    From e85501f2f8f7f57c4b2493c723e9ef7464f7528a Mon Sep 17 00:00:00 2001
    From: "minghua.xie" 
    Date: Mon, 21 Aug 2023 17:42:14 +0800
    Subject: [PATCH 07/22] protocol
    
    ---
     .../core/rpc/netty/v1/ProtocolV1Decoder.java  | 19 ++++++++++---------
     1 file changed, 10 insertions(+), 9 deletions(-)
    
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java
    index 08354348547..8e2db58f3f3 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java
    @@ -94,19 +94,20 @@ public ProtocolRpcMessage decodeFrame(ByteBuf frame) {
             }
     
             // read body
    -        int bodyLength = fullLength - headLength;
             if (messageType == ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST) {
                 rpcMessage.setBody(HeartbeatMessage.PING);
             } else if (messageType == ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) {
                 rpcMessage.setBody(HeartbeatMessage.PONG);
    -        } else if (bodyLength > 0) {
    -            byte[] bs = new byte[bodyLength];
    -            frame.readBytes(bs);
    -            Compressor compressor = CompressorFactory.getCompressor(compressorType);
    -            bs = compressor.decompress(bs);
    -            Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codecType),version);
    -            rpcMessage.setBody(serializer.deserialize(bs));
    -            return rpcMessage;
    +        } else {
    +            int bodyLength = fullLength - headLength;
    +            if (bodyLength > 0) {
    +                byte[] bs = new byte[bodyLength];
    +                frame.readBytes(bs);
    +                Compressor compressor = CompressorFactory.getCompressor(compressorType);
    +                bs = compressor.decompress(bs);
    +                Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec()), version);
    +                rpcMessage.setBody(serializer.deserialize(bs));
    +            }
             }
     
             return rpcMessage;
    
    From 900428f697d13d8e74f0661db0e09a5cef4e0543 Mon Sep 17 00:00:00 2001
    From: "minghua.xie" 
    Date: Mon, 21 Aug 2023 17:45:34 +0800
    Subject: [PATCH 08/22] protocol
    
    ---
     .../main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    index 6e22ad809db..383b5d106ab 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    @@ -60,7 +60,7 @@
      */
     public class ProtocolV1Encoder implements ProtocolEncoder {
     
    -    private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV0Encoder.class);
    +    private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV1Encoder.class);
     
     
         public void encode(RpcMessage message, ByteBuf out) {
    
    From 45fc67ec90663102de62970d11ccfe39d24036a4 Mon Sep 17 00:00:00 2001
    From: "minghua.xie" 
    Date: Mon, 21 Aug 2023 17:47:24 +0800
    Subject: [PATCH 09/22] protocol
    
    ---
     .../main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    index 383b5d106ab..842c5210143 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    @@ -65,6 +65,8 @@ public class ProtocolV1Encoder implements ProtocolEncoder {
     
         public void encode(RpcMessage message, ByteBuf out) {
             try {
    +//            if (msg instanceof RpcMessage) {
    +
                 ProtocolV1RpcMessage rpcMessage = new ProtocolV1RpcMessage();
                 rpcMessage.rpcMsg2ProtocolMsg(message);
     
    
    From 74382e5082fd132419e4dfed86581b3a97da2dbe Mon Sep 17 00:00:00 2001
    From: "minghua.xie" 
    Date: Mon, 21 Aug 2023 17:48:12 +0800
    Subject: [PATCH 10/22] protocol
    
    ---
     .../main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    index 842c5210143..644ecec4057 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    @@ -65,11 +65,11 @@ public class ProtocolV1Encoder implements ProtocolEncoder {
     
         public void encode(RpcMessage message, ByteBuf out) {
             try {
    -//            if (msg instanceof RpcMessage) {
     
                 ProtocolV1RpcMessage rpcMessage = new ProtocolV1RpcMessage();
                 rpcMessage.rpcMsg2ProtocolMsg(message);
     
    +//            if (msg instanceof RpcMessage) {
                 int fullLength = ProtocolConstants.V1_HEAD_LENGTH;
                 int headLength = ProtocolConstants.V1_HEAD_LENGTH;
     
    
    From 6cffd4a5d34d0d6f45882bea3881201ae0feb8fb Mon Sep 17 00:00:00 2001
    From: "minghua.xie" 
    Date: Mon, 28 Aug 2023 16:56:37 +0800
    Subject: [PATCH 11/22] protocol
    
    ---
     .../common/loader/EnhancedServiceLoader.java  |  1 +
     .../common/loader/ExtensionDefinition.java    |  4 ++--
     .../io/seata/common/loader/LoadLevel.java     |  1 +
     .../netty/AbstractNettyRemotingClient.java    |  2 +-
     .../netty/AbstractNettyRemotingServer.java    |  9 +++------
     .../rpc/netty/CompatibleProtocolDecoder.java  |  8 ++++----
     .../rpc/netty/CompatibleProtocolEncoder.java  |  6 +-----
     .../seata/core/rpc/netty/ProtocolDecoder.java |  7 ++++++-
     .../seata/core/rpc/netty/ProtocolEncoder.java |  6 ++++++
     .../core/rpc/netty/ProtocolRpcMessage.java    | 15 +++++++++++++++
     .../core/rpc/netty/TmNettyRemotingClient.java |  3 +--
     .../rpc/netty/v0/ProtocolV0Constants.java     |  2 +-
     .../core/rpc/netty/v0/ProtocolV0Decoder.java  | 19 ++++++++++---------
     .../core/rpc/netty/v0/ProtocolV0Encoder.java  | 15 ---------------
     .../rpc/netty/v0/ProtocolV0RpcMessage.java    |  7 ++-----
     .../core/rpc/netty/v1/ProtocolV1Decoder.java  |  1 -
     .../core/rpc/netty/v1/ProtocolV1Encoder.java  |  5 +----
     .../rpc/netty/v1/ProtocolV1RpcMessage.java    |  2 +-
     .../serializer/SerializerServiceLoader.java   |  2 +-
     .../serializer/seata/MessageCodecFactory.java |  2 +-
     .../v0/AbstractIdentifyRequestCodec.java      |  2 ++
     .../protocol/v0/RegisterTMRequestCodec.java   |  1 -
     .../protocol/v0/RegisterTMResponseCodec.java  |  2 --
     .../seata/protocol/v0/SeataV0Serializer.java  |  2 +-
     .../v1/AbstractIdentifyRequestCodec.java      |  3 ++-
     25 files changed, 63 insertions(+), 64 deletions(-)
    
    diff --git a/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java b/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java
    index c8e4f9e04c3..74863a6c490 100644
    --- a/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java
    +++ b/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java
    @@ -638,6 +638,7 @@ private ExtensionDefinition getCachedExtensionDefinition(String activateName,
                         return first.get();
                     }
                 }
    +            // todo [5738-discuss][class-loader] 实在找不到的话还要随便找个版本吗?这样不太严谨?
                 return CollectionUtils.getLast(definitions);
             }
     
    diff --git a/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java b/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java
    index 2a6c4fe0394..ef27aa74d95 100644
    --- a/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java
    +++ b/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java
    @@ -47,10 +47,10 @@ public Scope getScope() {
         }
     
         public ExtensionDefinition(String name, Integer order, Scope scope, Class clazz) {
    -        this(name,order,scope,clazz,0);
    +        this(name,order,scope,clazz,-1);
         }
     
    -    public ExtensionDefinition(String name, Integer order, Scope scope, Class clazz,int version) {
    +    public ExtensionDefinition(String name, Integer order, Scope scope, Class clazz, int version) {
             this.name = name;
             this.order = order;
             this.version = version;
    diff --git a/common/src/main/java/io/seata/common/loader/LoadLevel.java b/common/src/main/java/io/seata/common/loader/LoadLevel.java
    index cdc08eed059..086d65a10b5 100644
    --- a/common/src/main/java/io/seata/common/loader/LoadLevel.java
    +++ b/common/src/main/java/io/seata/common/loader/LoadLevel.java
    @@ -49,6 +49,7 @@
          *
          * @return the int
          */
    +    // todo [5738-discuss][class-loader] 由于0也是个版本,所以现在默认是-1
         byte version() default -1;
     
         /**
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java
    index 3c638bf12e3..6d6fc503e78 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java
    @@ -421,7 +421,7 @@ public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exce
                 if (rpcMessage != null) {
                     processMessage(ctx, rpcMessage);
                 } else {
    -                //todo 会有这种情况吗??【特殊】
    +                // todo [5738-discuss][类型] 会有这种情况吗??按之前的就是不处理?
                     //打日志?
                 }
             }
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java
    index f8509e5ae31..435d713d5dc 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java
    @@ -74,15 +74,15 @@ public Object sendSyncRequest(String resourceId, String clientId, Object msg, bo
         }
     
         private void superSendAsync(Channel channel, RpcMessage rpcMessage) {
    -        //todo 优化,是否为空
             RpcContext rpcContext = ChannelManager.getContextFromIdentified(channel);
    +        // todo [5738-discuss][兼容] ,目前看到用这个方法的地方都没有做空判断
             rpcMessage.setProtocolVersion(rpcContext.getProtocolVersion());
             super.sendAsync(channel, rpcMessage);
         }
     
         private Object superSendSync(Channel channel, RpcMessage rpcMessage) throws TimeoutException {
    -        //todo 优化,是否为空
             RpcContext rpcContext = ChannelManager.getContextFromIdentified(channel);
    +        // todo [5738-discuss][兼容] ,目前看到用这个方法的地方都没有做空判断
             rpcMessage.setProtocolVersion(rpcContext.getProtocolVersion());
             return super.sendSync(channel, rpcMessage, NettyServerConfig.getRpcRequestTimeout());
         }
    @@ -105,8 +105,6 @@ public void sendAsyncRequest(Channel channel, Object msg) {
             superSendAsync(channel, rpcMessage);
         }
     
    -
    -
         @Override
         public void sendAsyncResponse(RpcMessage rpcMessage, Channel channel, Object msg) {
             Channel clientChannel = channel;
    @@ -186,11 +184,10 @@ public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exce
                 if (rpcMessage != null) {
                     processMessage(ctx, rpcMessage);
                 } else {
    -                //todo 正常会有这种情况吗?打日志还是抛异常?
    +                // todo [5738-discuss][兼容] 正常会有这种情况吗?打日志还是抛异常?
                 }
             }
     
    -
             @Override
             public void channelWritabilityChanged(ChannelHandlerContext ctx) {
                 synchronized (lock) {
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java
    index e8528a24ba0..61d70127986 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java
    @@ -87,6 +87,7 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
             byte version;
             try {
                 if (isV0(in)) {
    +                // todo [5738-discuss][decode] 旧版本连super都不会走,会不会有其他问题?
                     decoded = in;
                     version = ProtocolConstants.VERSION_0;
                 } else {
    @@ -99,7 +100,7 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
                     try {
                         ProtocolDecoder decoder = protocolDecoderMap.get(version);
                         if (decoder == null) {
    -                        // todo 要不要适配当前版本?
    +                        // todo [5738-discuss][兼容] 要不要适配当前版本?
                             throw new IllegalArgumentException("Unknown version: " + version);
                         }
                         return decoder.decodeFrame(frame);
    @@ -111,8 +112,7 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
                 }
             } catch (Exception exx) {
                 LOGGER.error("Decode frame error, cause: {}", exx.getMessage());
    -            //todo
    -            exx.printStackTrace();
    +            // todo [5738-discuss][优化] 这里抛出去之后似乎没有地方打印了?
                 throw new DecodeException(exx);
             }
             return decoded;
    @@ -133,7 +133,7 @@ protected byte decideVersion(Object in) {
                 frame.resetReaderIndex();
                 return version;
             }
    -        // todo
    +        // todo [5738-discuss][兼容] 类型不一致的情况要允许吗?
             return -1;
         }
     
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java
    index 20c637730bf..4f318090381 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java
    @@ -21,11 +21,8 @@
     import io.netty.handler.codec.MessageToByteEncoder;
     import io.seata.core.protocol.ProtocolConstants;
     import io.seata.core.protocol.RpcMessage;
    -import io.seata.core.rpc.netty.v0.ProtocolV0Decoder;
     import io.seata.core.rpc.netty.v0.ProtocolV0Encoder;
    -import io.seata.core.rpc.netty.v1.ProtocolV1Decoder;
     import io.seata.core.rpc.netty.v1.ProtocolV1Encoder;
    -import io.seata.core.rpc.netty.v1.ProtocolV1RpcMessage;
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
     
    @@ -66,12 +63,11 @@ public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) {
                     byte version = rpcMessage.getProtocolVersion();
                     ProtocolEncoder encoder = protocolEncoderMap.get(version);
                     if (encoder == null) {
    -                    // todo 要不要适配当前版本?
    +                    // todo [5738-discuss][encode] 要不要适配当前版本?
                         throw new IllegalArgumentException("Unknown version: " + version);
                     }
     
                     encoder.encode(rpcMessage,out);
    -
                 } else {
                     throw new UnsupportedOperationException("Not support this class:" + msg.getClass());
                 }
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java
    index d6ebb3f6974..f551e1b99e4 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java
    @@ -16,8 +16,13 @@
     package io.seata.core.rpc.netty;
     
     import io.netty.buffer.ByteBuf;
    -import io.seata.core.rpc.netty.v0.ProtocolV0RpcMessage;
     
    +/**
    + * the protocol decoder
    + *
    + * @author minghua.xie
    + * @date 2023/8/1
    + **/
     public interface ProtocolDecoder {
     
         ProtocolRpcMessage decodeFrame(ByteBuf in);
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java
    index 74bf1b1b2d7..d8c72fcf663 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java
    @@ -18,6 +18,12 @@
     import io.netty.buffer.ByteBuf;
     import io.seata.core.protocol.RpcMessage;
     
    +/**
    + * the protocol encoder
    + *
    + * @author minghua.xie
    + * @date 2023/8/1
    + **/
     public interface ProtocolEncoder {
         void encode(RpcMessage rpcMessage, ByteBuf out);
     }
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java
    index 5ce758d7d50..7cfe882b661 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java
    @@ -1,3 +1,18 @@
    +/*
    + *  Copyright 1999-2019 Seata.io Group.
    + *
    + *  Licensed under the Apache License, Version 2.0 (the "License");
    + *  you may not use this file except in compliance with the License.
    + *  You may obtain a copy of the License at
    + *
    + *       http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing, software
    + *  distributed under the License is distributed on an "AS IS" BASIS,
    + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  See the License for the specific language governing permissions and
    + *  limitations under the License.
    + */
     package io.seata.core.rpc.netty;
     
     import io.seata.core.protocol.RpcMessage;
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/TmNettyRemotingClient.java b/core/src/main/java/io/seata/core/rpc/netty/TmNettyRemotingClient.java
    index c90db35f386..e2a238b61df 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/TmNettyRemotingClient.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/TmNettyRemotingClient.java
    @@ -221,8 +221,7 @@ public void onRegisterMsgSuccess(String serverAddress, Channel channel, Object r
             RegisterTMRequest registerTMRequest = (RegisterTMRequest) requestMessage;
             RegisterTMResponse registerTMResponse = (RegisterTMResponse) response;
             if (LOGGER.isInfoEnabled()) {
    -            LOGGER.info("register TM success. client version:{}, server version:{},channel:{}",
    -                    registerTMRequest.getVersion(), registerTMResponse.getVersion(), channel);
    +            LOGGER.info("register TM success. client version:{}, server version:{},channel:{}", registerTMRequest.getVersion(), registerTMResponse.getVersion(), channel);
             }
             getClientChannelManager().registerChannel(serverAddress, channel);
         }
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java
    index be761391727..49016d659b3 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java
    @@ -16,7 +16,7 @@
     package io.seata.core.rpc.netty.v0;
     
     /**
    - * ?
    + * protocol v0 constants
      *
      * @author Bughue
      * @date 2023/7/18
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java
    index 979dcd66e13..a54573c8e28 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java
    @@ -68,12 +68,12 @@ public class ProtocolV0Decoder implements ProtocolDecoder {
         @Override
         public ProtocolV0RpcMessage decodeFrame(ByteBuf in) {
             ProtocolV0RpcMessage rpcMessage = new ProtocolV0RpcMessage();
    -        // todo 旧版本是直接返回跳过了,我们需要保留这个逻辑?【特殊】
    +        // todo [5738-discuss][decode] 旧版本是直接返回跳过了,我们需要保留这个逻辑?【特殊】
             if (in.readableBytes() < ProtocolV0Constants.HEAD_LENGTH) {
                 throw new IllegalArgumentException("Nothing to decode.");
             }
     
    -        // todo 这里是为了bodyLength不满足要求时reset,意义是什么?【特殊】
    +        // todo [5738-discuss][decode] 这里是为了bodyLength不满足要求时reset,意义是什么?【特殊】
             in.markReaderIndex();
     
             // todo 外层已经判断过了,这里可以跳过
    @@ -109,7 +109,7 @@ public ProtocolV0RpcMessage decodeFrame(ByteBuf in) {
             }
     
             if (bodyLength > 0 && in.readableBytes() < bodyLength) {
    -            // todo 【特殊】
    +            // todo [5738-discuss][兼容] 这种情况要允许吗?
                 in.resetReaderIndex();
                 throw new IllegalArgumentException("readableBytes < bodyLength");
             }
    @@ -119,7 +119,8 @@ public ProtocolV0RpcMessage decodeFrame(ByteBuf in) {
             rpcMessage.setRequest(isRequest);
     
             try {
    -            // v0_1
    +            // v0 方案1(未完整实现
    +            // todo [5738-discuss][decode] 旧方式完全分离出来更难改
                 // todo serializer==null
     //            MessageCodecV0 msgCodec = serializer.getMsgInstanceByCode(typeCode);
     //            if (!msgCodec.decode(in)) {
    @@ -127,18 +128,18 @@ public ProtocolV0RpcMessage decodeFrame(ByteBuf in) {
     //            }
     //            rpcMessage.setBody(msgCodec);
     
    -            // v0_2
    +            // v0 方案2(已实现
                 int length = in.readableBytes();
                 byte[] bs = new byte[length];
                 in.readBytes(bs);
    +            // todo [5738-discuss][decode] 旧版本协议在这里是有messageType的,所以这里要补
                 byte[] bs2 = new byte[2 + length];
    -            bs2[0] = (byte) (0x00FF & (typeCode>>8));
    +            bs2[0] = (byte) (0x00FF & (typeCode >> 8));
                 bs2[1] = (byte) (0x00FF & typeCode);
    -            System.arraycopy(bs,0,bs2,2, length);
    -            byte codecType = isSeataCodec? SerializerType.SEATA.getCode():SerializerType.HESSIAN.getCode();
    +            System.arraycopy(bs, 0, bs2, 2, length);
    +            byte codecType = isSeataCodec ? SerializerType.SEATA.getCode() : SerializerType.HESSIAN.getCode();
                 Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codecType), ProtocolConstants.VERSION_0);
                 rpcMessage.setBody(serializer.deserialize(bs2));
    -
             } catch (Exception e) {
                 LOGGER.error("decode error", "", e);
                 throw e;
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java
    index 8e1cfc4a599..988276eee36 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java
    @@ -17,15 +17,11 @@
     
     import io.netty.buffer.ByteBuf;
     import io.netty.channel.ChannelHandlerContext;
    -import io.seata.core.compressor.Compressor;
    -import io.seata.core.compressor.CompressorFactory;
     import io.seata.core.protocol.HeartbeatMessage;
     import io.seata.core.protocol.MessageTypeAware;
     import io.seata.core.protocol.ProtocolConstants;
     import io.seata.core.protocol.RpcMessage;
     import io.seata.core.rpc.netty.ProtocolEncoder;
    -import io.seata.core.rpc.netty.ProtocolRpcMessage;
    -import io.seata.core.rpc.netty.v1.ProtocolV1RpcMessage;
     import io.seata.core.serializer.Serializer;
     import io.seata.core.serializer.SerializerServiceLoader;
     import io.seata.core.serializer.SerializerType;
    @@ -66,15 +62,6 @@ public class ProtocolV0Encoder implements ProtocolEncoder {
     
         private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV0Encoder.class);
     
    -    public static void encode(ChannelHandlerContext ctx, ProtocolV0RpcMessage rpcMessage, ByteBuf out) {
    -        try {
    -            // todo 按照旧协议方式encode
    -            System.out.println();
    -        } catch (Throwable e) {
    -            LOGGER.error("Encode request error!", e);
    -        }
    -    }
    -
         @Override
         public void encode(RpcMessage message, ByteBuf out) {
             try {
    @@ -96,8 +83,6 @@ public void encode(RpcMessage message, ByteBuf out) {
                     return;
                 }
     
    -
    -
                 byte[] bodyBytes = null;
                 Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codec), ProtocolConstants.VERSION_0);
                 bodyBytes = serializer.serialize(msg.getBody());
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java
    index 3ed60fb8167..9cb1af723d8 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java
    @@ -15,19 +15,16 @@
      */
     package io.seata.core.rpc.netty.v0;
     
    -import io.seata.common.util.StringUtils;
     import io.seata.core.compressor.CompressorType;
     import io.seata.core.protocol.ProtocolConstants;
     import io.seata.core.protocol.RpcMessage;
     import io.seata.core.rpc.netty.ProtocolRpcMessage;
     import io.seata.core.serializer.SerializerType;
     
    -import java.util.HashMap;
    -import java.util.Map;
     import java.util.concurrent.atomic.AtomicLong;
     
     /**
    - * ?
    + * the protocol v0 rpc message
      *
      * @author minghua.xie
      * @date 2023/8/1
    @@ -163,7 +160,7 @@ public void setMessageType(byte messageType) {
         public RpcMessage protocolMsg2RpcMsg(){
             RpcMessage rpcMessage = new RpcMessage();
             rpcMessage.setMessageType(this.messageType);
    -        // todo 基础配置
    +        // todo 基础配置补充完整
             rpcMessage.setCompressor(CompressorType.NONE.getCode());
     
             byte codecType = this.isSeataCodec? SerializerType.SEATA.getCode():SerializerType.HESSIAN.getCode();
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java
    index 8e2db58f3f3..9e06ed526a9 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java
    @@ -112,5 +112,4 @@ public ProtocolRpcMessage decodeFrame(ByteBuf frame) {
     
             return rpcMessage;
         }
    -
     }
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    index 644ecec4057..d91e08189e8 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java
    @@ -16,14 +16,12 @@
     package io.seata.core.rpc.netty.v1;
     
     import io.netty.buffer.ByteBuf;
    -import io.seata.core.protocol.RpcMessage;
     import io.seata.core.rpc.netty.ProtocolEncoder;
    -import io.seata.core.rpc.netty.ProtocolRpcMessage;
    -import io.seata.core.rpc.netty.v0.ProtocolV0Encoder;
     import io.seata.core.serializer.Serializer;
     import io.seata.core.compressor.Compressor;
     import io.seata.core.compressor.CompressorFactory;
     import io.seata.core.protocol.ProtocolConstants;
    +import io.seata.core.protocol.RpcMessage;
     import io.seata.core.serializer.SerializerServiceLoader;
     import io.seata.core.serializer.SerializerType;
     import org.slf4j.Logger;
    @@ -69,7 +67,6 @@ public void encode(RpcMessage message, ByteBuf out) {
                 ProtocolV1RpcMessage rpcMessage = new ProtocolV1RpcMessage();
                 rpcMessage.rpcMsg2ProtocolMsg(message);
     
    -//            if (msg instanceof RpcMessage) {
                 int fullLength = ProtocolConstants.V1_HEAD_LENGTH;
                 int headLength = ProtocolConstants.V1_HEAD_LENGTH;
     
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java
    index 60578e2be6c..ba2cbd8d5e1 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java
    @@ -24,7 +24,7 @@
     import java.util.Map;
     
     /**
    - * ?
    + * protocol v1 rpc message
      *
      * @author minghua.xie
      * @date 2023/8/1
    diff --git a/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java b/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java
    index c2d1b3ab9c1..bca11d6b4c5 100644
    --- a/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java
    +++ b/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java
    @@ -39,7 +39,7 @@ private SerializerServiceLoader() {
          * @return the service of {@link Serializer}
          * @throws EnhancedServiceNotFoundException the enhanced service not found exception
          */
    -    public static Serializer load(SerializerType type,int version) throws EnhancedServiceNotFoundException {
    +    public static Serializer load(SerializerType type, int version) throws EnhancedServiceNotFoundException {
             if (type == SerializerType.PROTOBUF) {
                 try {
                     ReflectionUtil.getClassByName(PROTOBUF_SERIALIZER_CLASS_NAME);
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java
    index 612b550d16c..8d7091aca5d 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java
    @@ -83,7 +83,7 @@
      * @author zhangsen
      */
     public class MessageCodecFactory {
    -
    +// todo [5738-discuss][codec] 这个工厂类的大部分职责都被我改成serialize父类的map了,剩下的merge和batch看如何处理?
         /**
          * The constant UTF8.
          */
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java
    index 6cfb8733271..1fe8b5dd0ee 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java
    @@ -24,6 +24,8 @@
      * The type Abstract identify request codec.
      */
     public abstract class AbstractIdentifyRequestCodec extends AbstractMessageCodec {
    +    // todo [5738-discuss][codec] 像这种父类如果是这次的新旧版本都一样,要写成继承吗
    +    // todo [5738-discuss][codec] 这些codec类只依靠包区分是否足够?
     
         @Override
         public Class getMessageClassType() {
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java
    index ff2569bcf63..d071572f301 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java
    @@ -24,7 +24,6 @@
      * @author zhangsen
      */
     public class RegisterTMRequestCodec extends AbstractIdentifyRequestCodec {
    -
         @Override
         public Class getMessageClassType() {
             return RegisterTMRequest.class;
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java
    index ad481ed6d3b..456786132d4 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java
    @@ -17,7 +17,6 @@
     
     
     import io.seata.core.protocol.RegisterTMResponse;
    -import io.seata.serializer.seata.protocol.v1.AbstractIdentifyResponseCodec;
     
     /**
      * The type Register tm response codec.
    @@ -25,7 +24,6 @@
      * @author zhangsen
      */
     public class RegisterTMResponseCodec extends AbstractIdentifyResponseCodec {
    -
         @Override
         public Class getMessageClassType() {
             return RegisterTMResponse.class;
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java
    index 9c8b55357aa..8bb8f0b9018 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java
    @@ -30,7 +30,7 @@
     import java.nio.ByteBuffer;
     
     /**
    - * The Seata codec v1.
    + * The Seata codec v0.
      *
      * @author Bughue
      */
    diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java
    index 663bdf9f55a..3a325a5e7ab 100644
    --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java
    +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java
    @@ -24,7 +24,8 @@
      * The type Abstract identify request codec.
      */
     public abstract class AbstractIdentifyRequestCodec extends AbstractMessageCodec {
    -
    +    // todo [5738-discuss][codec] 像这种父类如果是这次的新旧版本都一样,要写成继承吗
    +    // todo [5738-discuss][codec] 这些codec类只依靠包区分是否足够?
         @Override
         public Class getMessageClassType() {
             return AbstractIdentifyRequest.class;
    
    From 9207d2f45060a5211676f50f3bb78680fe3146bd Mon Sep 17 00:00:00 2001
    From: "minghua.xie" 
    Date: Thu, 21 Sep 2023 18:29:53 +0800
    Subject: [PATCH 12/22] protocol
    
    ---
     .../common/loader/EnhancedServiceLoader.java  |  30 +-
     .../common/loader/ExtensionDefinition.java    |  10 +-
     .../io/seata/common/loader/LoadLevel.java     |   8 -
     .../io/seata/core/protocol/RpcMessage.java    |  10 +-
     .../java/io/seata/core/protocol/Version.java  |  12 +-
     .../rpc/DefaultServerMessageListenerImpl.java |   4 +-
     .../java/io/seata/core/rpc/RpcContext.java    |  10 -
     .../core/rpc/netty/AbstractNettyRemoting.java |   6 +-
     .../netty/AbstractNettyRemotingClient.java    |  15 +-
     .../netty/AbstractNettyRemotingServer.java    |  35 +-
     .../seata/core/rpc/netty/ChannelManager.java  |   6 +-
     .../rpc/netty/CompatibleProtocolDecoder.java  |  12 +-
     .../rpc/netty/CompatibleProtocolEncoder.java  |  12 +-
     .../netty/CompatibleProtocolVersionMap.java   |  16 +
     .../core/rpc/netty/NettyClientBootstrap.java  |   2 -
     .../seata/core/rpc/netty/ProtocolDecoder.java |   2 +-
     .../seata/core/rpc/netty/ProtocolEncoder.java |   2 +-
     ...onstants.java => ProtocolConstantsV0.java} |   2 +-
     ...lV0Decoder.java => ProtocolDecoderV0.java} |  49 +--
     ...lV0Encoder.java => ProtocolEncoderV0.java} |  21 +-
     ...Message.java => ProtocolRpcMessageV0.java} |   5 +-
     .../seata/core/rpc/netty/v0/SerializerV0.java |   6 -
     ...lV1Decoder.java => ProtocolDecoderV1.java} |   9 +-
     ...lV1Encoder.java => ProtocolEncoderV1.java} |   8 +-
     ...Message.java => ProtocolRpcMessageV1.java} |   7 +-
     .../rpc/processor/server/RegRmProcessor.java  |   2 +-
     .../rpc/processor/server/RegTmProcessor.java  |   4 +-
     .../serializer/SerializerServiceLoader.java   |   8 +-
     .../serializer/seata/MessageCodecFactory.java | 191 +---------
     .../seata/SeataAbstractSerializer.java        | 127 -------
     .../serializer/seata/SeataSerializer.java     | 145 ++++++++
     .../v0/AbstractIdentifyRequestCodec.java      | 156 ---------
     .../v0/AbstractIdentifyResponseCodec.java     |  70 ----
     .../protocol/v0/AbstractMessageCodec.java     |  72 ----
     .../v0/AbstractResultMessageCodec.java        |  77 ----
     .../protocol/v0/BatchResultMessageCodec.java  |  13 +
     .../protocol/v0/MergeResultMessageCodec.java  |  13 +
     .../protocol/v0/MergedWarpMessageCodec.java   |  13 +
     .../protocol/v0/MessageCodecFactoryV0.java    |  54 +++
     .../protocol/v0/RegisterTMRequestCodec.java   |  32 --
     .../protocol/v0/RegisterTMResponseCodec.java  |  32 --
     .../seata/protocol/v0/SeataV0Serializer.java  | 100 ------
     .../v0_1/AbstractIdentifyRequestV0.java       | 329 ------------------
     .../v0_1/AbstractIdentifyResponseV0.java      | 144 --------
     .../protocol/v0_1/AbstractMessageV0.java      |  88 -----
     .../v0_1/AbstractResultMessageV0.java         | 155 ---------
     .../seata/protocol/v0_1/MergedMessageV0.java  |  33 --
     .../protocol/v0_1/RegisterRMRequestV0.java    | 174 ---------
     .../protocol/v0_1/RegisterRMResponseV0.java   |  53 ---
     .../protocol/v0_1/RegisterTMRequestV0.java    |  73 ----
     .../protocol/v0_1/RegisterTMResponseV0.java   |  53 ---
     .../protocol/v0_1/SeataV0Serializer.java      | 139 --------
     .../v1/AbstractIdentifyRequestCodec.java      |   3 +-
     .../protocol/v1/BatchResultMessageCodec.java  |   9 +-
     .../protocol/v1/MergeResultMessageCodec.java  |   9 +-
     .../protocol/v1/MergedWarpMessageCodec.java   |   9 +-
     .../protocol/v1/MessageCodecFactoryV1.java    | 184 ++++++++++
     .../seata/protocol/v1/SeataV1Serializer.java  |  47 ---
     .../io.seata.core.rpc.netty.v0.SerializerV0   |   1 -
     .../io.seata.core.serializer.Serializer       |   3 +-
     60 files changed, 565 insertions(+), 2349 deletions(-)
     create mode 100644 core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolVersionMap.java
     rename core/src/main/java/io/seata/core/rpc/netty/v0/{ProtocolV0Constants.java => ProtocolConstantsV0.java} (96%)
     rename core/src/main/java/io/seata/core/rpc/netty/v0/{ProtocolV0Decoder.java => ProtocolDecoderV0.java} (71%)
     rename core/src/main/java/io/seata/core/rpc/netty/v0/{ProtocolV0Encoder.java => ProtocolEncoderV0.java} (87%)
     rename core/src/main/java/io/seata/core/rpc/netty/v0/{ProtocolV0RpcMessage.java => ProtocolRpcMessageV0.java} (97%)
     delete mode 100644 core/src/main/java/io/seata/core/rpc/netty/v0/SerializerV0.java
     rename core/src/main/java/io/seata/core/rpc/netty/v1/{ProtocolV1Decoder.java => ProtocolDecoderV1.java} (95%)
     rename core/src/main/java/io/seata/core/rpc/netty/v1/{ProtocolV1Encoder.java => ProtocolEncoderV1.java} (96%)
     rename core/src/main/java/io/seata/core/rpc/netty/v1/{ProtocolV1RpcMessage.java => ProtocolRpcMessageV1.java} (95%)
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java
     create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponseCodec.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageCodec.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageCodec.java
     create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/BatchResultMessageCodec.java
     create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergeResultMessageCodec.java
     create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedWarpMessageCodec.java
     create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MessageCodecFactoryV0.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyRequestV0.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyResponseV0.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractMessageV0.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractResultMessageV0.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/MergedMessageV0.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMRequestV0.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMResponseV0.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMRequestV0.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMResponseV0.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/SeataV0Serializer.java
     create mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MessageCodecFactoryV1.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/SeataV1Serializer.java
     delete mode 100644 serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.rpc.netty.v0.SerializerV0
    
    diff --git a/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java b/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java
    index 74863a6c490..dc56d50f76c 100644
    --- a/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java
    +++ b/common/src/main/java/io/seata/common/loader/EnhancedServiceLoader.java
    @@ -25,7 +25,6 @@
     import java.util.List;
     import java.util.Map;
     import java.util.Objects;
    -import java.util.Optional;
     import java.util.concurrent.ConcurrentHashMap;
     import java.util.concurrent.ConcurrentMap;
     import java.util.stream.Collectors;
    @@ -89,11 +88,6 @@ public static  S load(Class service, String activateName) throws EnhancedS
             return InnerEnhancedServiceLoader.getServiceLoader(service).load(activateName, findClassLoader());
         }
     
    -
    -    public static  S load(Class service, String activateName,int version) throws EnhancedServiceNotFoundException {
    -        return InnerEnhancedServiceLoader.getServiceLoader(service).loadExtension(activateName, findClassLoader(), null, null, version);
    -    }
    -
         /**
          * Specify classLoader to load the service provider
          *
    @@ -413,13 +407,13 @@ private S loadExtension(ClassLoader loader, Class[] argTypes, Object[] args)
     
             @SuppressWarnings("rawtypes")
             private S loadExtension(String activateName, ClassLoader loader, Class[] argTypes,
    -                                Object[] args, int version) {
    +                                Object[] args) {
                 if (StringUtils.isEmpty(activateName)) {
                     throw new IllegalArgumentException("the name of service provider for [" + type.getName() + "] name is null");
                 }
                 try {
                     loadAllExtensionClass(loader);
    -                ExtensionDefinition cachedExtensionDefinition = getCachedExtensionDefinition(activateName, version);
    +                ExtensionDefinition cachedExtensionDefinition = getCachedExtensionDefinition(activateName);
                     return getExtensionInstance(cachedExtensionDefinition, loader, argTypes, args);
                 } catch (Throwable e) {
                     if (e instanceof EnhancedServiceNotFoundException) {
    @@ -432,13 +426,6 @@ private S loadExtension(String activateName, ClassLoader loader, Class[] argType
                 }
             }
     
    -
    -        @SuppressWarnings("rawtypes")
    -        private S loadExtension(String activateName, ClassLoader loader, Class[] argTypes,
    -                                Object[] args) {
    -            return loadExtension(activateName,loader,argTypes,args, -1);
    -        }
    -
             private S getExtensionInstance(ExtensionDefinition definition, ClassLoader loader, Class[] argTypes,
                                            Object[] args) {
                 if (definition == null) {
    @@ -594,15 +581,13 @@ private ExtensionDefinition getUnloadedExtensionDefinition(String className,
                     String serviceName = null;
                     int priority = 0;
                     Scope scope = Scope.SINGLETON;
    -                byte version = -1;
                     LoadLevel loadLevel = clazz.getAnnotation(LoadLevel.class);
                     if (loadLevel != null) {
                         serviceName = loadLevel.name();
                         priority = loadLevel.order();
                         scope = loadLevel.scope();
    -                    version = loadLevel.version();
                     }
    -                ExtensionDefinition result = new ExtensionDefinition<>(serviceName, priority, scope, enhancedServiceClass, version);
    +                ExtensionDefinition result = new ExtensionDefinition<>(serviceName, priority, scope, enhancedServiceClass);
                     classToDefinitionMap.put(clazz, result);
                     if (serviceName != null) {
                         CollectionUtils.computeIfAbsent(nameToDefinitionsMap, serviceName, e -> new ArrayList<>())
    @@ -630,15 +615,8 @@ private ExtensionDefinition getDefaultExtensionDefinition() {
                 return CollectionUtils.getLast(currentDefinitions);
             }
     
    -        private ExtensionDefinition getCachedExtensionDefinition(String activateName, int version) {
    +        private ExtensionDefinition getCachedExtensionDefinition(String activateName) {
                 List> definitions = nameToDefinitionsMap.get(activateName);
    -            if (version >= 0) {
    -                Optional> first = definitions.stream().filter(d -> d.getVersion() == version).findFirst();
    -                if (first.isPresent()) {
    -                    return first.get();
    -                }
    -            }
    -            // todo [5738-discuss][class-loader] 实在找不到的话还要随便找个版本吗?这样不太严谨?
                 return CollectionUtils.getLast(definitions);
             }
     
    diff --git a/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java b/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java
    index ef27aa74d95..ea8b4790c1a 100644
    --- a/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java
    +++ b/common/src/main/java/io/seata/common/loader/ExtensionDefinition.java
    @@ -28,15 +28,11 @@ final class ExtensionDefinition {
         private final String name;
         private final Class serviceClass;
         private final Integer order;
    -    private final Integer version;
         private final Scope scope;
     
         public Integer getOrder() {
             return this.order;
         }
    -    public Integer getVersion() {
    -        return this.version;
    -    }
     
         public Class getServiceClass() {
             return this.serviceClass;
    @@ -47,16 +43,12 @@ public Scope getScope() {
         }
     
         public ExtensionDefinition(String name, Integer order, Scope scope, Class clazz) {
    -        this(name,order,scope,clazz,-1);
    -    }
    -
    -    public ExtensionDefinition(String name, Integer order, Scope scope, Class clazz, int version) {
             this.name = name;
             this.order = order;
    -        this.version = version;
             this.scope = scope;
             this.serviceClass = clazz;
         }
    +
         @Override
         public int hashCode() {
             final int prime = 31;
    diff --git a/common/src/main/java/io/seata/common/loader/LoadLevel.java b/common/src/main/java/io/seata/common/loader/LoadLevel.java
    index 086d65a10b5..1c974a6a03f 100644
    --- a/common/src/main/java/io/seata/common/loader/LoadLevel.java
    +++ b/common/src/main/java/io/seata/common/loader/LoadLevel.java
    @@ -44,14 +44,6 @@
          */
         int order() default 0;
     
    -    /**
    -     * version int.
    -     *
    -     * @return the int
    -     */
    -    // todo [5738-discuss][class-loader] 由于0也是个版本,所以现在默认是-1
    -    byte version() default -1;
    -
         /**
          * Scope enum.
          */
    diff --git a/core/src/main/java/io/seata/core/protocol/RpcMessage.java b/core/src/main/java/io/seata/core/protocol/RpcMessage.java
    index 7f1f91d1ebb..d47b60af514 100644
    --- a/core/src/main/java/io/seata/core/protocol/RpcMessage.java
    +++ b/core/src/main/java/io/seata/core/protocol/RpcMessage.java
    @@ -34,7 +34,7 @@ public class RpcMessage {
         private Map headMap = new HashMap<>();
         private Object body;
     
    -    private byte protocolVersion;
    +    private String version;
     
         /**
          * Gets id.
    @@ -170,12 +170,12 @@ public void setMessageType(byte messageType) {
             this.messageType = messageType;
         }
     
    -    public byte getProtocolVersion() {
    -        return protocolVersion;
    +    public String getVersion() {
    +        return version;
         }
     
    -    public void setProtocolVersion(byte protocolVersion) {
    -        this.protocolVersion = protocolVersion;
    +    public void setVersion(String version) {
    +        this.version = version;
         }
     
         @Override
    diff --git a/core/src/main/java/io/seata/core/protocol/Version.java b/core/src/main/java/io/seata/core/protocol/Version.java
    index 96b47df8d8b..bdf77b26e3e 100644
    --- a/core/src/main/java/io/seata/core/protocol/Version.java
    +++ b/core/src/main/java/io/seata/core/protocol/Version.java
    @@ -37,7 +37,7 @@ public class Version {
          * The constant CURRENT.
          */
         private static final String CURRENT = VersionInfo.VERSION;
    -    private static final String VERSION_0_7_1 = "0.7.1";
    +    public static final String VERSION_0_7_1 = "0.7.1";
         private static final String VERSION_1_5_0 = "1.5.0";
         private static final int MAX_VERSION_DOT = 3;
     
    @@ -152,6 +152,16 @@ public static long convertVersionNotThrowException(String version) {
             return -1;
         }
     
    +    public static byte calcProtocolVersion(String sdkVersion) throws IncompatibleVersionException {
    +        long version = convertVersion(sdkVersion);
    +        long v0 = convertVersion(VERSION_0_7_1);
    +        if (version <= v0) {
    +            return ProtocolConstants.VERSION_0;
    +        }else {
    +            return ProtocolConstants.VERSION_1;
    +        }
    +    }
    +
         private static long calculatePartValue(String partNumeric, int size, int index) {
             return Long.parseLong(partNumeric) * Double.valueOf(Math.pow(100, size - index)).longValue();
         }
    diff --git a/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java b/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java
    index 40499d1d80d..c81f78fb5d4 100644
    --- a/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java
    +++ b/core/src/main/java/io/seata/core/rpc/DefaultServerMessageListenerImpl.java
    @@ -113,7 +113,7 @@ public void onRegRmMessage(RpcMessage request, ChannelHandlerContext ctx, Regist
             String errorInfo = StringUtils.EMPTY;
             try {
                 if (checkAuthHandler == null || checkAuthHandler.regResourceManagerCheckAuth(message)) {
    -                ChannelManager.registerRMChannel(message, ctx.channel(), request.getProtocolVersion());
    +                ChannelManager.registerRMChannel(message, ctx.channel());
                     Version.putChannelVersion(ctx.channel(), message.getVersion());
                     isSuccess = true;
                     if (LOGGER.isDebugEnabled()) {
    @@ -145,7 +145,7 @@ public void onRegTmMessage(RpcMessage request, ChannelHandlerContext ctx, Regist
             String errorInfo = StringUtils.EMPTY;
             try {
                 if (checkAuthHandler == null || checkAuthHandler.regTransactionManagerCheckAuth(message)) {
    -                ChannelManager.registerTMChannel(message, ctx.channel(), request.getProtocolVersion());
    +                ChannelManager.registerTMChannel(message, ctx.channel());
                     Version.putChannelVersion(ctx.channel(), message.getVersion());
                     isSuccess = true;
                     if (LOGGER.isDebugEnabled()) {
    diff --git a/core/src/main/java/io/seata/core/rpc/RpcContext.java b/core/src/main/java/io/seata/core/rpc/RpcContext.java
    index 6a86b088126..2fe3cca0769 100644
    --- a/core/src/main/java/io/seata/core/rpc/RpcContext.java
    +++ b/core/src/main/java/io/seata/core/rpc/RpcContext.java
    @@ -42,8 +42,6 @@ public class RpcContext {
     
         private String version;
     
    -    private byte protocolVersion;
    -
         private String applicationId;
     
         private String transactionServiceGroup;
    @@ -322,14 +320,6 @@ public void setClientId(String clientId) {
             this.clientId = clientId;
         }
     
    -    public byte getProtocolVersion() {
    -        return protocolVersion;
    -    }
    -
    -    public void setProtocolVersion(byte protocolVersion) {
    -        this.protocolVersion = protocolVersion;
    -    }
    -
         @Override
         public String toString() {
             return "RpcContext{" +
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java
    index 1fa623e0302..2fe850e63b5 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java
    @@ -28,6 +28,7 @@
     import io.seata.core.protocol.MessageTypeAware;
     import io.seata.core.protocol.ProtocolConstants;
     import io.seata.core.protocol.RpcMessage;
    +import io.seata.core.protocol.Version;
     import io.seata.core.rpc.Disposable;
     import io.seata.core.rpc.hook.RpcHook;
     import io.seata.core.rpc.processor.Pair;
    @@ -231,15 +232,14 @@ protected void sendAsync(Channel channel, RpcMessage rpcMessage) {
                 }
             });
         }
    -
    -    protected RpcMessage buildRequestMessage(Object msg, byte messageType) {
    +    protected RpcMessage buildRequestMessage(Object msg, byte messageType, String version) {
             RpcMessage rpcMessage = new RpcMessage();
             rpcMessage.setId(getNextMessageId());
             rpcMessage.setMessageType(messageType);
             rpcMessage.setCodec(ProtocolConstants.CONFIGURED_CODEC);
             rpcMessage.setCompressor(ProtocolConstants.CONFIGURED_COMPRESSOR);
             rpcMessage.setBody(msg);
    -        rpcMessage.setProtocolVersion(ProtocolConstants.VERSION_CURRENT);
    +        rpcMessage.setVersion(version);
             return rpcMessage;
         }
     
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java
    index 6d6fc503e78..1e08f6ab75b 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java
    @@ -50,6 +50,7 @@
     import io.seata.core.protocol.MessageFuture;
     import io.seata.core.protocol.ProtocolConstants;
     import io.seata.core.protocol.RpcMessage;
    +import io.seata.core.protocol.Version;
     import io.seata.core.protocol.transaction.AbstractGlobalEndRequest;
     import io.seata.core.protocol.transaction.BranchRegisterRequest;
     import io.seata.core.protocol.transaction.BranchReportRequest;
    @@ -141,7 +142,7 @@ public AbstractNettyRemotingClient(NettyClientConfig nettyClientConfig, EventExe
         public Object sendSyncRequest(Object msg) throws TimeoutException {
             String serverAddress = loadBalance(getTransactionServiceGroup(), msg);
             long timeoutMillis = this.getRpcRequestTimeout();
    -        RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC);
    +        RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC, Version.getCurrent());
     
             // send batch message
             // put message into basketMap, @see MergedSendRunnable
    @@ -195,7 +196,7 @@ public Object sendSyncRequest(Channel channel, Object msg) throws TimeoutExcepti
                 LOGGER.warn("sendSyncRequest nothing, caused by null channel.");
                 return null;
             }
    -        RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC);
    +        RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC, Version.getCurrent());
             return super.sendSync(channel, rpcMessage, this.getRpcRequestTimeout());
         }
     
    @@ -206,8 +207,8 @@ public void sendAsyncRequest(Channel channel, Object msg) {
                 return;
             }
             RpcMessage rpcMessage = buildRequestMessage(msg, msg instanceof HeartbeatMessage
    -            ? ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST
    -            : ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY);
    +                ? ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST
    +                : ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY, Version.getCurrent());
             if (rpcMessage.getBody() instanceof MergeMessage) {
                 mergeMsgMap.put(rpcMessage.getId(), (MergeMessage) rpcMessage.getBody());
             }
    @@ -416,13 +417,9 @@ public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exce
                 RpcMessage rpcMessage = null;
                 if (msg instanceof ProtocolRpcMessage) {
                     rpcMessage = ((ProtocolRpcMessage) msg).protocolMsg2RpcMsg();
    -            }
    -
    -            if (rpcMessage != null) {
                     processMessage(ctx, rpcMessage);
                 } else {
    -                // todo [5738-discuss][类型] 会有这种情况吗??按之前的就是不处理?
    -                //打日志?
    +                LOGGER.error("rpcMessage type error");
                 }
             }
     
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java
    index 435d713d5dc..5e7c2740804 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java
    @@ -69,31 +69,21 @@ public Object sendSyncRequest(String resourceId, String clientId, Object msg, bo
             if (channel == null) {
                 throw new RuntimeException("rm client is not connected. dbkey:" + resourceId + ",clientId:" + clientId);
             }
    -        RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC);
    -        return superSendSync(channel, rpcMessage);
    -    }
    -
    -    private void superSendAsync(Channel channel, RpcMessage rpcMessage) {
             RpcContext rpcContext = ChannelManager.getContextFromIdentified(channel);
    -        // todo [5738-discuss][兼容] ,目前看到用这个方法的地方都没有做空判断
    -        rpcMessage.setProtocolVersion(rpcContext.getProtocolVersion());
    -        super.sendAsync(channel, rpcMessage);
    -    }
    -
    -    private Object superSendSync(Channel channel, RpcMessage rpcMessage) throws TimeoutException {
    -        RpcContext rpcContext = ChannelManager.getContextFromIdentified(channel);
    -        // todo [5738-discuss][兼容] ,目前看到用这个方法的地方都没有做空判断
    -        rpcMessage.setProtocolVersion(rpcContext.getProtocolVersion());
    +        RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC, rpcContext.getVersion());
             return super.sendSync(channel, rpcMessage, NettyServerConfig.getRpcRequestTimeout());
         }
     
    +
    +
         @Override
         public Object sendSyncRequest(Channel channel, Object msg) throws TimeoutException {
             if (channel == null) {
                 throw new RuntimeException("client is not connected");
             }
    -        RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC);
    -        return superSendSync(channel, rpcMessage);
    +        RpcContext rpcContext = ChannelManager.getContextFromIdentified(channel);
    +        RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC, rpcContext.getVersion());
    +        return super.sendSync(channel, rpcMessage, NettyServerConfig.getRpcRequestTimeout());
         }
     
         @Override
    @@ -101,8 +91,9 @@ public void sendAsyncRequest(Channel channel, Object msg) {
             if (channel == null) {
                 throw new RuntimeException("client is not connected");
             }
    -        RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY);
    -        superSendAsync(channel, rpcMessage);
    +        RpcContext rpcContext = ChannelManager.getContextFromIdentified(channel);
    +        RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY, rpcContext.getVersion());
    +        super.sendAsync(channel, rpcMessage);
         }
     
         @Override
    @@ -115,7 +106,7 @@ public void sendAsyncResponse(RpcMessage rpcMessage, Channel channel, Object msg
                 RpcMessage rpcMsg = buildResponseMessage(rpcMessage, msg, msg instanceof HeartbeatMessage
                     ? ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE
                     : ProtocolConstants.MSGTYPE_RESPONSE);
    -            superSendAsync(clientChannel, rpcMsg);
    +            super.sendAsync(clientChannel, rpcMsg);
             } else {
                 throw new RuntimeException("channel is error.");
             }
    @@ -180,11 +171,9 @@ public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exce
                 RpcMessage rpcMessage = null;
                 if (msg instanceof ProtocolRpcMessage) {
                     rpcMessage = ((ProtocolRpcMessage) msg).protocolMsg2RpcMsg();
    -            }
    -            if (rpcMessage != null) {
                     processMessage(ctx, rpcMessage);
    -            } else {
    -                // todo [5738-discuss][兼容] 正常会有这种情况吗?打日志还是抛异常?
    +            }else {
    +                LOGGER.error("rpcMessage type error");
                 }
             }
     
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/ChannelManager.java b/core/src/main/java/io/seata/core/rpc/netty/ChannelManager.java
    index b946815045e..33e39033e95 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/ChannelManager.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/ChannelManager.java
    @@ -120,7 +120,7 @@ private static RpcContext buildChannelHolder(NettyPoolKey.TransactionRole client
          * @param channel the channel
          * @throws IncompatibleVersionException the incompatible version exception
          */
    -    public static void registerTMChannel(RegisterTMRequest request, Channel channel, byte protocolVersion)
    +    public static void registerTMChannel(RegisterTMRequest request, Channel channel)
             throws IncompatibleVersionException {
             Version.checkVersion(request.getVersion());
             RpcContext rpcContext = buildChannelHolder(NettyPoolKey.TransactionRole.TMROLE, request.getVersion(),
    @@ -133,7 +133,6 @@ public static void registerTMChannel(RegisterTMRequest request, Channel channel,
             ConcurrentMap clientIdentifiedMap = CollectionUtils.computeIfAbsent(TM_CHANNELS,
                 clientIdentified, key -> new ConcurrentHashMap<>());
             rpcContext.holdInClientChannels(clientIdentifiedMap);
    -        rpcContext.setProtocolVersion(protocolVersion);
         }
     
         /**
    @@ -143,7 +142,7 @@ public static void registerTMChannel(RegisterTMRequest request, Channel channel,
          * @param channel                the channel
          * @throws IncompatibleVersionException the incompatible  version exception
          */
    -    public static void registerRMChannel(RegisterRMRequest resourceManagerRequest, Channel channel, byte protocolVersion)
    +    public static void registerRMChannel(RegisterRMRequest resourceManagerRequest, Channel channel)
             throws IncompatibleVersionException {
             Version.checkVersion(resourceManagerRequest.getVersion());
             Set dbkeySet = dbKeytoSet(resourceManagerRequest.getResourceIds());
    @@ -167,7 +166,6 @@ public static void registerRMChannel(RegisterRMRequest resourceManagerRequest, C
                 rpcContext.holdInResourceManagerChannels(resourceId, portMap);
                 updateChannelsResource(resourceId, clientIp, resourceManagerRequest.getApplicationId());
             }
    -        rpcContext.setProtocolVersion(protocolVersion);
         }
     
         private static void updateChannelsResource(String resourceId, String clientIp, String applicationId) {
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java
    index 61d70127986..db859581dda 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java
    @@ -21,8 +21,8 @@
     import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
     import io.seata.core.exception.DecodeException;
     import io.seata.core.protocol.ProtocolConstants;
    -import io.seata.core.rpc.netty.v0.ProtocolV0Decoder;
    -import io.seata.core.rpc.netty.v1.ProtocolV1Decoder;
    +import io.seata.core.rpc.netty.v0.ProtocolDecoderV0;
    +import io.seata.core.rpc.netty.v1.ProtocolDecoderV1;
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
     
    @@ -75,8 +75,8 @@ int lengthFieldLength,  FullLength is int(4B). so values is 4
             */
             super(maxFrameLength, 3, 4, -7, 0);
             protocolDecoderMap = ImmutableMap.builder()
    -                .put(ProtocolConstants.VERSION_0, new ProtocolV0Decoder())
    -                .put(ProtocolConstants.VERSION_1, new ProtocolV1Decoder())
    +                .put(ProtocolConstants.VERSION_0, new ProtocolDecoderV0())
    +                .put(ProtocolConstants.VERSION_1, new ProtocolDecoderV1())
                     .build();
         }
     
    @@ -87,7 +87,6 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
             byte version;
             try {
                 if (isV0(in)) {
    -                // todo [5738-discuss][decode] 旧版本连super都不会走,会不会有其他问题?
                     decoded = in;
                     version = ProtocolConstants.VERSION_0;
                 } else {
    @@ -100,7 +99,6 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
                     try {
                         ProtocolDecoder decoder = protocolDecoderMap.get(version);
                         if (decoder == null) {
    -                        // todo [5738-discuss][兼容] 要不要适配当前版本?
                             throw new IllegalArgumentException("Unknown version: " + version);
                         }
                         return decoder.decodeFrame(frame);
    @@ -112,7 +110,6 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
                 }
             } catch (Exception exx) {
                 LOGGER.error("Decode frame error, cause: {}", exx.getMessage());
    -            // todo [5738-discuss][优化] 这里抛出去之后似乎没有地方打印了?
                 throw new DecodeException(exx);
             }
             return decoded;
    @@ -133,7 +130,6 @@ protected byte decideVersion(Object in) {
                 frame.resetReaderIndex();
                 return version;
             }
    -        // todo [5738-discuss][兼容] 类型不一致的情况要允许吗?
             return -1;
         }
     
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java
    index 4f318090381..4142375bf3d 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java
    @@ -21,8 +21,9 @@
     import io.netty.handler.codec.MessageToByteEncoder;
     import io.seata.core.protocol.ProtocolConstants;
     import io.seata.core.protocol.RpcMessage;
    -import io.seata.core.rpc.netty.v0.ProtocolV0Encoder;
    -import io.seata.core.rpc.netty.v1.ProtocolV1Encoder;
    +import io.seata.core.protocol.Version;
    +import io.seata.core.rpc.netty.v0.ProtocolEncoderV0;
    +import io.seata.core.rpc.netty.v1.ProtocolEncoderV1;
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
     
    @@ -50,8 +51,8 @@ public class CompatibleProtocolEncoder extends MessageToByteEncoder {
         public CompatibleProtocolEncoder(){
             super();
             protocolEncoderMap = ImmutableMap.builder()
    -                .put(ProtocolConstants.VERSION_0, new ProtocolV0Encoder())
    -                .put(ProtocolConstants.VERSION_1, new ProtocolV1Encoder())
    +                .put(ProtocolConstants.VERSION_0, new ProtocolEncoderV0())
    +                .put(ProtocolConstants.VERSION_1, new ProtocolEncoderV1())
                     .build();
         }
     
    @@ -60,10 +61,9 @@ public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) {
             try {
                 if (msg instanceof RpcMessage) {
                     RpcMessage rpcMessage = (RpcMessage) msg;
    -                byte version = rpcMessage.getProtocolVersion();
    +                byte version = Version.calcProtocolVersion(rpcMessage.getVersion());
                     ProtocolEncoder encoder = protocolEncoderMap.get(version);
                     if (encoder == null) {
    -                    // todo [5738-discuss][encode] 要不要适配当前版本?
                         throw new IllegalArgumentException("Unknown version: " + version);
                     }
     
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolVersionMap.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolVersionMap.java
    new file mode 100644
    index 00000000000..8e39abb4ccd
    --- /dev/null
    +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolVersionMap.java
    @@ -0,0 +1,16 @@
    +package io.seata.core.rpc.netty;
    +
    +import io.seata.core.protocol.IncompatibleVersionException;
    +import io.seata.core.protocol.ProtocolConstants;
    +import io.seata.core.protocol.Version;
    +
    +/**
    + * ?
    + *
    + * @author Bughue
    + * @date 2023/9/20
    + **/
    +public class CompatibleProtocolVersionMap {
    +
    +
    +}
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/NettyClientBootstrap.java b/core/src/main/java/io/seata/core/rpc/netty/NettyClientBootstrap.java
    index 8e44eec36b8..3a6462d514d 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/NettyClientBootstrap.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/NettyClientBootstrap.java
    @@ -34,8 +34,6 @@
     import io.seata.common.exception.FrameworkException;
     import io.seata.common.thread.NamedThreadFactory;
     import io.seata.core.rpc.RemotingBootstrap;
    -import io.seata.core.rpc.netty.v1.ProtocolV1Decoder;
    -import io.seata.core.rpc.netty.v1.ProtocolV1Encoder;
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
     
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java
    index f551e1b99e4..37a5973853c 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolDecoder.java
    @@ -20,7 +20,7 @@
     /**
      * the protocol decoder
      *
    - * @author minghua.xie
    + * @author Bughue
      * @date 2023/8/1
      **/
     public interface ProtocolDecoder {
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java
    index d8c72fcf663..606a8d51a30 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolEncoder.java
    @@ -21,7 +21,7 @@
     /**
      * the protocol encoder
      *
    - * @author minghua.xie
    + * @author Bughue
      * @date 2023/8/1
      **/
     public interface ProtocolEncoder {
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolConstantsV0.java
    similarity index 96%
    rename from core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java
    rename to core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolConstantsV0.java
    index 49016d659b3..eaaa9780457 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Constants.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolConstantsV0.java
    @@ -21,7 +21,7 @@
      * @author Bughue
      * @date 2023/7/18
      **/
    -public class ProtocolV0Constants {
    +public class ProtocolConstantsV0 {
         public static short MAGIC = (short)0xdada;
     
         public static int HEAD_LENGTH = 14;
    diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolDecoderV0.java
    similarity index 71%
    rename from core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java
    rename to core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolDecoderV0.java
    index a54573c8e28..e0ea927daa3 100644
    --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Decoder.java
    +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolDecoderV0.java
    @@ -20,7 +20,6 @@
     import io.seata.core.protocol.HeartbeatMessage;
     
     import io.seata.core.protocol.ProtocolConstants;
    -import io.seata.core.rpc.RegisterCheckAuthHandler;
     import io.seata.core.rpc.netty.ProtocolDecoder;
     import io.seata.core.serializer.Serializer;
     import io.seata.core.serializer.SerializerServiceLoader;
    @@ -28,9 +27,6 @@
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
     
    -import java.util.Iterator;
    -import java.util.ServiceLoader;
    -
     /**
      * 
      *  seata-version < 0.7
    @@ -56,34 +52,28 @@
      * 

    * * @author Bughue - * @see ProtocolV0Encoder + * @see ProtocolEncoderV0 * @since 2.0.0 */ -public class ProtocolV0Decoder implements ProtocolDecoder { +public class ProtocolDecoderV0 implements ProtocolDecoder { - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV0Decoder.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolDecoderV0.class); - private static final SerializerV0 serializer = EnhancedServiceLoader.load(SerializerV0.class);; @Override - public ProtocolV0RpcMessage decodeFrame(ByteBuf in) { - ProtocolV0RpcMessage rpcMessage = new ProtocolV0RpcMessage(); - // todo [5738-discuss][decode] 旧版本是直接返回跳过了,我们需要保留这个逻辑?【特殊】 - if (in.readableBytes() < ProtocolV0Constants.HEAD_LENGTH) { + public ProtocolRpcMessageV0 decodeFrame(ByteBuf in) { + ProtocolRpcMessageV0 rpcMessage = new ProtocolRpcMessageV0(); + if (in.readableBytes() < ProtocolConstantsV0.HEAD_LENGTH) { throw new IllegalArgumentException("Nothing to decode."); } - // todo [5738-discuss][decode] 这里是为了bodyLength不满足要求时reset,意义是什么?【特殊】 in.markReaderIndex(); - - // todo 外层已经判断过了,这里可以跳过 short protocol = in.readShort(); - int flag = (int) in.readShort(); - boolean isHeartbeat = (ProtocolV0Constants.FLAG_HEARTBEAT & flag) > 0; - boolean isRequest = (ProtocolV0Constants.FLAG_REQUEST & flag) > 0; - boolean isSeataCodec = (ProtocolV0Constants.FLAG_SEATA_CODEC & flag) > 0; + boolean isHeartbeat = (ProtocolConstantsV0.FLAG_HEARTBEAT & flag) > 0; + boolean isRequest = (ProtocolConstantsV0.FLAG_REQUEST & flag) > 0; + boolean isSeataCodec = (ProtocolConstantsV0.FLAG_SEATA_CODEC & flag) > 0; rpcMessage.setSeataCodec(isSeataCodec); short bodyLength = 0; @@ -109,30 +99,20 @@ public ProtocolV0RpcMessage decodeFrame(ByteBuf in) { } if (bodyLength > 0 && in.readableBytes() < bodyLength) { - // todo [5738-discuss][兼容] 这种情况要允许吗? in.resetReaderIndex(); throw new IllegalArgumentException("readableBytes < bodyLength"); } - rpcMessage.setAsync((ProtocolV0Constants.FLAG_ASYNC & flag) > 0); + rpcMessage.setAsync((ProtocolConstantsV0.FLAG_ASYNC & flag) > 0); rpcMessage.setHeartbeat(false); rpcMessage.setRequest(isRequest); try { - // v0 方案1(未完整实现 - // todo [5738-discuss][decode] 旧方式完全分离出来更难改 - // todo serializer==null -// MessageCodecV0 msgCodec = serializer.getMsgInstanceByCode(typeCode); -// if (!msgCodec.decode(in)) { -// throw new IllegalArgumentException("decode fail."); -// } -// rpcMessage.setBody(msgCodec); - - // v0 方案2(已实现 int length = in.readableBytes(); byte[] bs = new byte[length]; in.readBytes(bs); - // todo [5738-discuss][decode] 旧版本协议在这里是有messageType的,所以这里要补 + + // fill messageType in v0 byte[] bs2 = new byte[2 + length]; bs2[0] = (byte) (0x00FF & (typeCode >> 8)); bs2[1] = (byte) (0x00FF & typeCode); @@ -141,12 +121,11 @@ public ProtocolV0RpcMessage decodeFrame(ByteBuf in) { Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codecType), ProtocolConstants.VERSION_0); rpcMessage.setBody(serializer.deserialize(bs2)); } catch (Exception e) { - LOGGER.error("decode error", "", e); + LOGGER.error("decode error", e); throw e; } if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Receive:" + rpcMessage.getBody() + ",messageId:" - + msgId); + LOGGER.debug("Receive:" + rpcMessage.getBody() + ", messageId:" + msgId); } return rpcMessage; } diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolEncoderV0.java similarity index 87% rename from core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java rename to core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolEncoderV0.java index 988276eee36..5c1cf3f05de 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0Encoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolEncoderV0.java @@ -16,7 +16,6 @@ package io.seata.core.rpc.netty.v0; import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; import io.seata.core.protocol.HeartbeatMessage; import io.seata.core.protocol.MessageTypeAware; import io.seata.core.protocol.ProtocolConstants; @@ -28,8 +27,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.nio.ByteBuffer; - /** *
      *  seata-version < 0.7
    @@ -55,25 +52,25 @@
      * 

    * * @author Bughue - * @see ProtocolV0Decoder + * @see ProtocolDecoderV0 * @since 2.0.0 */ -public class ProtocolV0Encoder implements ProtocolEncoder { +public class ProtocolEncoderV0 implements ProtocolEncoder { - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV0Encoder.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolEncoderV0.class); @Override public void encode(RpcMessage message, ByteBuf out) { try { byte codec = message.getCodec(); - ProtocolV0RpcMessage msg = new ProtocolV0RpcMessage(); + ProtocolRpcMessageV0 msg = new ProtocolRpcMessageV0(); msg.rpcMsg2ProtocolMsg(message); - out.writeShort(ProtocolV0Constants.MAGIC); - int flag = (msg.isAsync() ? ProtocolV0Constants.FLAG_ASYNC : 0) - | (msg.isHeartbeat() ? ProtocolV0Constants.FLAG_HEARTBEAT : 0) - | (msg.isRequest() ? ProtocolV0Constants.FLAG_REQUEST : 0) - | (msg.isSeataCodec() ? ProtocolV0Constants.FLAG_SEATA_CODEC : 0); + out.writeShort(ProtocolConstantsV0.MAGIC); + int flag = (msg.isAsync() ? ProtocolConstantsV0.FLAG_ASYNC : 0) + | (msg.isHeartbeat() ? ProtocolConstantsV0.FLAG_HEARTBEAT : 0) + | (msg.isRequest() ? ProtocolConstantsV0.FLAG_REQUEST : 0) + | (msg.isSeataCodec() ? ProtocolConstantsV0.FLAG_SEATA_CODEC : 0); out.writeShort((short) flag); diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java similarity index 97% rename from core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java rename to core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java index 9cb1af723d8..5d926b1f74c 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolV0RpcMessage.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java @@ -26,10 +26,10 @@ /** * the protocol v0 rpc message * - * @author minghua.xie + * @author Bughue * @date 2023/8/1 **/ -public class ProtocolV0RpcMessage implements ProtocolRpcMessage { +public class ProtocolRpcMessageV0 implements ProtocolRpcMessage { private static AtomicLong NEXT_ID = new AtomicLong(0); @@ -160,7 +160,6 @@ public void setMessageType(byte messageType) { public RpcMessage protocolMsg2RpcMsg(){ RpcMessage rpcMessage = new RpcMessage(); rpcMessage.setMessageType(this.messageType); - // todo 基础配置补充完整 rpcMessage.setCompressor(CompressorType.NONE.getCode()); byte codecType = this.isSeataCodec? SerializerType.SEATA.getCode():SerializerType.HESSIAN.getCode(); diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/SerializerV0.java b/core/src/main/java/io/seata/core/rpc/netty/v0/SerializerV0.java deleted file mode 100644 index 90246ff4fa8..00000000000 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/SerializerV0.java +++ /dev/null @@ -1,6 +0,0 @@ -package io.seata.core.rpc.netty.v0; - -public interface SerializerV0 { - - MessageCodecV0 getMsgInstanceByCode(short typeCode); -} diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolDecoderV1.java similarity index 95% rename from core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java rename to core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolDecoderV1.java index 9e06ed526a9..5a15df97a54 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Decoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolDecoderV1.java @@ -19,7 +19,6 @@ import io.seata.core.compressor.Compressor; import io.seata.core.compressor.CompressorFactory; import io.seata.core.protocol.HeartbeatMessage; -import io.seata.core.rpc.netty.CompatibleProtocolDecoder; import io.seata.core.protocol.ProtocolConstants; import io.seata.core.rpc.netty.ProtocolDecoder; import io.seata.core.rpc.netty.ProtocolRpcMessage; @@ -55,12 +54,12 @@ * https://github.com/seata/seata/issues/893 * * @author Geng Zhang - * @see ProtocolV1Encoder + * @see ProtocolEncoderV1 * @since 0.7.0 */ -public class ProtocolV1Decoder implements ProtocolDecoder { +public class ProtocolDecoderV1 implements ProtocolDecoder { - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV1Decoder.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolDecoderV1.class); @Override public ProtocolRpcMessage decodeFrame(ByteBuf frame) { @@ -80,7 +79,7 @@ public ProtocolRpcMessage decodeFrame(ByteBuf frame) { byte compressorType = frame.readByte(); int requestId = frame.readInt(); - ProtocolV1RpcMessage rpcMessage = new ProtocolV1RpcMessage(); + ProtocolRpcMessageV1 rpcMessage = new ProtocolRpcMessageV1(); rpcMessage.setCodec(codecType); rpcMessage.setId(requestId); rpcMessage.setCompressor(compressorType); diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolEncoderV1.java similarity index 96% rename from core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java rename to core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolEncoderV1.java index d91e08189e8..0710ddb58e1 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1Encoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolEncoderV1.java @@ -53,18 +53,18 @@ * https://github.com/seata/seata/issues/893 * * @author Geng Zhang - * @see ProtocolV1Decoder + * @see ProtocolDecoderV1 * @since 0.7.0 */ -public class ProtocolV1Encoder implements ProtocolEncoder { +public class ProtocolEncoderV1 implements ProtocolEncoder { - private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolV1Encoder.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolEncoderV1.class); public void encode(RpcMessage message, ByteBuf out) { try { - ProtocolV1RpcMessage rpcMessage = new ProtocolV1RpcMessage(); + ProtocolRpcMessageV1 rpcMessage = new ProtocolRpcMessageV1(); rpcMessage.rpcMsg2ProtocolMsg(message); int fullLength = ProtocolConstants.V1_HEAD_LENGTH; diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java similarity index 95% rename from core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java rename to core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java index ba2cbd8d5e1..639ee76de69 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolV1RpcMessage.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java @@ -16,7 +16,6 @@ package io.seata.core.rpc.netty.v1; import io.seata.common.util.StringUtils; -import io.seata.core.protocol.ProtocolConstants; import io.seata.core.protocol.RpcMessage; import io.seata.core.rpc.netty.ProtocolRpcMessage; @@ -26,10 +25,10 @@ /** * protocol v1 rpc message * - * @author minghua.xie + * @author Bughue * @date 2023/8/1 **/ -public class ProtocolV1RpcMessage implements ProtocolRpcMessage { +public class ProtocolRpcMessageV1 implements ProtocolRpcMessage { private int id; private byte messageType; @@ -183,7 +182,6 @@ public RpcMessage protocolMsg2RpcMsg(){ rpcMessage.setCompressor(this.compressor); rpcMessage.setHeadMap(this.headMap); rpcMessage.setBody(this.body); - rpcMessage.setProtocolVersion(ProtocolConstants.VERSION_1); return rpcMessage; } @@ -195,5 +193,6 @@ public void rpcMsg2ProtocolMsg(RpcMessage rpcMessage) { this.messageType = rpcMessage.getMessageType(); this.codec = rpcMessage.getCodec(); this.compressor = rpcMessage.getCompressor(); + rpcMessage.getVersion(); } } diff --git a/core/src/main/java/io/seata/core/rpc/processor/server/RegRmProcessor.java b/core/src/main/java/io/seata/core/rpc/processor/server/RegRmProcessor.java index 03b8af68f2e..1e4767387a2 100644 --- a/core/src/main/java/io/seata/core/rpc/processor/server/RegRmProcessor.java +++ b/core/src/main/java/io/seata/core/rpc/processor/server/RegRmProcessor.java @@ -64,7 +64,7 @@ private void onRegRmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) { String errorInfo = StringUtils.EMPTY; try { if (null == checkAuthHandler || checkAuthHandler.regResourceManagerCheckAuth(message)) { - ChannelManager.registerRMChannel(message, ctx.channel(), rpcMessage.getProtocolVersion()); + ChannelManager.registerRMChannel(message, ctx.channel()); Version.putChannelVersion(ctx.channel(), message.getVersion()); isSuccess = true; if (LOGGER.isDebugEnabled()) { diff --git a/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java b/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java index 985f7ac1cc4..1b7deb6f647 100644 --- a/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java +++ b/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java @@ -65,7 +65,7 @@ private void onRegTmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) { String errorInfo = StringUtils.EMPTY; try { if (null == checkAuthHandler || checkAuthHandler.regTransactionManagerCheckAuth(message)) { - ChannelManager.registerTMChannel(message, ctx.channel(), rpcMessage.getProtocolVersion()); + ChannelManager.registerTMChannel(message, ctx.channel(), rpcMessage.getVersion()); Version.putChannelVersion(ctx.channel(), message.getVersion()); isSuccess = true; if (LOGGER.isDebugEnabled()) { @@ -90,7 +90,7 @@ private void onRegTmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) { remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), response); if (isSuccess && LOGGER.isInfoEnabled()) { LOGGER.info("TM register success,message:{},channel:{},client version:{},client protocol-version:{}" - , message, ctx.channel(), message.getVersion(), rpcMessage.getProtocolVersion()); + , message, ctx.channel(), message.getVersion(), rpcMessage.getVersion()); } } diff --git a/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java b/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java index bca11d6b4c5..caa7e2bc630 100644 --- a/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java +++ b/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java @@ -39,7 +39,7 @@ private SerializerServiceLoader() { * @return the service of {@link Serializer} * @throws EnhancedServiceNotFoundException the enhanced service not found exception */ - public static Serializer load(SerializerType type, int version) throws EnhancedServiceNotFoundException { + public static Serializer load(SerializerType type, byte version) throws EnhancedServiceNotFoundException { if (type == SerializerType.PROTOBUF) { try { ReflectionUtil.getClassByName(PROTOBUF_SERIALIZER_CLASS_NAME); @@ -48,6 +48,10 @@ public static Serializer load(SerializerType type, int version) throws EnhancedS "Please manually reference 'io.seata:seata-serializer-protobuf' dependency ", e); } } - return EnhancedServiceLoader.load(Serializer.class, type.name(), version); + if (type == SerializerType.SEATA) { + return EnhancedServiceLoader.load(Serializer.class, type.name(), new Object[]{version}); + }else { + return EnhancedServiceLoader.load(Serializer.class, type.name()); + } } } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java index 8d7091aca5d..b3aa78a3164 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java @@ -1,51 +1,5 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package io.seata.serializer.seata; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -import io.seata.serializer.seata.protocol.v1.BatchResultMessageCodec; -import io.seata.serializer.seata.protocol.v1.MergeResultMessageCodec; -import io.seata.serializer.seata.protocol.v1.MergedWarpMessageCodec; -import io.seata.serializer.seata.protocol.v1.RegisterRMRequestCodec; -import io.seata.serializer.seata.protocol.v1.RegisterRMResponseCodec; -import io.seata.serializer.seata.protocol.v1.RegisterTMRequestCodec; -import io.seata.serializer.seata.protocol.v1.RegisterTMResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.BranchCommitRequestCodec; -import io.seata.serializer.seata.protocol.v1.transaction.BranchCommitResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.BranchRegisterRequestCodec; -import io.seata.serializer.seata.protocol.v1.transaction.BranchRegisterResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.BranchReportRequestCodec; -import io.seata.serializer.seata.protocol.v1.transaction.BranchReportResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.BranchRollbackRequestCodec; -import io.seata.serializer.seata.protocol.v1.transaction.BranchRollbackResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalBeginRequestCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalBeginResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalCommitRequestCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalCommitResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalLockQueryRequestCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalLockQueryResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalReportRequestCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalReportResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalRollbackRequestCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalRollbackResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalStatusRequestCodec; -import io.seata.serializer.seata.protocol.v1.transaction.GlobalStatusResponseCodec; -import io.seata.serializer.seata.protocol.v1.transaction.UndoLogDeleteRequestCodec; import io.seata.core.protocol.AbstractMessage; import io.seata.core.protocol.BatchResultMessage; import io.seata.core.protocol.MergeResultMessage; @@ -77,17 +31,10 @@ import io.seata.core.protocol.transaction.GlobalStatusResponse; import io.seata.core.protocol.transaction.UndoLogDeleteRequest; -/** - * The type Message codec factory. - * - * @author zhangsen - */ -public class MessageCodecFactory { -// todo [5738-discuss][codec] 这个工厂类的大部分职责都被我改成serialize父类的map了,剩下的merge和batch看如何处理? - /** - * The constant UTF8. - */ - protected static final Charset UTF8 = StandardCharsets.UTF_8; +public abstract class MessageCodecFactory { + + public abstract MessageSeataCodec getMessageCodec(short typeCode); + /** * Get message codec message codec. @@ -95,142 +42,17 @@ public class MessageCodecFactory { * @param abstractMessage the abstract message * @return the message codec */ - public static MessageSeataCodec getMessageCodec(AbstractMessage abstractMessage) { + public MessageSeataCodec getMessageCodec(AbstractMessage abstractMessage) { return getMessageCodec(abstractMessage.getTypeCode()); } - /** - * Gets msg instance by code. - * - * @param typeCode the type code - * @return the msg instance by code - */ - public static MessageSeataCodec getMessageCodec(short typeCode) { - MessageSeataCodec msgCodec = null; - switch (typeCode) { - case MessageType.TYPE_SEATA_MERGE: - msgCodec = new MergedWarpMessageCodec(); - break; - case MessageType.TYPE_SEATA_MERGE_RESULT: - msgCodec = new MergeResultMessageCodec(); - break; - case MessageType.TYPE_REG_CLT: - msgCodec = new RegisterTMRequestCodec(); - break; - case MessageType.TYPE_REG_CLT_RESULT: - msgCodec = new RegisterTMResponseCodec(); - break; - case MessageType.TYPE_REG_RM: - msgCodec = new RegisterRMRequestCodec(); - break; - case MessageType.TYPE_REG_RM_RESULT: - msgCodec = new RegisterRMResponseCodec(); - break; - case MessageType.TYPE_BRANCH_COMMIT: - msgCodec = new BranchCommitRequestCodec(); - break; - case MessageType.TYPE_BRANCH_ROLLBACK: - msgCodec = new BranchRollbackRequestCodec(); - break; - case MessageType.TYPE_GLOBAL_REPORT: - msgCodec = new GlobalReportRequestCodec(); - break; - case MessageType.TYPE_BATCH_RESULT_MSG: - msgCodec = new BatchResultMessageCodec(); - break; - default: - break; - } - - if (msgCodec != null) { - return msgCodec; - } - - try { - msgCodec = getMergeRequestMessageSeataCodec(typeCode); - } catch (Exception exx) { - } - - if (msgCodec != null) { - return msgCodec; - } - - msgCodec = getMergeResponseMessageSeataCodec(typeCode); - - return msgCodec; - } - - /** - * Gets merge request instance by code. - * - * @param typeCode the type code - * @return the merge request instance by code - */ - protected static MessageSeataCodec getMergeRequestMessageSeataCodec(int typeCode) { - switch (typeCode) { - case MessageType.TYPE_GLOBAL_BEGIN: - return new GlobalBeginRequestCodec(); - case MessageType.TYPE_GLOBAL_COMMIT: - return new GlobalCommitRequestCodec(); - case MessageType.TYPE_GLOBAL_ROLLBACK: - return new GlobalRollbackRequestCodec(); - case MessageType.TYPE_GLOBAL_STATUS: - return new GlobalStatusRequestCodec(); - case MessageType.TYPE_GLOBAL_LOCK_QUERY: - return new GlobalLockQueryRequestCodec(); - case MessageType.TYPE_BRANCH_REGISTER: - return new BranchRegisterRequestCodec(); - case MessageType.TYPE_BRANCH_STATUS_REPORT: - return new BranchReportRequestCodec(); - case MessageType.TYPE_GLOBAL_REPORT: - return new GlobalReportRequestCodec(); - default: - throw new IllegalArgumentException("not support typeCode," + typeCode); - } - } - - /** - * Gets merge response instance by code. - * - * @param typeCode the type code - * @return the merge response instance by code - */ - protected static MessageSeataCodec getMergeResponseMessageSeataCodec(int typeCode) { - switch (typeCode) { - case MessageType.TYPE_GLOBAL_BEGIN_RESULT: - return new GlobalBeginResponseCodec(); - case MessageType.TYPE_GLOBAL_COMMIT_RESULT: - return new GlobalCommitResponseCodec(); - case MessageType.TYPE_GLOBAL_ROLLBACK_RESULT: - return new GlobalRollbackResponseCodec(); - case MessageType.TYPE_GLOBAL_STATUS_RESULT: - return new GlobalStatusResponseCodec(); - case MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT: - return new GlobalLockQueryResponseCodec(); - case MessageType.TYPE_BRANCH_REGISTER_RESULT: - return new BranchRegisterResponseCodec(); - case MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT: - return new BranchReportResponseCodec(); - case MessageType.TYPE_BRANCH_COMMIT_RESULT: - return new BranchCommitResponseCodec(); - case MessageType.TYPE_BRANCH_ROLLBACK_RESULT: - return new BranchRollbackResponseCodec(); - case MessageType.TYPE_RM_DELETE_UNDOLOG: - return new UndoLogDeleteRequestCodec(); - case MessageType.TYPE_GLOBAL_REPORT_RESULT: - return new GlobalReportResponseCodec(); - default: - throw new IllegalArgumentException("not support typeCode," + typeCode); - } - } - /** * Gets message. * * @param typeCode the type code * @return the message */ - public static AbstractMessage getMessage(short typeCode) { + public AbstractMessage getMessage(short typeCode) { AbstractMessage abstractMessage = null; switch (typeCode) { case MessageType.TYPE_SEATA_MERGE: @@ -350,5 +172,4 @@ protected static AbstractMessage getMergeResponseInstanceByCode(int typeCode) { throw new IllegalArgumentException("not support typeCode," + typeCode); } } - } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java deleted file mode 100644 index 9c590ea0bf4..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataAbstractSerializer.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata; - -import com.sun.tools.javac.util.Pair; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.seata.core.protocol.AbstractMessage; -import io.seata.core.serializer.Serializer; - -import java.nio.ByteBuffer; -import java.util.HashMap; -import java.util.Map; - -/** - * The Seata codec. - * - * @author zhangsen - */ -public abstract class SeataAbstractSerializer implements Serializer { - - protected Map,Class>> classMap = new HashMap(); - - public Class getCodecClass(short typeCode){ - Pair, Class> pair = classMap.get(typeCode); - if(pair !=null && pair.fst !=null){ - return pair.fst; - }else { - return null; - } - } - - public Class getMessageClass(short typeCode){ - Pair, Class> pair = classMap.get(typeCode); - if(pair !=null && pair.snd !=null){ - return pair.snd; - }else { - return null; - } - } - - @Override - public byte[] serialize(T t) { - if (t == null || !(t instanceof AbstractMessage)) { - throw new IllegalArgumentException("AbstractMessage isn't available."); - } - AbstractMessage abstractMessage = (AbstractMessage)t; - //typecode - short typecode = abstractMessage.getTypeCode(); - //msg codec - MessageSeataCodec messageCodec = getCodecByType(typecode); - //get empty ByteBuffer - ByteBuf out = Unpooled.buffer(1024); - //msg encode - messageCodec.encode(t, out); - byte[] body = new byte[out.readableBytes()]; - out.readBytes(body); - - //typecode + body - ByteBuffer byteBuffer = ByteBuffer.allocate(2 + body.length); - byteBuffer.putShort(typecode); - byteBuffer.put(body); - - byteBuffer.flip(); - byte[] content = new byte[byteBuffer.limit()]; - byteBuffer.get(content); - return content; - } - - @Override - public T deserialize(byte[] bytes) { - if (bytes == null || bytes.length == 0) { - throw new IllegalArgumentException("Nothing to decode."); - } - if (bytes.length < 2) { - throw new IllegalArgumentException("The byte[] isn't available for decode."); - } - ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); - //typecode - short typecode = byteBuffer.getShort(); - //msg body - byte[] body = new byte[byteBuffer.remaining()]; - byteBuffer.get(body); - ByteBuffer in = ByteBuffer.wrap(body); - //new Messgae - AbstractMessage abstractMessage = getMessageByType(typecode); - //get messageCodec - MessageSeataCodec messageCodec = getCodecByType(typecode); - //decode - messageCodec.decode(abstractMessage, in); - return (T)abstractMessage; - } - - protected AbstractMessage getMessageByType(short typecode) { - try { - return getMessageClass(typecode).newInstance(); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - protected MessageSeataCodec getCodecByType(short typecode) { - try { - return getCodecClass(typecode).newInstance(); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java new file mode 100644 index 00000000000..46b6e3f2e00 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java @@ -0,0 +1,145 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata; + +import com.google.common.collect.ImmutableMap; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.seata.common.loader.LoadLevel; +import io.seata.core.protocol.AbstractMessage; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.serializer.Serializer; +import io.seata.serializer.seata.protocol.v1.MessageCodecFactoryV1; + +import java.nio.ByteBuffer; +import java.util.Map; + +/** + * The Seata codec. + * + * @author zhangsen + */ +@LoadLevel(name = "SEATA") +public class SeataSerializer implements Serializer { + + MessageCodecFactory factory; + byte protocolVersion ; + static Map FACTORY_MAP = ImmutableMap.builder() +// .put(ProtocolConstants.VERSION_0, new ?()) + .put(ProtocolConstants.VERSION_1, new MessageCodecFactoryV1()) + .build(); + + public SeataSerializer(byte version){ + factory = FACTORY_MAP.get(version); + protocolVersion = version; + } + + @Override + public byte[] serialize(T t) { + if (t == null || !(t instanceof AbstractMessage)) { + throw new IllegalArgumentException("AbstractMessage isn't available."); + } + AbstractMessage abstractMessage = (AbstractMessage)t; + //typecode + short typecode = abstractMessage.getTypeCode(); + //msg codec + MessageSeataCodec messageCodec = factory.getMessageCodec(typecode); + //get empty ByteBuffer + ByteBuf out = Unpooled.buffer(1024); + //msg encode + messageCodec.encode(t, out); + byte[] body = new byte[out.readableBytes()]; + out.readBytes(body); + + ByteBuffer byteBuffer; + if (protocolVersion == ProtocolConstants.VERSION_0) { + byteBuffer = ByteBuffer.allocate(body.length); + } else { + //typecode + body + byteBuffer = ByteBuffer.allocate(2 + body.length); + byteBuffer.putShort(typecode); + } + byteBuffer.put(body); + + byteBuffer.flip(); + byte[] content = new byte[byteBuffer.limit()]; + byteBuffer.get(content); + return content; + } + + @Override + public T deserialize(byte[] bytes) { + if (bytes == null || bytes.length == 0) { + throw new IllegalArgumentException("Nothing to decode."); + } + if (bytes.length < 2) { + throw new IllegalArgumentException("The byte[] isn't available for decode."); + } + ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); + //typecode + short typecode = byteBuffer.getShort(); + //msg body + byte[] body = new byte[byteBuffer.remaining()]; + byteBuffer.get(body); + ByteBuffer in = ByteBuffer.wrap(body); + //new Messgae + AbstractMessage abstractMessage = factory.getMessage(typecode); + //get messageCodec + MessageSeataCodec messageCodec = factory.getMessageCodec(typecode); + //decode + messageCodec.decode(abstractMessage, in); + return (T)abstractMessage; + } + +// public Class getCodecClass(short typeCode){ +// Pair, Class> pair = classMap.get(typeCode); +// if(pair !=null && pair.fst !=null){ +// return pair.fst; +// }else { +// return null; +// } +// } +// +// public Class getMessageClass(short typeCode){ +// Pair, Class> pair = classMap.get(typeCode); +// if(pair !=null && pair.snd !=null){ +// return pair.snd; +// }else { +// return null; +// } +// } + +// protected AbstractMessage getMessageByType(short typecode) { +// try { +// return getMessageClass(typecode).newInstance(); +// } catch (InstantiationException e) { +// throw new RuntimeException(e); +// } catch (IllegalAccessException e) { +// throw new RuntimeException(e); +// } +// } +// +// protected MessageSeataCodec getCodecByType(short typecode) { +// try { +// return getCodecClass(typecode).newInstance(); +// } catch (InstantiationException e) { +// throw new RuntimeException(e); +// } catch (IllegalAccessException e) { +// throw new RuntimeException(e); +// } +// } + +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java deleted file mode 100644 index 1fe8b5dd0ee..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyRequestCodec.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0; - -import io.netty.buffer.ByteBuf; -import io.seata.core.protocol.AbstractIdentifyRequest; - -import java.nio.ByteBuffer; - -/** - * The type Abstract identify request codec. - */ -public abstract class AbstractIdentifyRequestCodec extends AbstractMessageCodec { - // todo [5738-discuss][codec] 像这种父类如果是这次的新旧版本都一样,要写成继承吗 - // todo [5738-discuss][codec] 这些codec类只依靠包区分是否足够? - - @Override - public Class getMessageClassType() { - return AbstractIdentifyRequest.class; - } - - /** - * Do encode. - * - * @param the type parameter - * @param t the t - * @param out the out - */ - protected void doEncode(T t, ByteBuf out) { - AbstractIdentifyRequest abstractIdentifyRequest = (AbstractIdentifyRequest)t; - String version = abstractIdentifyRequest.getVersion(); - String applicationId = abstractIdentifyRequest.getApplicationId(); - String transactionServiceGroup = abstractIdentifyRequest.getTransactionServiceGroup(); - String extraData = abstractIdentifyRequest.getExtraData(); - - if (version != null) { - byte[] bs = version.getBytes(UTF8); - out.writeShort((short)bs.length); - if (bs.length > 0) { - out.writeBytes(bs); - } - } else { - out.writeShort((short)0); - } - - if (applicationId != null) { - byte[] bs = applicationId.getBytes(UTF8); - out.writeShort((short)bs.length); - if (bs.length > 0) { - out.writeBytes(bs); - } - } else { - out.writeShort((short)0); - } - - if (transactionServiceGroup != null) { - byte[] bs = transactionServiceGroup.getBytes(UTF8); - out.writeShort((short)bs.length); - if (bs.length > 0) { - out.writeBytes(bs); - } - } else { - out.writeShort((short)0); - } - - if (extraData != null) { - byte[] bs = extraData.getBytes(UTF8); - out.writeShort((short)bs.length); - if (bs.length > 0) { - out.writeBytes(bs); - } - } else { - out.writeShort((short)0); - } - - } - - @Override - public void encode(T t, ByteBuf out) { - doEncode(t, out); - } - - @Override - public void decode(T t, ByteBuffer in) { - AbstractIdentifyRequest abstractIdentifyRequest = (AbstractIdentifyRequest)t; - - //version len - short len = 0; - if (in.remaining() < 2) { - return; - } - len = in.getShort(); - //version - if (in.remaining() < len) { - return; - } - byte[] bs = new byte[len]; - in.get(bs); - abstractIdentifyRequest.setVersion(new String(bs, UTF8)); - - //applicationId len - if (in.remaining() < 2) { - return; - } - len = in.getShort(); - //applicationId - if (in.remaining() < len) { - return; - } - bs = new byte[len]; - in.get(bs); - abstractIdentifyRequest.setApplicationId(new String(bs, UTF8)); - - //transactionServiceGroup len - if (in.remaining() < 2) { - return; - } - len = in.getShort(); - - //transactionServiceGroup - if (in.remaining() < len) { - return; - } - bs = new byte[len]; - in.get(bs); - abstractIdentifyRequest.setTransactionServiceGroup(new String(bs, UTF8)); - - //ExtraData len - if (in.remaining() < 2) { - return; - } - len = in.getShort(); - - if (in.remaining() >= len) { - bs = new byte[len]; - in.get(bs); - abstractIdentifyRequest.setExtraData(new String(bs, UTF8)); - } else { - //maybe null - } - } - -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponseCodec.java deleted file mode 100644 index aa64e57b88f..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractIdentifyResponseCodec.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0; - -import io.netty.buffer.ByteBuf; -import io.seata.core.protocol.AbstractIdentifyResponse; - -import java.nio.ByteBuffer; - -/** - * The type Abstract identify response. - * - * @author sharajava - */ -public abstract class AbstractIdentifyResponseCodec extends AbstractResultMessageCodec { - - @Override - public Class getMessageClassType() { - return AbstractIdentifyResponse.class; - } - - @Override - public void encode(T t, ByteBuf out) { - AbstractIdentifyResponse abstractIdentifyResponse = (AbstractIdentifyResponse)t; - boolean identified = abstractIdentifyResponse.isIdentified(); - String version = abstractIdentifyResponse.getVersion(); - - out.writeByte(identified ? (byte)1 : (byte)0); - if (version != null) { - byte[] bs = version.getBytes(UTF8); - out.writeShort((short)bs.length); - if (bs.length > 0) { - out.writeBytes(bs); - } - } else { - out.writeShort((short)0); - } - } - - @Override - public void decode(T t, ByteBuffer in) { - AbstractIdentifyResponse abstractIdentifyResponse = (AbstractIdentifyResponse)t; - - abstractIdentifyResponse.setIdentified(in.get() == 1); - short len = in.getShort(); - if (len <= 0) { - return; - } - if (in.remaining() < len) { - return; - } - byte[] bs = new byte[len]; - in.get(bs); - abstractIdentifyResponse.setVersion(new String(bs, UTF8)); - } - -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageCodec.java deleted file mode 100644 index 68d93d95efc..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractMessageCodec.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0; - -import io.seata.serializer.seata.MessageSeataCodec; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -/** - * The type Abstract message codec. - * - * @author zhangsen - */ -public abstract class AbstractMessageCodec implements MessageSeataCodec { - - /** - * The constant LOGGER. - */ - protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractMessageCodec.class); - - /** - * The constant UTF8. - */ - protected static final Charset UTF8 = StandardCharsets.UTF_8; - - /** - * Bytes to int int. - * - * @param bytes the bytes - * @param offset the offset - * @return the int - */ - public static int bytesToInt(byte[] bytes, int offset) { - int ret = 0; - for (int i = 0; i < 4 && i + offset < bytes.length; i++) { - ret <<= 8; - ret |= (int)bytes[i + offset] & 0xFF; - } - return ret; - } - - /** - * Int to bytes. - * - * @param i the - * @param bytes the bytes - * @param offset the offset - */ - public static void intToBytes(int i, byte[] bytes, int offset) { - bytes[offset] = (byte)((i >> 24) & 0xFF); - bytes[offset + 1] = (byte)((i >> 16) & 0xFF); - bytes[offset + 2] = (byte)((i >> 8) & 0xFF); - bytes[offset + 3] = (byte)(i & 0xFF); - } - -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageCodec.java deleted file mode 100644 index ef36305a90e..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/AbstractResultMessageCodec.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0; - -import io.netty.buffer.ByteBuf; -import io.seata.common.util.StringUtils; -import io.seata.core.protocol.AbstractResultMessage; -import io.seata.core.protocol.ResultCode; - -import java.nio.ByteBuffer; - -/** - * The type Abstract result message codec. - * - * @author zhangsen - */ -public abstract class AbstractResultMessageCodec extends AbstractMessageCodec { - - @Override - public Class getMessageClassType() { - return AbstractResultMessage.class; - } - - @Override - public void encode(T t, ByteBuf out) { - AbstractResultMessage abstractResultMessage = (AbstractResultMessage)t; - ResultCode resultCode = abstractResultMessage.getResultCode(); - String resultMsg = abstractResultMessage.getMsg(); - - out.writeByte(resultCode.ordinal()); - if (resultCode == ResultCode.Failed) { - if (StringUtils.isNotEmpty(resultMsg)) { - String msg; - if (resultMsg.length() > Short.MAX_VALUE) { - msg = resultMsg.substring(0, Short.MAX_VALUE); - } else { - msg = resultMsg; - } - byte[] bs = msg.getBytes(UTF8); - out.writeShort((short)bs.length); - out.writeBytes(bs); - } else { - out.writeShort((short)0); - } - } - } - - @Override - public void decode(T t, ByteBuffer in) { - AbstractResultMessage abstractResultMessage = (AbstractResultMessage)t; - - ResultCode resultCode = ResultCode.get(in.get()); - abstractResultMessage.setResultCode(resultCode); - if (resultCode == ResultCode.Failed) { - short len = in.getShort(); - if (len > 0) { - byte[] msg = new byte[len]; - in.get(msg); - abstractResultMessage.setMsg(new String(msg, UTF8)); - } - } - } - -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/BatchResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/BatchResultMessageCodec.java new file mode 100644 index 00000000000..a530d4b4e68 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/BatchResultMessageCodec.java @@ -0,0 +1,13 @@ +package io.seata.serializer.seata.protocol.v0; + +/** + * ? + * + * @author Bughue + * @date 2023/9/21 + **/ +public class BatchResultMessageCodec extends io.seata.serializer.seata.protocol.v1.BatchResultMessageCodec { + public BatchResultMessageCodec(){ + this.factory = new MessageCodecFactoryV0(); + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergeResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergeResultMessageCodec.java new file mode 100644 index 00000000000..00b88110223 --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergeResultMessageCodec.java @@ -0,0 +1,13 @@ +package io.seata.serializer.seata.protocol.v0; + +/** + * ? + * + * @author Bughue + * @date 2023/9/21 + **/ +public class MergeResultMessageCodec extends io.seata.serializer.seata.protocol.v1.MergeResultMessageCodec { + public MergeResultMessageCodec(){ + this.factory = new MessageCodecFactoryV0(); + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedWarpMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedWarpMessageCodec.java new file mode 100644 index 00000000000..1a3b6600cbd --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedWarpMessageCodec.java @@ -0,0 +1,13 @@ +package io.seata.serializer.seata.protocol.v0; + +/** + * ? + * + * @author Bughue + * @date 2023/9/21 + **/ +public class MergedWarpMessageCodec extends io.seata.serializer.seata.protocol.v1.MergedWarpMessageCodec { + public MergedWarpMessageCodec(){ + this.factory = new MessageCodecFactoryV0(); + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MessageCodecFactoryV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MessageCodecFactoryV0.java new file mode 100644 index 00000000000..0205c91820d --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MessageCodecFactoryV0.java @@ -0,0 +1,54 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v0; + +import io.seata.core.protocol.AbstractMessage; +import io.seata.core.protocol.MergeResultMessage; +import io.seata.core.protocol.MergedWarpMessage; +import io.seata.core.protocol.MessageType; +import io.seata.serializer.seata.MessageSeataCodec; +import io.seata.serializer.seata.protocol.v1.MessageCodecFactoryV1; + +/** + * The type Message codec factory v0. + * + * @author Bughue + */ +public class MessageCodecFactoryV0 extends MessageCodecFactoryV1 { + + public MessageSeataCodec getMessageCodec(short typeCode) { + MessageSeataCodec msgCodec = null; + switch (typeCode) { + case MessageType.TYPE_SEATA_MERGE: + msgCodec = new MergedWarpMessageCodec(); + break; + case MessageType.TYPE_SEATA_MERGE_RESULT: + msgCodec = new MergeResultMessageCodec(); + break; + case MessageType.TYPE_BATCH_RESULT_MSG: + msgCodec = new BatchResultMessageCodec(); + break; + default: + break; + } + + if (msgCodec != null) { + return msgCodec; + } + + return super.getMessageCodec(typeCode); + } +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java deleted file mode 100644 index d071572f301..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMRequestCodec.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0; - - -import io.seata.core.protocol.RegisterTMRequest; - -/** - * The type Register tm request codec. - * - * @author zhangsen - */ -public class RegisterTMRequestCodec extends AbstractIdentifyRequestCodec { - @Override - public Class getMessageClassType() { - return RegisterTMRequest.class; - } - -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java deleted file mode 100644 index 456786132d4..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/RegisterTMResponseCodec.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0; - - -import io.seata.core.protocol.RegisterTMResponse; - -/** - * The type Register tm response codec. - * - * @author zhangsen - */ -public class RegisterTMResponseCodec extends AbstractIdentifyResponseCodec { - @Override - public Class getMessageClassType() { - return RegisterTMResponse.class; - } - -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java deleted file mode 100644 index 8bb8f0b9018..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/SeataV0Serializer.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0; - -import com.sun.tools.javac.util.Pair; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.seata.common.loader.LoadLevel; -import io.seata.core.protocol.AbstractMessage; -import io.seata.core.protocol.MessageType; -import io.seata.core.protocol.ProtocolConstants; -import io.seata.core.protocol.RegisterTMRequest; -import io.seata.core.protocol.RegisterTMResponse; -import io.seata.serializer.seata.MessageSeataCodec; -import io.seata.serializer.seata.SeataAbstractSerializer; - -import java.nio.ByteBuffer; - -/** - * The Seata codec v0. - * - * @author Bughue - */ -@LoadLevel(name = "SEATA", version = ProtocolConstants.VERSION_0) -public class SeataV0Serializer extends SeataAbstractSerializer { - - public SeataV0Serializer() { - classMap.put(MessageType.TYPE_REG_CLT, new Pair<>(RegisterTMRequestCodec.class, RegisterTMRequest.class)); - classMap.put(MessageType.TYPE_REG_CLT_RESULT, new Pair<>(RegisterTMResponseCodec.class, RegisterTMResponse.class)); -// classMap.put(MessageType.TYPE_REG_RM, new Pair<>(RegisterRMRequestCodec.class, RegisterRMRequest.class)); -// classMap.put(MessageType.TYPE_REG_RM_RESULT, new Pair<>(RegisterRMResponseCodec.class, RegisterRMResponse.class)); - - } - - @Override - public byte[] serialize(T t) { - if (t == null || !(t instanceof AbstractMessage)) { - throw new IllegalArgumentException("AbstractMessage isn't available."); - } - AbstractMessage abstractMessage = (AbstractMessage)t; - //typecode - short typecode = abstractMessage.getTypeCode(); - //msg codec - MessageSeataCodec messageCodec = getCodecByType(typecode); - //get empty ByteBuffer - ByteBuf out = Unpooled.buffer(1024); - //msg encode - messageCodec.encode(t, out); - byte[] body = new byte[out.readableBytes()]; - out.readBytes(body); - - //typecode + body - ByteBuffer byteBuffer = ByteBuffer.allocate(body.length); - byteBuffer.put(body); - - byteBuffer.flip(); - byte[] content = new byte[byteBuffer.limit()]; - byteBuffer.get(content); - return content; - } - - @Override - public T deserialize(byte[] bytes) { - if (bytes == null || bytes.length == 0) { - throw new IllegalArgumentException("Nothing to decode."); - } - if (bytes.length < 2) { - throw new IllegalArgumentException("The byte[] isn't available for decode."); - } - ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); - //typecode - short typecode = byteBuffer.getShort(); - //msg body - byte[] body = new byte[byteBuffer.remaining()]; - byteBuffer.get(body); - ByteBuffer in = ByteBuffer.wrap(body); - //new Messgae - AbstractMessage abstractMessage = getMessageByType(typecode); - //get messageCodec - MessageSeataCodec messageCodec = getCodecByType(typecode); - //decode - messageCodec.decode(abstractMessage, in); - return (T)abstractMessage; - } - - -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyRequestV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyRequestV0.java deleted file mode 100644 index 8865cdb58a3..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyRequestV0.java +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0_1; - -import io.netty.buffer.ByteBuf; -import io.seata.core.protocol.AbstractIdentifyRequest; -import io.seata.core.protocol.Version; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.nio.ByteBuffer; - -/** - * The type Abstract identify request. - * - * @author sharajava - */ -public abstract class AbstractIdentifyRequestV0 extends AbstractMessageV0 { - - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractIdentifyRequestV0.class); - - /** - * The Version. - */ - protected String version = Version.getCurrent(); - - /** - * The Application id. - */ - protected String applicationId; - - /** - * The Transaction service group. - */ - protected String transactionServiceGroup; - - /** - * The Extra data. - */ - protected String extraData; - - /** - * Instantiates a new Abstract identify request. - * - * @param applicationId the application id - * @param transactionServiceGroup the transaction service group - */ - public AbstractIdentifyRequestV0(String applicationId, String transactionServiceGroup) { - this.applicationId = applicationId; - this.transactionServiceGroup = transactionServiceGroup; - } - - /** - * Instantiates a new Abstract identify request. - * - * @param applicationId the application id - * @param transactionServiceGroup the transaction service group - * @param extraData the extra data - */ - public AbstractIdentifyRequestV0(String applicationId, String transactionServiceGroup, String extraData) { - this.applicationId = applicationId; - this.transactionServiceGroup = transactionServiceGroup; - this.extraData = extraData; - } - - /** - * Gets version. - * - * @return the version - */ - public String getVersion() { - return version; - } - - /** - * Sets version. - * - * @param version the version - */ - public void setVersion(String version) { - this.version = version; - } - - /** - * Gets application id. - * - * @return the application id - */ - public String getApplicationId() { - return applicationId; - } - - /** - * Sets application id. - * - * @param applicationId the application id - */ - public void setApplicationId(String applicationId) { - this.applicationId = applicationId; - } - - /** - * Gets transaction service group. - * - * @return the transaction service group - */ - public String getTransactionServiceGroup() { - return transactionServiceGroup; - } - - /** - * Sets transaction service group. - * - * @param transactionServiceGroup the transaction service group - */ - public void setTransactionServiceGroup(String transactionServiceGroup) { - this.transactionServiceGroup = transactionServiceGroup; - } - - /** - * Gets extra data. - * - * @return the extra data - */ - public String getExtraData() { - return extraData; - } - - /** - * Sets extra data. - * - * @param extraData the extra data - */ - public void setExtraData(String extraData) { - this.extraData = extraData; - } - - /** - * The Byte buffer. - */ - public ByteBuffer byteBuffer = ByteBuffer.allocate(10 * 1024); - - /** - * Do encode. - */ - protected void doEncode() { - byteBuffer.clear(); - if (this.version != null) { - byte[] bs = version.getBytes(UTF8); - byteBuffer.putShort((short)bs.length); - if (bs.length > 0) { - byteBuffer.put(bs); - } - } else { - byteBuffer.putShort((short)0); - } - - if (this.applicationId != null) { - byte[] bs = applicationId.getBytes(UTF8); - byteBuffer.putShort((short)bs.length); - if (bs.length > 0) { - byteBuffer.put(bs); - } - } else { - byteBuffer.putShort((short)0); - } - - if (this.transactionServiceGroup != null) { - byte[] bs = transactionServiceGroup.getBytes(UTF8); - byteBuffer.putShort((short)bs.length); - if (bs.length > 0) { - byteBuffer.put(bs); - } - } else { - byteBuffer.putShort((short)0); - } - - if (this.extraData != null) { - byte[] bs = extraData.getBytes(UTF8); - byteBuffer.putShort((short)bs.length); - if (bs.length > 0) { - byteBuffer.put(bs); - } - } else { - byteBuffer.putShort((short)0); - } - - } - - private final byte[] flushEncode() { - byteBuffer.flip(); - byte[] content = new byte[byteBuffer.limit()]; - byteBuffer.get(content); - byteBuffer.clear(); // >? - return content; - } - - @Override - public final byte[] encode() { - doEncode(); - return flushEncode(); - } - -// @Override - public boolean decode(ByteBuf in) { - - short len; - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (in.readableBytes() < len) { - return false; - } - byte[] bs = new byte[len]; - in.readBytes(bs); - this.setVersion(new String(bs, UTF8)); - - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (in.readableBytes() < len) { - return false; - } - bs = new byte[len]; - in.readBytes(bs); - this.setApplicationId(new String(bs, UTF8)); - - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (in.readableBytes() < len) { - return false; - } - bs = new byte[len]; - in.readBytes(bs); - this.setTransactionServiceGroup(new String(bs, UTF8)); - - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (in.readableBytes() >= len) { - bs = new byte[len]; - in.readBytes(bs); - this.setExtraData(new String(bs, UTF8)); - } else { - //maybe null - } - - return true; - } - - @Override - public boolean decode(ByteBuf in,AbstractIdentifyRequest req) { - - - short len; - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (in.readableBytes() < len) { - return false; - } - byte[] bs = new byte[len]; - in.readBytes(bs); - req.setVersion(new String(bs, UTF8)); - - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (in.readableBytes() < len) { - return false; - } - bs = new byte[len]; - in.readBytes(bs); - req.setApplicationId(new String(bs, UTF8)); - - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (in.readableBytes() < len) { - return false; - } - bs = new byte[len]; - in.readBytes(bs); - req.setTransactionServiceGroup(new String(bs, UTF8)); - - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (in.readableBytes() >= len) { - bs = new byte[len]; - in.readBytes(bs); - req.setExtraData(new String(bs, UTF8)); - } else { - //maybe null - } - - return true; - } -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyResponseV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyResponseV0.java deleted file mode 100644 index e90a3f6bac6..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractIdentifyResponseV0.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0_1; - -import io.netty.buffer.ByteBuf; -import io.seata.core.protocol.Version; - -/** - * The type Abstract identify response. - * - * @author sharajava - */ -public abstract class AbstractIdentifyResponseV0 extends AbstractResultMessageV0 { - - protected String version = Version.getCurrent(); - - private String extraData; - - private boolean identified; - - /** - * Gets version. - * - * @return the version - */ - public String getVersion() { - return version; - } - - /** - * Sets version. - * - * @param version the version - */ - public void setVersion(String version) { - this.version = version; - } - - /** - * Gets extra data. - * - * @return the extra data - */ - public String getExtraData() { - return extraData; - } - - /** - * Sets extra data. - * - * @param extraData the extra data - */ - public void setExtraData(String extraData) { - this.extraData = extraData; - } - - /** - * Is identified boolean. - * - * @return the boolean - */ - public boolean isIdentified() { - return identified; - } - - /** - * Sets identified. - * - * @param identified the identified - */ - public void setIdentified(boolean identified) { - this.identified = identified; - } - - @Override - public void doEncode() { - // super.doEncode(); - byteBuffer.put(this.identified ? (byte)1 : (byte)0); - if (this.version != null) { - byte[] bs = version.getBytes(UTF8); - byteBuffer.putShort((short)bs.length); - if (bs.length > 0) { - byteBuffer.put(bs); - } - } else { - byteBuffer.putShort((short)0); - } - - } - - @Override - public boolean decode(ByteBuf in) { - if (in.readableBytes() < 3) { - return false; - } - this.identified = in.readByte() == 1; - short len = in.readShort(); - if (len <= 0) { - return false; - } - if (in.readableBytes() < len) { - return false; - } - byte[] bs = new byte[len]; - in.readBytes(bs); - this.setVersion(new String(bs, UTF8)); - return true; - - } - - @Override - public String toString() { - StringBuilder result = new StringBuilder(); - result.append("version="); - result.append(version); - result.append(","); - result.append("extraData="); - result.append(extraData); - result.append(","); - result.append("identified="); - result.append(identified); - result.append(","); - result.append("resultCode="); - result.append(getResultCode()); - result.append(","); - result.append("msg="); - result.append(getMsg()); - - return result.toString(); - } -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractMessageV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractMessageV0.java deleted file mode 100644 index 4d4d9627140..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractMessageV0.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0_1; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.seata.common.Constants; -import io.seata.core.protocol.AbstractIdentifyRequest; -import io.seata.core.protocol.AbstractMessage; -import io.seata.core.rpc.netty.v0.MessageCodecV0; - -import java.io.Serializable; -import java.nio.charset.Charset; - -/** - * The type Abstract message. - * - * @author jimin.jm @alibaba-inc.com - * @date 2018 /9/14 - */ -public abstract class AbstractMessageV0 implements MessageCodecV0, Serializable { - private static final long serialVersionUID = -1441020418526899889L; - - /** - * The constant UTF8. - */ - protected static final Charset UTF8 = Constants.DEFAULT_CHARSET; - /** - * The Ctx. - */ - protected ChannelHandlerContext ctx; - - /** - * Bytes to int int. - * - * @param bytes the bytes - * @param offset the offset - * @return the int - */ - public static int bytesToInt(byte[] bytes, int offset) { - int ret = 0; - for (int i = 0; i < 4 && i + offset < bytes.length; i++) { - ret <<= 8; - ret |= (int)bytes[i + offset] & 0xFF; - } - return ret; - } - - /** - * Int to bytes. - * - * @param i the - * @param bytes the bytes - * @param offset the offset - */ - public static void intToBytes(int i, byte[] bytes, int offset) { - bytes[offset] = (byte)((i >> 24) & 0xFF); - bytes[offset + 1] = (byte)((i >> 16) & 0xFF); - bytes[offset + 2] = (byte)((i >> 8) & 0xFF); - bytes[offset + 3] = (byte)(i & 0xFF); - } - - @Override - public boolean decode(ByteBuf in, T req){ - return false; - } - - /** - * Gets msg instance by code. - * - * @param typeCode the type code - * @return the msg instance by code - */ - -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractResultMessageV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractResultMessageV0.java deleted file mode 100644 index 04b5a46af97..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/AbstractResultMessageV0.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0_1; - -import io.netty.buffer.ByteBuf; -import io.seata.core.protocol.AbstractResultMessage; -import io.seata.core.protocol.ResultCode; - -import java.nio.ByteBuffer; - -/** - * The type Abstract result message. - * - * @author jimin.jm @alibaba-inc.com - * @date 2018 /9/14 - */ -public abstract class AbstractResultMessageV0 extends AbstractMessageV0 implements MergedMessageV0 { - private static final long serialVersionUID = 6540352050650203313L; - - private ResultCode resultCode; - - /** - * The Byte buffer. - */ - public ByteBuffer byteBuffer = ByteBuffer.allocate(512); - - /** - * Gets result code. - * - * @return the result code - */ - public ResultCode getResultCode() { - return resultCode; - } - - /** - * Sets result code. - * - * @param resultCode the result code - */ - public void setResultCode(ResultCode resultCode) { - this.resultCode = resultCode; - } - - private String msg; - - /** - * Gets msg. - * - * @return the msg - */ - public String getMsg() { - return msg; - } - - /** - * Sets msg. - * - * @param msg the msg - */ - public void setMsg(String msg) { - this.msg = msg; - } - - /** - * Do encode. - */ - protected void doEncode() { - byteBuffer.put((byte)resultCode.ordinal()); - if (resultCode == ResultCode.Failed) { - if (getMsg() != null) { - String msg; - if (getMsg().length() > 128) { - msg = getMsg().substring(0, 128); - } else { - msg = getMsg(); - } - byte[] bs = msg.getBytes(UTF8); - if (bs.length > 400 && getMsg().length() > 64) { - msg = getMsg().substring(0, 64); - bs = msg.getBytes(UTF8); - } - byteBuffer.putShort((short)bs.length); - if (bs.length > 0) { - byteBuffer.put(bs); - } - } else { - byteBuffer.putShort((short)0); - } - } - } - - private final byte[] flushEncode() { - byteBuffer.flip(); - byte[] content = new byte[byteBuffer.limit()]; - byteBuffer.get(content); - byteBuffer.clear(); // >? - return content; - } - - @Override - public final byte[] encode() { - doEncode(); - return flushEncode(); - } - - @Override - public void decode(ByteBuffer byteBuffer) { - setResultCode(ResultCode.get(byteBuffer.get())); - if (resultCode == ResultCode.Failed) { - short len = byteBuffer.getShort(); - if (len > 0) { - byte[] msg = new byte[len]; - byteBuffer.get(msg); - this.setMsg(new String(msg, UTF8)); - } - } - } - - @Override - public boolean decode(ByteBuf in,AbstractResultMessage resultMessage) { - if (in.readableBytes() < 1) { - return false; - } - resultMessage.setResultCode(ResultCode.get(in.readByte())); - if (resultCode == ResultCode.Failed) { - if (in.readableBytes() < 2) { - return false; - } - short len = in.readShort(); - if (in.readableBytes() < len) { - return false; - } - if (len > 0) { - byte[] msg = new byte[len]; - in.readBytes(msg); - resultMessage.setMsg(new String(msg, UTF8)); - } - } - return true; - } -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/MergedMessageV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/MergedMessageV0.java deleted file mode 100644 index 1938b8dc27f..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/MergedMessageV0.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0_1; - -import java.nio.ByteBuffer; - -/** - * The interface Merged message. - * - * @author jimin.jm @alibaba-inc.com - * @date 2018 /9/17 - */ -public interface MergedMessageV0 { - /** - * Decode. - * - * @param byteBuffer the byte buffer - */ - void decode(ByteBuffer byteBuffer); -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMRequestV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMRequestV0.java deleted file mode 100644 index 632fbbb7021..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMRequestV0.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0_1; - -import io.netty.buffer.ByteBuf; - -import java.io.Serializable; - -import static io.seata.core.protocol.MessageType.TYPE_REG_RM; - -/** - * The type Register rm request. - * - * @author jimin.jm @alibaba-inc.com - * @date 2018 /10/10 - */ -public class RegisterRMRequestV0 extends AbstractIdentifyRequestV0 implements Serializable { - private static final long serialVersionUID = 7539732523682335742L; - - private String resourceIds; - - /** - * Instantiates a new Register rm request. - */ - public RegisterRMRequestV0() { - this(null, null); - } - - /** - * Instantiates a new Register rm request. - * - * @param applicationId the application id - * @param transactionServiceGroup the transaction service group - */ - public RegisterRMRequestV0(String applicationId, String transactionServiceGroup) { - super(applicationId, transactionServiceGroup); - } - - /** - * Gets resource ids. - * - * @return the resource ids - */ - public String getResourceIds() { - return resourceIds; - } - - /** - * Sets resource ids. - * - * @param resourceIds the resource ids - */ - public void setResourceIds(String resourceIds) { - this.resourceIds = resourceIds; - } - - @Override - public short getTypeCode() { - return TYPE_REG_RM; - } - - @Override - protected void doEncode() { - super.doEncode(); - if (this.resourceIds != null) { - byte[] bs = resourceIds.getBytes(UTF8); - byteBuffer.putInt(bs.length); - if (bs.length > 0) { - byteBuffer.put(bs); - } - } else { - byteBuffer.putInt(0); - } - } - - @Override - public boolean decode(ByteBuf in) { - - if (in.readableBytes() < 2) { - return false; - } - short len = in.readShort(); - if (len > 0) { - if (in.readableBytes() < len) { - return false; - } - byte[] bs = new byte[len]; - in.readBytes(bs); - this.setVersion(new String(bs, UTF8)); - } else { - return false; - } - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (len > 0) { - if (in.readableBytes() < len) { - return false; - } - byte[] bs = new byte[len]; - in.readBytes(bs); - this.setApplicationId(new String(bs, UTF8)); - } - - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (in.readableBytes() < len) { - return false; - } - byte[] bs = new byte[len]; - in.readBytes(bs); - this.setTransactionServiceGroup(new String(bs, UTF8)); - - if (in.readableBytes() < 2) { - return false; - } - len = in.readShort(); - - if (len > 0) { - if (in.readableBytes() < len) { - return false; - } - bs = new byte[len]; - in.readBytes(bs); - this.setExtraData(new String(bs, UTF8)); - } - - int iLen; - if (in.readableBytes() < 4) { - return false; - } - iLen = in.readInt(); - - if (iLen > 0) { - if (in.readableBytes() < iLen) { - return false; - } - bs = new byte[iLen]; - in.readBytes(bs); - this.setResourceIds(new String(bs, UTF8)); - return true; - } - //maybe null - - return true; - } - - @Override - public String toString() { - return "RegisterRMRequest{" + - "resourceIds='" + resourceIds + '\'' + - ", applicationId='" + applicationId + '\'' + - ", transactionServiceGroup='" + transactionServiceGroup + '\'' + - '}'; - } -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMResponseV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMResponseV0.java deleted file mode 100644 index 15b02401315..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterRMResponseV0.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0_1; - - -import io.seata.core.protocol.MessageType; - -import java.io.Serializable; - -/** - * The type Register rm response. - * - * @author jimin.jm @alibaba-inc.com - * @date 2018 /10/10 - */ -public class RegisterRMResponseV0 extends AbstractIdentifyResponseV0 implements Serializable { - private static final long serialVersionUID = 6391375605848221420L; - - /** - * Instantiates a new Register rm response. - */ - public RegisterRMResponseV0() { - this(true); - } - - /** - * Instantiates a new Register rm response. - * - * @param result the result - */ - public RegisterRMResponseV0(boolean result) { - super(); - setIdentified(result); - } - - @Override - public short getTypeCode() { - return MessageType.TYPE_REG_RM_RESULT; - } -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMRequestV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMRequestV0.java deleted file mode 100644 index d2e2bfa0c5c..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMRequestV0.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0_1; - - -import io.seata.core.protocol.MessageType; - -import java.io.Serializable; - -/** - * The type Register tm request. - * - * @author jimin.jm @alibaba-inc.com - * @date 2018 /10/15 - */ -public class RegisterTMRequestV0 extends AbstractIdentifyRequestV0 implements Serializable { - private static final long serialVersionUID = -5929081344190543690L; - - /** - * Instantiates a new Register tm request. - */ - public RegisterTMRequestV0() { - this(null, null); - } - - /** - * Instantiates a new Register tm request. - * - * @param applicationId the application id - * @param transactionServiceGroup the transaction service group - * @param extraData the extra data - */ - public RegisterTMRequestV0(String applicationId, String transactionServiceGroup, String extraData) { - super(applicationId, transactionServiceGroup, extraData); - - } - - /** - * Instantiates a new Register tm request. - * - * @param applicationId the application id - * @param transactionServiceGroup the transaction service group - */ - public RegisterTMRequestV0(String applicationId, String transactionServiceGroup) { - super(applicationId, transactionServiceGroup); - } - - @Override - public short getTypeCode() { - return MessageType.TYPE_REG_CLT; - } - - @Override - public String toString() { - return "RegisterTMRequest{" + - "applicationId='" + applicationId + '\'' + - ", transactionServiceGroup='" + transactionServiceGroup + '\'' + - '}'; - } -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMResponseV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMResponseV0.java deleted file mode 100644 index 89196224514..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/RegisterTMResponseV0.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0_1; - - -import io.seata.core.protocol.MessageType; - -import java.io.Serializable; - -/** - * The type Register tm response. - * - * @author jimin.jm @alibaba-inc.com - * @date 2018 /10/15 - */ -public class RegisterTMResponseV0 extends AbstractIdentifyResponseV0 implements Serializable { - private static final long serialVersionUID = 3629846050062228749L; - - /** - * Instantiates a new Register tm response. - */ - public RegisterTMResponseV0() { - this(true); - } - - /** - * Instantiates a new Register tm response. - * - * @param result the result - */ - public RegisterTMResponseV0(boolean result) { - super(); - setIdentified(result); - } - - @Override - public short getTypeCode() { - return MessageType.TYPE_REG_CLT_RESULT; - } -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/SeataV0Serializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/SeataV0Serializer.java deleted file mode 100644 index ed35f987b1b..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0_1/SeataV0Serializer.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v0_1; - -import io.seata.core.protocol.MessageType; -import io.seata.core.rpc.netty.v0.MessageCodecV0; -import io.seata.core.rpc.netty.v0.SerializerV0; - -/** - * The Seata codec v0. - * - * @author Bughue - */ -public class SeataV0Serializer implements SerializerV0 { - - public SeataV0Serializer() { - - } - - - @Override - public MessageCodecV0 getMsgInstanceByCode(short typeCode) { - MessageCodecV0 msgCodec = null; - switch (typeCode) { -// case MessageType.TYPE_SEATA_MERGE: -// msgCodec = new MergedWarpMessage(); -// break; -// case MessageType.TYPE_SEATA_MERGE_RESULT: -// msgCodec = new MergeResultMessage(); -// break; - case MessageType.TYPE_REG_CLT: - msgCodec = new RegisterTMRequestV0(); - break; - case MessageType.TYPE_REG_CLT_RESULT: - msgCodec = new RegisterTMResponseV0(); - break; - case MessageType.TYPE_REG_RM: - msgCodec = new RegisterRMRequestV0(); - break; - case MessageType.TYPE_REG_RM_RESULT: - msgCodec = new RegisterRMResponseV0(); - break; -// case MessageType.TYPE_BRANCH_COMMIT: -// msgCodec = new BranchCommitRequest(); -// break; -// case MessageType.TYPE_BRANCH_ROLLBACK: -// msgCodec = new BranchRollbackRequest(); -// break; - default: - break; - } - - if (null != msgCodec) { - return msgCodec; - } - - try { - msgCodec = (MessageCodecV0) getMergeRequestInstanceByCode(typeCode); - } catch (Exception exx) { - - } - if (null != msgCodec) { - return msgCodec; - } - - return (MessageCodecV0)getMergeResponseInstanceByCode(typeCode); - } - - /** - * Gets merge request instance by code. - * - * @param typeCode the type code - * @return the merge request instance by code - */ - public static MergedMessageV0 getMergeRequestInstanceByCode(int typeCode) { - switch (typeCode) { -// case MessageType.TYPE_GLOBAL_BEGIN: -// return new GlobalBeginRequest(); -// case MessageType.TYPE_GLOBAL_COMMIT: -// return new GlobalCommitRequest(); -// case MessageType.TYPE_GLOBAL_ROLLBACK: -// return new GlobalRollbackRequest(); -// case MessageType.TYPE_GLOBAL_STATUS: -// return new GlobalStatusRequest(); -// case MessageType.TYPE_GLOBAL_LOCK_QUERY: -// return new GlobalLockQueryRequest(); -// case MessageType.TYPE_BRANCH_REGISTER: -// return new BranchRegisterRequest(); -// case MessageType.TYPE_BRANCH_STATUS_REPORT: -// return new BranchReportRequest(); - default: - throw new IllegalArgumentException("not support typeCode," + typeCode); - } - } - - /** - * Gets merge response instance by code. - * - * @param typeCode the type code - * @return the merge response instance by code - */ - public static MergedMessageV0 getMergeResponseInstanceByCode(int typeCode) { - switch (typeCode) { -// case MessageType.TYPE_GLOBAL_BEGIN_RESULT: -// return new GlobalBeginResponse(); -// case MessageType.TYPE_GLOBAL_COMMIT_RESULT: -// return new GlobalCommitResponse(); -// case MessageType.TYPE_GLOBAL_ROLLBACK_RESULT: -// return new GlobalRollbackResponse(); -// case MessageType.TYPE_GLOBAL_STATUS_RESULT: -// return new GlobalStatusResponse(); -// case MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT: -// return new GlobalLockQueryResponse(); -// case MessageType.TYPE_BRANCH_REGISTER_RESULT: -// return new BranchRegisterResponse(); -// case MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT: -// return new BranchReportResponse(); -// case MessageType.TYPE_BRANCH_COMMIT_RESULT: -// return new BranchCommitResponse(); -// case MessageType.TYPE_BRANCH_ROLLBACK_RESULT: -// return new BranchRollbackResponse(); - default: - throw new IllegalArgumentException("not support typeCode," + typeCode); - } - } -} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java index 3a325a5e7ab..663bdf9f55a 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/AbstractIdentifyRequestCodec.java @@ -24,8 +24,7 @@ * The type Abstract identify request codec. */ public abstract class AbstractIdentifyRequestCodec extends AbstractMessageCodec { - // todo [5738-discuss][codec] 像这种父类如果是这次的新旧版本都一样,要写成继承吗 - // todo [5738-discuss][codec] 这些codec类只依靠包区分是否足够? + @Override public Class getMessageClassType() { return AbstractIdentifyRequest.class; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/BatchResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/BatchResultMessageCodec.java index ccbf67f5742..5be3557380c 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/BatchResultMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/BatchResultMessageCodec.java @@ -24,8 +24,8 @@ import io.seata.core.protocol.AbstractMessage; import io.seata.core.protocol.AbstractResultMessage; import io.seata.core.protocol.BatchResultMessage; -import io.seata.serializer.seata.MessageCodecFactory; import io.seata.serializer.seata.MessageSeataCodec; +import io.seata.serializer.seata.MessageCodecFactory; /** * the type batch result message codec @@ -35,6 +35,7 @@ */ public class BatchResultMessageCodec extends AbstractMessageCodec { + protected MessageCodecFactory factory = new MessageCodecFactoryV1(); @Override public Class getMessageClassType() { return BatchResultMessage.class; @@ -53,7 +54,7 @@ public void encode(T t, ByteBuf out) { for (final AbstractMessage msg : msgs) { final ByteBuf subBuffer = Unpooled.buffer(1024); short typeCode = msg.getTypeCode(); - MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode); + MessageSeataCodec messageCodec = factory.getMessageCodec(typeCode); messageCodec.encode(msg, subBuffer); buffer.writeShort(msg.getTypeCode()); buffer.writeBytes(subBuffer); @@ -106,8 +107,8 @@ protected void decode(BatchResultMessage batchResultMessage, ByteBuffer byteBuff List msgIds = new ArrayList<>(); for (int idx = 0; idx < msgNum; idx++) { short typeCode = byteBuffer.getShort(); - AbstractMessage abstractResultMessage = MessageCodecFactory.getMessage(typeCode); - MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode); + AbstractMessage abstractResultMessage = factory.getMessage(typeCode); + MessageSeataCodec messageCodec = factory.getMessageCodec(typeCode); messageCodec.decode(abstractResultMessage, byteBuffer); msgs.add((AbstractResultMessage) abstractResultMessage); } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergeResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergeResultMessageCodec.java index 074b2d3a095..4db88e62070 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergeResultMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergeResultMessageCodec.java @@ -18,11 +18,11 @@ import java.nio.ByteBuffer; import io.netty.buffer.ByteBuf; -import io.seata.serializer.seata.MessageCodecFactory; import io.seata.serializer.seata.MessageSeataCodec; import io.seata.core.protocol.AbstractMessage; import io.seata.core.protocol.AbstractResultMessage; import io.seata.core.protocol.MergeResultMessage; +import io.seata.serializer.seata.MessageCodecFactory; /** * The type Merge result message codec. @@ -31,6 +31,7 @@ */ public class MergeResultMessageCodec extends AbstractMessageCodec { + protected MessageCodecFactory factory = new MessageCodecFactoryV1(); @Override public Class getMessageClassType() { return MergeResultMessage.class; @@ -48,7 +49,7 @@ public void encode(T t, ByteBuf out) { short typeCode = msg.getTypeCode(); //put typeCode out.writeShort(typeCode); - MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode); + MessageSeataCodec messageCodec = factory.getMessageCodec(typeCode); messageCodec.encode(msg, out); } @@ -90,8 +91,8 @@ protected void decode(MergeResultMessage mergeResultMessage, ByteBuffer byteBuff AbstractResultMessage[] msgs = new AbstractResultMessage[msgNum]; for (int idx = 0; idx < msgNum; idx++) { short typeCode = byteBuffer.getShort(); - AbstractMessage abstractResultMessage = MessageCodecFactory.getMessage(typeCode); - MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode); + AbstractMessage abstractResultMessage = factory.getMessage(typeCode); + MessageSeataCodec messageCodec = factory.getMessageCodec(typeCode); messageCodec.decode(abstractResultMessage, byteBuffer); msgs[idx] = (AbstractResultMessage)abstractResultMessage; } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergedWarpMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergedWarpMessageCodec.java index 0bd7b184caa..fc6e0221df2 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergedWarpMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MergedWarpMessageCodec.java @@ -21,10 +21,10 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import io.seata.serializer.seata.MessageCodecFactory; import io.seata.serializer.seata.MessageSeataCodec; import io.seata.core.protocol.AbstractMessage; import io.seata.core.protocol.MergedWarpMessage; +import io.seata.serializer.seata.MessageCodecFactory; /** * The type Merged warp message codec. @@ -33,6 +33,7 @@ */ public class MergedWarpMessageCodec extends AbstractMessageCodec { + protected MessageCodecFactory factory = new MessageCodecFactoryV1(); @Override public Class getMessageClassType() { return MergedWarpMessage.class; @@ -51,7 +52,7 @@ public void encode(T t, ByteBuf out) { for (final AbstractMessage msg : msgs) { final ByteBuf subBuffer = Unpooled.buffer(1024); short typeCode = msg.getTypeCode(); - MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode); + MessageSeataCodec messageCodec = factory.getMessageCodec(typeCode); messageCodec.encode(msg, subBuffer); buffer.writeShort(msg.getTypeCode()); buffer.writeBytes(subBuffer); @@ -96,8 +97,8 @@ private void doDecode(MergedWarpMessage mergedWarpMessage, ByteBuffer byteBuffer List msgs = new ArrayList(); for (int idx = 0; idx < msgNum; idx++) { short typeCode = byteBuffer.getShort(); - AbstractMessage abstractMessage = MessageCodecFactory.getMessage(typeCode); - MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode); + AbstractMessage abstractMessage = factory.getMessage(typeCode); + MessageSeataCodec messageCodec = factory.getMessageCodec(typeCode); messageCodec.decode(abstractMessage, byteBuffer); msgs.add(abstractMessage); } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MessageCodecFactoryV1.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MessageCodecFactoryV1.java new file mode 100644 index 00000000000..6e14490fc2e --- /dev/null +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MessageCodecFactoryV1.java @@ -0,0 +1,184 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.serializer.seata.protocol.v1; + +import io.seata.core.protocol.MessageType; +import io.seata.serializer.seata.MessageSeataCodec; +import io.seata.serializer.seata.MessageCodecFactory; +import io.seata.serializer.seata.protocol.v1.transaction.BranchCommitRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchCommitResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchRegisterRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchRegisterResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchReportRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchReportResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchRollbackRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.BranchRollbackResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalBeginRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalBeginResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalCommitRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalCommitResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalLockQueryRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalLockQueryResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalReportRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalReportResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalRollbackRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalRollbackResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalStatusRequestCodec; +import io.seata.serializer.seata.protocol.v1.transaction.GlobalStatusResponseCodec; +import io.seata.serializer.seata.protocol.v1.transaction.UndoLogDeleteRequestCodec; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +/** + * The type Message codec factory. + * + * @author zhangsen + */ +public class MessageCodecFactoryV1 extends MessageCodecFactory { + /** + * The constant UTF8. + */ + protected static final Charset UTF8 = StandardCharsets.UTF_8; + + /** + * Gets msg instance by code. + * + * @param typeCode the type code + * @return the msg instance by code + */ + public MessageSeataCodec getMessageCodec(short typeCode) { + MessageSeataCodec msgCodec = null; + switch (typeCode) { + case MessageType.TYPE_SEATA_MERGE: + msgCodec = new MergedWarpMessageCodec(); + break; + case MessageType.TYPE_SEATA_MERGE_RESULT: + msgCodec = new MergeResultMessageCodec(); + break; + case MessageType.TYPE_REG_CLT: + msgCodec = new RegisterTMRequestCodec(); + break; + case MessageType.TYPE_REG_CLT_RESULT: + msgCodec = new RegisterTMResponseCodec(); + break; + case MessageType.TYPE_REG_RM: + msgCodec = new RegisterRMRequestCodec(); + break; + case MessageType.TYPE_REG_RM_RESULT: + msgCodec = new RegisterRMResponseCodec(); + break; + case MessageType.TYPE_BRANCH_COMMIT: + msgCodec = new BranchCommitRequestCodec(); + break; + case MessageType.TYPE_BRANCH_ROLLBACK: + msgCodec = new BranchRollbackRequestCodec(); + break; + case MessageType.TYPE_GLOBAL_REPORT: + msgCodec = new GlobalReportRequestCodec(); + break; + case MessageType.TYPE_BATCH_RESULT_MSG: + msgCodec = new BatchResultMessageCodec(); + break; + default: + break; + } + + if (msgCodec != null) { + return msgCodec; + } + + try { + msgCodec = getMergeRequestMessageSeataCodec(typeCode); + } catch (Exception exx) { + } + + if (msgCodec != null) { + return msgCodec; + } + + msgCodec = getMergeResponseMessageSeataCodec(typeCode); + + return msgCodec; + } + + /** + * Gets merge request instance by code. + * + * @param typeCode the type code + * @return the merge request instance by code + */ + protected static MessageSeataCodec getMergeRequestMessageSeataCodec(int typeCode) { + switch (typeCode) { + case MessageType.TYPE_GLOBAL_BEGIN: + return new GlobalBeginRequestCodec(); + case MessageType.TYPE_GLOBAL_COMMIT: + return new GlobalCommitRequestCodec(); + case MessageType.TYPE_GLOBAL_ROLLBACK: + return new GlobalRollbackRequestCodec(); + case MessageType.TYPE_GLOBAL_STATUS: + return new GlobalStatusRequestCodec(); + case MessageType.TYPE_GLOBAL_LOCK_QUERY: + return new GlobalLockQueryRequestCodec(); + case MessageType.TYPE_BRANCH_REGISTER: + return new BranchRegisterRequestCodec(); + case MessageType.TYPE_BRANCH_STATUS_REPORT: + return new BranchReportRequestCodec(); + case MessageType.TYPE_GLOBAL_REPORT: + return new GlobalReportRequestCodec(); + default: + throw new IllegalArgumentException("not support typeCode," + typeCode); + } + } + + /** + * Gets merge response instance by code. + * + * @param typeCode the type code + * @return the merge response instance by code + */ + protected static MessageSeataCodec getMergeResponseMessageSeataCodec(int typeCode) { + switch (typeCode) { + case MessageType.TYPE_GLOBAL_BEGIN_RESULT: + return new GlobalBeginResponseCodec(); + case MessageType.TYPE_GLOBAL_COMMIT_RESULT: + return new GlobalCommitResponseCodec(); + case MessageType.TYPE_GLOBAL_ROLLBACK_RESULT: + return new GlobalRollbackResponseCodec(); + case MessageType.TYPE_GLOBAL_STATUS_RESULT: + return new GlobalStatusResponseCodec(); + case MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT: + return new GlobalLockQueryResponseCodec(); + case MessageType.TYPE_BRANCH_REGISTER_RESULT: + return new BranchRegisterResponseCodec(); + case MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT: + return new BranchReportResponseCodec(); + case MessageType.TYPE_BRANCH_COMMIT_RESULT: + return new BranchCommitResponseCodec(); + case MessageType.TYPE_BRANCH_ROLLBACK_RESULT: + return new BranchRollbackResponseCodec(); + case MessageType.TYPE_RM_DELETE_UNDOLOG: + return new UndoLogDeleteRequestCodec(); + case MessageType.TYPE_GLOBAL_REPORT_RESULT: + return new GlobalReportResponseCodec(); + default: + throw new IllegalArgumentException("not support typeCode," + typeCode); + } + } + + + +} diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/SeataV1Serializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/SeataV1Serializer.java deleted file mode 100644 index b2e46218984..00000000000 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/SeataV1Serializer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.serializer.seata.protocol.v1; - -import com.sun.tools.javac.util.Pair; -import io.seata.common.loader.LoadLevel; -import io.seata.core.protocol.MessageType; -import io.seata.core.protocol.ProtocolConstants; -import io.seata.core.protocol.RegisterRMRequest; -import io.seata.core.protocol.RegisterRMResponse; -import io.seata.core.protocol.RegisterTMRequest; -import io.seata.core.protocol.RegisterTMResponse; -import io.seata.serializer.seata.SeataAbstractSerializer; - -/** - * The Seata codec v1. - * - * @author Bughue - */ -@LoadLevel(name = "SEATA", version = ProtocolConstants.VERSION_1) -public class SeataV1Serializer extends SeataAbstractSerializer { - - public SeataV1Serializer() { - classMap.put(MessageType.TYPE_REG_CLT, new Pair<>(RegisterTMRequestCodec.class, RegisterTMRequest.class)); - classMap.put(MessageType.TYPE_REG_CLT_RESULT, new Pair<>(RegisterTMResponseCodec.class, RegisterTMResponse.class)); - classMap.put(MessageType.TYPE_REG_RM, new Pair<>(RegisterRMRequestCodec.class, RegisterRMRequest.class)); - classMap.put(MessageType.TYPE_REG_RM_RESULT, new Pair<>(RegisterRMResponseCodec.class, RegisterRMResponse.class)); - - } - - - - -} diff --git a/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.rpc.netty.v0.SerializerV0 b/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.rpc.netty.v0.SerializerV0 deleted file mode 100644 index 07bab05d194..00000000000 --- a/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.rpc.netty.v0.SerializerV0 +++ /dev/null @@ -1 +0,0 @@ -io.seata.serializer.seata.protocol.v0_1.SeataV0Serializer \ No newline at end of file diff --git a/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer b/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer index d448c8d46fb..0d76176a84c 100644 --- a/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer +++ b/serializer/seata-serializer-seata/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer @@ -1,2 +1 @@ -io.seata.serializer.seata.protocol.v1.SeataV1Serializer -io.seata.serializer.seata.protocol.v0.SeataV0Serializer +io.seata.serializer.seata.SeataSerializer \ No newline at end of file From 67c5a3006c86b04326abcada2e0d226878fe5300 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 13 Nov 2023 14:06:46 +0800 Subject: [PATCH 13/22] application.example.yml --- test-protocol-mock-server/pom.xml | 52 +++++++++++ .../seata/mock/protocol/MockNettyClient.java | 89 +++++++++++++++++++ .../mock/protocol/MockServerApplication.java | 32 +++++++ .../mock/protocol/rm/v1/MockRmClient.java | 21 +++++ .../mock/protocol/tm/v1/MockTmClient.java | 26 ++++++ .../src/test/resources/README.md | 2 + .../src/test/resources/logback.xml | 29 ++++++ 7 files changed, 251 insertions(+) create mode 100644 test-protocol-mock-server/pom.xml create mode 100644 test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java create mode 100644 test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockServerApplication.java create mode 100644 test-protocol-mock-server/src/main/java/io/seata/mock/protocol/rm/v1/MockRmClient.java create mode 100644 test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java create mode 100644 test-protocol-mock-server/src/test/resources/README.md create mode 100755 test-protocol-mock-server/src/test/resources/logback.xml diff --git a/test-protocol-mock-server/pom.xml b/test-protocol-mock-server/pom.xml new file mode 100644 index 00000000000..6fdc4a271c9 --- /dev/null +++ b/test-protocol-mock-server/pom.xml @@ -0,0 +1,52 @@ + + + + + io.seata + seata-parent + ${revision} + + 4.0.0 + seata-test-protocol-mock-server + jar + seata-test-protocol-mock-server ${project.version} + test for Seata protocol + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + + + + ${project.groupId} + seata-core + ${project.version} + + + + + \ No newline at end of file diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java new file mode 100644 index 00000000000..c7f0a5cb8ef --- /dev/null +++ b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java @@ -0,0 +1,89 @@ +package io.seata.mock.protocol; + +import io.netty.channel.Channel; +import io.netty.util.concurrent.EventExecutorGroup; +import io.seata.core.protocol.AbstractMessage; +import io.seata.core.protocol.MessageType; +import io.seata.core.rpc.netty.AbstractNettyRemotingClient; +import io.seata.core.rpc.netty.NettyClientConfig; +import io.seata.core.rpc.netty.NettyPoolKey; +import io.seata.core.rpc.processor.client.ClientHeartbeatProcessor; +import io.seata.core.rpc.processor.client.ClientOnResponseProcessor; +import io.seata.core.rpc.processor.client.RmBranchCommitProcessor; +import io.seata.core.rpc.processor.client.RmBranchRollbackProcessor; +import io.seata.core.rpc.processor.client.RmUndoLogProcessor; + +import java.util.concurrent.ThreadPoolExecutor; +import java.util.function.Function; + +/** + * ? + * + * @author minghua.xie + * @date 2023/11/10 + **/ +public class MockNettyClient extends AbstractNettyRemotingClient { + public MockNettyClient(NettyClientConfig nettyClientConfig, EventExecutorGroup eventExecutorGroup, ThreadPoolExecutor messageExecutor, NettyPoolKey.TransactionRole transactionRole) { + super(nettyClientConfig, eventExecutorGroup, messageExecutor, transactionRole); + } + + @Override + public void onRegisterMsgSuccess(String serverAddress, Channel channel, Object response, AbstractMessage requestMessage) { + + } + + @Override + public void onRegisterMsgFail(String serverAddress, Channel channel, Object response, AbstractMessage requestMessage) { + + } + + @Override + protected Function getPoolKeyFunction() { + return null; + } + + @Override + protected String getTransactionServiceGroup() { + return null; + } + + @Override + protected boolean isEnableClientBatchSendRequest() { + return false; + } + + @Override + protected long getRpcRequestTimeout() { + return 0; + } + + + private void registerProcessor() { + ClientHeartbeatProcessor clientHeartbeatProcessor = new ClientHeartbeatProcessor(); + super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, clientHeartbeatProcessor, null); + + super.registerProcessor(MessageType.TYPE_SEATA_MERGE_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_BATCH_RESULT_MSG, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT, onResponseProcessor, null); + + + super.registerProcessor(MessageType.TYPE_REG_RM_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_RM_DELETE_UNDOLOG, rmUndoLogProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_BRANCH_COMMIT, rmBranchCommitProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_BRANCH_ROLLBACK, rmBranchRollbackProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_BRANCH_REGISTER_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT, onResponseProcessor, null); + + + super.registerProcessor(MessageType.TYPE_GLOBAL_BEGIN_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_GLOBAL_COMMIT_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_GLOBAL_REPORT_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_GLOBAL_ROLLBACK_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_GLOBAL_STATUS_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_REG_CLT_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_BATCH_RESULT_MSG, onResponseProcessor, null); + // 2.registry heartbeat message processor + ClientHeartbeatProcessor clientHeartbeatProcessor = new ClientHeartbeatProcessor(); + super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, clientHeartbeatProcessor, null); + } +} diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockServerApplication.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockServerApplication.java new file mode 100644 index 00000000000..05eb05e3959 --- /dev/null +++ b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockServerApplication.java @@ -0,0 +1,32 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.mock.protocol; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import java.io.IOException; + +/** + * @author spilledyear@outlook.com + */ +@SpringBootApplication(scanBasePackages = {"io.seata.mock.protocol"}) +public class MockServerApplication { + public static void main(String[] args) throws IOException { + // run the spring-boot application + SpringApplication.run(MockServerApplication.class, args); + } +} diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/rm/v1/MockRmClient.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/rm/v1/MockRmClient.java new file mode 100644 index 00000000000..327699ab7f7 --- /dev/null +++ b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/rm/v1/MockRmClient.java @@ -0,0 +1,21 @@ +package io.seata.mock.protocol.rm.v1; + +import io.netty.util.concurrent.EventExecutorGroup; +import io.seata.core.rpc.netty.NettyClientConfig; +import io.seata.core.rpc.netty.NettyPoolKey; +import io.seata.mock.protocol.MockNettyClient; + +import java.util.concurrent.ThreadPoolExecutor; + +/** + * ? + * + * @author minghua.xie + * @date 2023/11/10 + **/ +public class MockRmClient extends MockNettyClient { + public MockRmClient(NettyClientConfig nettyClientConfig, EventExecutorGroup eventExecutorGroup, ThreadPoolExecutor messageExecutor, NettyPoolKey.TransactionRole transactionRole) { + super(nettyClientConfig, eventExecutorGroup, messageExecutor, transactionRole); + } + +} diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java new file mode 100644 index 00000000000..a82df504644 --- /dev/null +++ b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java @@ -0,0 +1,26 @@ +package io.seata.mock.protocol.tm.v1; + +import io.netty.channel.Channel; +import io.netty.util.concurrent.EventExecutorGroup; +import io.seata.core.protocol.AbstractMessage; +import io.seata.core.rpc.netty.AbstractNettyRemotingClient; +import io.seata.core.rpc.netty.NettyClientConfig; +import io.seata.core.rpc.netty.NettyPoolKey; +import io.seata.mock.protocol.MockNettyClient; + +import java.util.concurrent.ThreadPoolExecutor; +import java.util.function.Function; + +/** + * ? + * + * @author minghua.xie + * @date 2023/11/10 + **/ +public class MockTmClient extends MockNettyClient { + public MockTmClient(NettyClientConfig nettyClientConfig, EventExecutorGroup eventExecutorGroup, ThreadPoolExecutor messageExecutor, NettyPoolKey.TransactionRole transactionRole) { + super(nettyClientConfig, eventExecutorGroup, messageExecutor, transactionRole); + } + + +} diff --git a/test-protocol-mock-server/src/test/resources/README.md b/test-protocol-mock-server/src/test/resources/README.md new file mode 100644 index 00000000000..fc7352a038a --- /dev/null +++ b/test-protocol-mock-server/src/test/resources/README.md @@ -0,0 +1,2 @@ +## seata 多版本协议 mock server +## \ No newline at end of file diff --git a/test-protocol-mock-server/src/test/resources/logback.xml b/test-protocol-mock-server/src/test/resources/logback.xml new file mode 100755 index 00000000000..b0c85610e45 --- /dev/null +++ b/test-protocol-mock-server/src/test/resources/logback.xml @@ -0,0 +1,29 @@ + + + + + + + + %date [SEATA] [%thread] %-5level %logger{80} - %msg%n + + + + + + + From 45d1cf18b85ca6c6453fb43b6c11bff696ca53a5 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Tue, 14 Nov 2023 18:00:57 +0800 Subject: [PATCH 14/22] mock --- .../rpc/processor/server/RegTmProcessor.java | 2 +- .../seata/mock/protocol/MockNettyClient.java | 59 ++++---- .../mock/protocol/MockRemotingProcessor.java | 34 +++++ .../protocol/tc/MockNettyRemotingServer.java | 132 ++++++++++++++++++ .../mock/protocol/tm/v1/MockTmClient.java | 22 ++- 5 files changed, 216 insertions(+), 33 deletions(-) create mode 100644 test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockRemotingProcessor.java create mode 100644 test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tc/MockNettyRemotingServer.java diff --git a/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java b/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java index 1b7deb6f647..601251e821e 100644 --- a/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java +++ b/core/src/main/java/io/seata/core/rpc/processor/server/RegTmProcessor.java @@ -65,7 +65,7 @@ private void onRegTmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) { String errorInfo = StringUtils.EMPTY; try { if (null == checkAuthHandler || checkAuthHandler.regTransactionManagerCheckAuth(message)) { - ChannelManager.registerTMChannel(message, ctx.channel(), rpcMessage.getVersion()); + ChannelManager.registerTMChannel(message, ctx.channel()); Version.putChannelVersion(ctx.channel(), message.getVersion()); isSuccess = true; if (LOGGER.isDebugEnabled()) { diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java index c7f0a5cb8ef..fad37c5fcc1 100644 --- a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java +++ b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java @@ -8,16 +8,12 @@ import io.seata.core.rpc.netty.NettyClientConfig; import io.seata.core.rpc.netty.NettyPoolKey; import io.seata.core.rpc.processor.client.ClientHeartbeatProcessor; -import io.seata.core.rpc.processor.client.ClientOnResponseProcessor; -import io.seata.core.rpc.processor.client.RmBranchCommitProcessor; -import io.seata.core.rpc.processor.client.RmBranchRollbackProcessor; -import io.seata.core.rpc.processor.client.RmUndoLogProcessor; import java.util.concurrent.ThreadPoolExecutor; import java.util.function.Function; /** - * ? + * mock client * * @author minghua.xie * @date 2023/11/10 @@ -59,31 +55,32 @@ protected long getRpcRequestTimeout() { private void registerProcessor() { - ClientHeartbeatProcessor clientHeartbeatProcessor = new ClientHeartbeatProcessor(); - super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, clientHeartbeatProcessor, null); - - super.registerProcessor(MessageType.TYPE_SEATA_MERGE_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_BATCH_RESULT_MSG, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT, onResponseProcessor, null); - - - super.registerProcessor(MessageType.TYPE_REG_RM_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_RM_DELETE_UNDOLOG, rmUndoLogProcessor, messageExecutor); - super.registerProcessor(MessageType.TYPE_BRANCH_COMMIT, rmBranchCommitProcessor, messageExecutor); - super.registerProcessor(MessageType.TYPE_BRANCH_ROLLBACK, rmBranchRollbackProcessor, messageExecutor); - super.registerProcessor(MessageType.TYPE_BRANCH_REGISTER_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT, onResponseProcessor, null); - - - super.registerProcessor(MessageType.TYPE_GLOBAL_BEGIN_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_GLOBAL_COMMIT_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_GLOBAL_REPORT_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_GLOBAL_ROLLBACK_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_GLOBAL_STATUS_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_REG_CLT_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_BATCH_RESULT_MSG, onResponseProcessor, null); - // 2.registry heartbeat message processor - ClientHeartbeatProcessor clientHeartbeatProcessor = new ClientHeartbeatProcessor(); - super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, clientHeartbeatProcessor, null); +// ClientHeartbeatProcessor clientHeartbeatProcessor = new ClientHeartbeatProcessor(); +// super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, clientHeartbeatProcessor, null); +// +// ; +// super.registerProcessor(MessageType.TYPE_SEATA_MERGE_RESULT, new MockRemotingProcessor<>(), null); +// super.registerProcessor(MessageType.TYPE_BATCH_RESULT_MSG, onResponseProcessor, null); +// super.registerProcessor(MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT, onResponseProcessor, null); +// +// +// super.registerProcessor(MessageType.TYPE_REG_RM_RESULT, onResponseProcessor, null); +// super.registerProcessor(MessageType.TYPE_RM_DELETE_UNDOLOG, rmUndoLogProcessor, messageExecutor); +// super.registerProcessor(MessageType.TYPE_BRANCH_COMMIT, rmBranchCommitProcessor, messageExecutor); +// super.registerProcessor(MessageType.TYPE_BRANCH_ROLLBACK, rmBranchRollbackProcessor, messageExecutor); +// super.registerProcessor(MessageType.TYPE_BRANCH_REGISTER_RESULT, onResponseProcessor, null); +// super.registerProcessor(MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT, onResponseProcessor, null); +// +// +// super.registerProcessor(MessageType.TYPE_GLOBAL_BEGIN_RESULT, onResponseProcessor, null); +// super.registerProcessor(MessageType.TYPE_GLOBAL_COMMIT_RESULT, onResponseProcessor, null); +// super.registerProcessor(MessageType.TYPE_GLOBAL_REPORT_RESULT, onResponseProcessor, null); +// super.registerProcessor(MessageType.TYPE_GLOBAL_ROLLBACK_RESULT, onResponseProcessor, null); +// super.registerProcessor(MessageType.TYPE_GLOBAL_STATUS_RESULT, onResponseProcessor, null); +// super.registerProcessor(MessageType.TYPE_REG_CLT_RESULT, onResponseProcessor, null); +// super.registerProcessor(MessageType.TYPE_BATCH_RESULT_MSG, onResponseProcessor, null); +// // 2.registry heartbeat message processor +// ClientHeartbeatProcessor clientHeartbeatProcessor = new ClientHeartbeatProcessor(); +// super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, clientHeartbeatProcessor, null); } } diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockRemotingProcessor.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockRemotingProcessor.java new file mode 100644 index 00000000000..ddacffc3eb3 --- /dev/null +++ b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockRemotingProcessor.java @@ -0,0 +1,34 @@ +package io.seata.mock.protocol; + +import io.netty.channel.ChannelHandlerContext; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.RemotingServer; +import io.seata.core.rpc.processor.RemotingProcessor; + +/** + * Mock Remoting Processor + * + * @author minghua.xie + * @date 2023/11/14 + **/ +public class MockRemotingProcessor implements RemotingProcessor { + + private Class clazz; + private RemotingServer remotingServer; + + public MockRemotingProcessor(Class clazz, RemotingServer remotingServer) { + this.clazz = clazz; + this.remotingServer = remotingServer; + } + + @Override + public void process(ChannelHandlerContext ctx, RpcMessage rpcMessage) throws Exception { + REQ message = (REQ) rpcMessage.getBody(); + System.out.println("message = " + message); + + RESP resp = clazz.newInstance(); + remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), resp); + } + + +} diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tc/MockNettyRemotingServer.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tc/MockNettyRemotingServer.java new file mode 100644 index 00000000000..82223c6576f --- /dev/null +++ b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tc/MockNettyRemotingServer.java @@ -0,0 +1,132 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.mock.protocol.tc; + +import io.netty.channel.Channel; +import io.seata.common.thread.NamedThreadFactory; +import io.seata.core.protocol.AbstractMessage; +import io.seata.core.protocol.AbstractResultMessage; +import io.seata.core.protocol.MessageType; +import io.seata.core.protocol.RegisterRMRequest; +import io.seata.core.protocol.RegisterRMResponse; +import io.seata.core.protocol.RegisterTMRequest; +import io.seata.core.protocol.RegisterTMResponse; +import io.seata.core.rpc.RpcContext; +import io.seata.core.rpc.ShutdownHook; +import io.seata.core.rpc.TransactionMessageHandler; +import io.seata.core.rpc.netty.AbstractNettyRemotingServer; +import io.seata.core.rpc.netty.NettyServerConfig; +import io.seata.core.rpc.processor.server.RegRmProcessor; +import io.seata.core.rpc.processor.server.RegTmProcessor; +import io.seata.core.rpc.processor.server.ServerHeartbeatProcessor; +import io.seata.core.rpc.processor.server.ServerOnRequestProcessor; +import io.seata.core.rpc.processor.server.ServerOnResponseProcessor; +import io.seata.mock.protocol.MockRemotingProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * The mock netty remoting server. + * + * @author Bughue + */ +public class MockNettyRemotingServer extends AbstractNettyRemotingServer { + + private static final Logger LOGGER = LoggerFactory.getLogger(MockNettyRemotingServer.class); + + + @Override + public void init() { + // registry processor + registerProcessor(); + } + + /** + * Instantiates a new Rpc remoting server. + * + * @param messageExecutor the message executor + */ + public MockNettyRemotingServer(ThreadPoolExecutor messageExecutor) { + super(messageExecutor, new NettyServerConfig()); + } + + @Override + public void destroyChannel(String serverAddress, Channel channel) { + if (LOGGER.isInfoEnabled()) { + LOGGER.info("will destroy channel:{},address:{}", channel, serverAddress); + } + channel.disconnect(); + channel.close(); + } + + private TransactionMessageHandler getHandler(){ + return new TransactionMessageHandler() { + @Override + public AbstractResultMessage onRequest(AbstractMessage request, RpcContext context) { + return null; + } + + @Override + public void onResponse(AbstractResultMessage response, RpcContext context) { + + } + }; + } + + private void registerProcessor() { + // 1. registry on request message processor + ServerOnRequestProcessor onRequestProcessor = + new ServerOnRequestProcessor(this, getHandler()); + ShutdownHook.getInstance().addDisposable(onRequestProcessor); + super.registerProcessor(MessageType.TYPE_BRANCH_REGISTER, onRequestProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_BRANCH_STATUS_REPORT, onRequestProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_GLOBAL_BEGIN, onRequestProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_GLOBAL_COMMIT, onRequestProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_GLOBAL_LOCK_QUERY, onRequestProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_GLOBAL_REPORT, onRequestProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_GLOBAL_ROLLBACK, onRequestProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_GLOBAL_STATUS, onRequestProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_SEATA_MERGE, onRequestProcessor, messageExecutor); + + // 2. registry on response message processor + ServerOnResponseProcessor onResponseProcessor = + new ServerOnResponseProcessor(getHandler(), getFutures()); + super.registerProcessor(MessageType.TYPE_BRANCH_COMMIT_RESULT, onResponseProcessor, messageExecutor); + super.registerProcessor(MessageType.TYPE_BRANCH_ROLLBACK_RESULT, onResponseProcessor, messageExecutor); + + // 3. registry rm message processor + MockRemotingProcessor regRmProcessor = new MockRemotingProcessor( + RegisterRMResponse.class,this); + super.registerProcessor(MessageType.TYPE_REG_RM, regRmProcessor, messageExecutor); + // 4. registry tm message processor + MockRemotingProcessor regTmProcessor = new MockRemotingProcessor( + RegisterTMResponse.class,this); + super.registerProcessor(MessageType.TYPE_REG_CLT, regTmProcessor, null); + // 5. registry heartbeat message processor + ServerHeartbeatProcessor heartbeatMessageProcessor = new ServerHeartbeatProcessor(this); + super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, heartbeatMessageProcessor, null); + } + + @Override + public void destroy() { + super.destroy(); + } +} diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java index a82df504644..bdbc6092162 100644 --- a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java +++ b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java @@ -3,9 +3,12 @@ import io.netty.channel.Channel; import io.netty.util.concurrent.EventExecutorGroup; import io.seata.core.protocol.AbstractMessage; +import io.seata.core.protocol.MessageType; import io.seata.core.rpc.netty.AbstractNettyRemotingClient; import io.seata.core.rpc.netty.NettyClientConfig; import io.seata.core.rpc.netty.NettyPoolKey; +import io.seata.core.rpc.processor.client.ClientHeartbeatProcessor; +import io.seata.core.rpc.processor.client.ClientOnResponseProcessor; import io.seata.mock.protocol.MockNettyClient; import java.util.concurrent.ThreadPoolExecutor; @@ -22,5 +25,22 @@ public MockTmClient(NettyClientConfig nettyClientConfig, EventExecutorGroup even super(nettyClientConfig, eventExecutorGroup, messageExecutor, transactionRole); } - + @Override + public void init() { + super.init(); + // 1.registry TC response processor + ClientOnResponseProcessor onResponseProcessor = + new ClientOnResponseProcessor(mergeMsgMap, super.getFutures(), getTransactionMessageHandler()); + super.registerProcessor(MessageType.TYPE_SEATA_MERGE_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_GLOBAL_BEGIN_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_GLOBAL_COMMIT_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_GLOBAL_REPORT_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_GLOBAL_ROLLBACK_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_GLOBAL_STATUS_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_REG_CLT_RESULT, onResponseProcessor, null); + super.registerProcessor(MessageType.TYPE_BATCH_RESULT_MSG, onResponseProcessor, null); + // 2.registry heartbeat message processor + ClientHeartbeatProcessor clientHeartbeatProcessor = new ClientHeartbeatProcessor(); + super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, clientHeartbeatProcessor, null); + } } From a2fe4832812cfe2c351294c778b949c747b0fb97 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 15 Nov 2023 15:06:15 +0800 Subject: [PATCH 15/22] classloader-version fix --- .../core/rpc/netty/AbstractNettyRemoting.java | 18 ++++++++++++++---- .../rpc/netty/AbstractNettyRemotingClient.java | 9 ++++----- .../rpc/netty/AbstractNettyRemotingServer.java | 3 ++- .../core/rpc/netty/ProtocolRpcMessage.java | 18 ++++++++++++++++++ .../rpc/netty/v0/ProtocolRpcMessageV0.java | 2 ++ .../rpc/netty/v1/ProtocolRpcMessageV1.java | 5 ++++- .../serializer/seata/SeataSerializer.java | 2 +- 7 files changed, 45 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java index b5571bc0a31..db97fd13237 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemoting.java @@ -64,7 +64,7 @@ public abstract class AbstractNettyRemoting implements Disposable { * The Timer executor. */ protected final ScheduledExecutorService timerExecutor = new ScheduledThreadPoolExecutor(1, - new NamedThreadFactory("timeoutChecker", 1, true)); + new NamedThreadFactory("timeoutChecker", 1, true)); /** * The Message executor. */ @@ -114,7 +114,7 @@ public void run() { futures.remove(entry.getKey()); RpcMessage rpcMessage = future.getRequestMessage(); future.setResultMessage(new TimeoutException(String - .format("msgId: %s ,msgType: %s ,msg: %s ,request timeout", rpcMessage.getId(), String.valueOf(rpcMessage.getMessageType()), rpcMessage.getBody().toString()))); + .format("msgId: %s ,msgType: %s ,msg: %s ,request timeout", rpcMessage.getId(), String.valueOf(rpcMessage.getMessageType()), rpcMessage.getBody().toString()))); if (LOGGER.isDebugEnabled()) { LOGGER.debug("timeout clear future: {}", entry.getValue().getRequestMessage().getBody()); } @@ -201,7 +201,7 @@ protected Object sendSync(Channel channel, RpcMessage rpcMessage, long timeoutMi return result; } catch (Exception exx) { LOGGER.error("wait response error:{},ip:{},request:{}", exx.getMessage(), channel.remoteAddress(), - rpcMessage.getBody()); + rpcMessage.getBody()); if (exx instanceof TimeoutException) { throw (TimeoutException) exx; } else { @@ -220,7 +220,7 @@ protected void sendAsync(Channel channel, RpcMessage rpcMessage) { channelWritableCheck(channel, rpcMessage.getBody()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("write message:" + rpcMessage.getBody() + ", channel:" + channel + ",active?" - + channel.isActive() + ",writable?" + channel.isWritable() + ",isopen?" + channel.isOpen()); + + channel.isActive() + ",writable?" + channel.isWritable() + ",isopen?" + channel.isOpen()); } doBeforeRpcHooks(ChannelUtil.getAddressFromChannel(channel), rpcMessage); @@ -231,6 +231,11 @@ protected void sendAsync(Channel channel, RpcMessage rpcMessage) { } }); } + + protected RpcMessage buildRequestMessage(Object msg, byte messageType) { + return buildRequestMessage(msg, messageType, Version.getCurrent()); + } + protected RpcMessage buildRequestMessage(Object msg, byte messageType, String version) { RpcMessage rpcMessage = new RpcMessage(); rpcMessage.setId(getNextMessageId()); @@ -243,12 +248,17 @@ protected RpcMessage buildRequestMessage(Object msg, byte messageType, String ve } protected RpcMessage buildResponseMessage(RpcMessage rpcMessage, Object msg, byte messageType) { + return buildResponseMessage(rpcMessage, msg, messageType, Version.getCurrent()); + } + + protected RpcMessage buildResponseMessage(RpcMessage rpcMessage, Object msg, byte messageType, String version) { RpcMessage rpcMsg = new RpcMessage(); rpcMsg.setMessageType(messageType); rpcMsg.setCodec(rpcMessage.getCodec()); // same with request rpcMsg.setCompressor(rpcMessage.getCompressor()); rpcMsg.setBody(msg); rpcMsg.setId(rpcMessage.getId()); + rpcMsg.setVersion(version); return rpcMsg; } diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java index d6ba3dc37a5..1bc47fd2a8f 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingClient.java @@ -49,7 +49,6 @@ import io.seata.core.protocol.MessageFuture; import io.seata.core.protocol.ProtocolConstants; import io.seata.core.protocol.RpcMessage; -import io.seata.core.protocol.Version; import io.seata.core.protocol.transaction.AbstractGlobalEndRequest; import io.seata.core.protocol.transaction.BranchRegisterRequest; import io.seata.core.protocol.transaction.BranchReportRequest; @@ -134,7 +133,7 @@ public AbstractNettyRemotingClient(NettyClientConfig nettyClientConfig, EventExe public Object sendSyncRequest(Object msg) throws TimeoutException { String serverAddress = loadBalance(getTransactionServiceGroup(), msg); long timeoutMillis = this.getRpcRequestTimeout(); - RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC, Version.getCurrent()); + RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC); // send batch message // put message into basketMap, @see MergedSendRunnable @@ -187,7 +186,7 @@ public Object sendSyncRequest(Channel channel, Object msg) throws TimeoutExcepti LOGGER.warn("sendSyncRequest nothing, caused by null channel."); return null; } - RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC, Version.getCurrent()); + RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC); return super.sendSync(channel, rpcMessage, this.getRpcRequestTimeout()); } @@ -198,8 +197,8 @@ public void sendAsyncRequest(Channel channel, Object msg) { return; } RpcMessage rpcMessage = buildRequestMessage(msg, msg instanceof HeartbeatMessage - ? ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST - : ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY, Version.getCurrent()); + ? ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST + : ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY); if (rpcMessage.getBody() instanceof MergeMessage) { mergeMsgMap.put(rpcMessage.getId(), (MergeMessage) rpcMessage.getBody()); } diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java index 5e7c2740804..b84f8fc936b 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java @@ -103,9 +103,10 @@ public void sendAsyncResponse(RpcMessage rpcMessage, Channel channel, Object msg clientChannel = ChannelManager.getSameClientChannel(channel); } if (clientChannel != null) { + RpcContext rpcContext = ChannelManager.getContextFromIdentified(channel); RpcMessage rpcMsg = buildResponseMessage(rpcMessage, msg, msg instanceof HeartbeatMessage ? ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE - : ProtocolConstants.MSGTYPE_RESPONSE); + : ProtocolConstants.MSGTYPE_RESPONSE, rpcContext.getVersion()); super.sendAsync(clientChannel, rpcMsg); } else { throw new RuntimeException("channel is error."); diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java index 7cfe882b661..712128a8b7e 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java @@ -15,6 +15,7 @@ */ package io.seata.core.rpc.netty; +import io.seata.core.protocol.AbstractIdentifyRequest; import io.seata.core.protocol.RpcMessage; /** @@ -26,4 +27,21 @@ public interface ProtocolRpcMessage { RpcMessage protocolMsg2RpcMsg(); void rpcMsg2ProtocolMsg(RpcMessage rpcMessage); + + static String getVersion(Object body) { + if(body instanceof AbstractIdentifyRequest){ + return ((AbstractIdentifyRequest) body).getVersion(); + }else { + //todo? + return null; + } + } + + static void setVersion(Object body, String version){ + if(body instanceof AbstractIdentifyRequest){ + ((AbstractIdentifyRequest) body).setVersion(version); + }else { + //todo? + } + } } diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java index 5d926b1f74c..cafe52d0694 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java @@ -180,12 +180,14 @@ public RpcMessage protocolMsg2RpcMsg(){ } rpcMessage.setBody(this.body); rpcMessage.setId((int) this.id); + rpcMessage.setVersion(ProtocolRpcMessage.getVersion(this.body)); return rpcMessage; } @Override public void rpcMsg2ProtocolMsg(RpcMessage rpcMessage) { this.body = rpcMessage.getBody(); + ProtocolRpcMessage.setVersion(this.body, rpcMessage.getVersion()); this.id = rpcMessage.getId(); this.isRequest = isRequest(rpcMessage.getMessageType()); this.isHeartbeat = isHeartbeat(rpcMessage.getMessageType()); diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java index 639ee76de69..7d95937b9b0 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java @@ -16,6 +16,7 @@ package io.seata.core.rpc.netty.v1; import io.seata.common.util.StringUtils; +import io.seata.core.protocol.AbstractIdentifyRequest; import io.seata.core.protocol.RpcMessage; import io.seata.core.rpc.netty.ProtocolRpcMessage; @@ -182,17 +183,19 @@ public RpcMessage protocolMsg2RpcMsg(){ rpcMessage.setCompressor(this.compressor); rpcMessage.setHeadMap(this.headMap); rpcMessage.setBody(this.body); + rpcMessage.setVersion(ProtocolRpcMessage.getVersion(this.body)); return rpcMessage; } + @Override public void rpcMsg2ProtocolMsg(RpcMessage rpcMessage) { this.body = rpcMessage.getBody(); + ProtocolRpcMessage.setVersion(this.body, rpcMessage.getVersion()); this.headMap = rpcMessage.getHeadMap(); this.id = rpcMessage.getId(); this.messageType = rpcMessage.getMessageType(); this.codec = rpcMessage.getCodec(); this.compressor = rpcMessage.getCompressor(); - rpcMessage.getVersion(); } } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java index 4957f30c329..e77f94a1582 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java @@ -42,7 +42,7 @@ public class SeataSerializer implements Serializer { .put(ProtocolConstants.VERSION_1, new MessageCodecFactoryV1()) .build(); - public SeataSerializer(byte version){ + public SeataSerializer(Byte version){ factory = FACTORY_MAP.get(version); protocolVersion = version; } From be10f07175691187c350c9138c4ff713c599ff50 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 15 Nov 2023 16:11:08 +0800 Subject: [PATCH 16/22] fix test and format --- .../java/io/seata/core/protocol/Version.java | 4 +-- .../rpc/netty/CompatibleProtocolDecoder.java | 2 +- .../rpc/netty/CompatibleProtocolEncoder.java | 4 +-- .../netty/CompatibleProtocolVersionMap.java | 16 ---------- .../core/rpc/netty/ProtocolRpcMessage.java | 12 +++---- .../rpc/netty/v0/ProtocolRpcMessageV0.java | 31 ++++++++++--------- .../serializer/SerializerServiceLoader.java | 2 +- .../BatchResultMessageSerializerTest.java | 4 +-- .../MergeResultMessageSerializerTest.java | 4 +-- .../MergedWarpMessageSerializerTest.java | 4 +-- .../RegisterRMRequestSerializerTest.java | 4 +-- .../RegisterRMResponseSerializerTest.java | 4 +-- .../RegisterTMRequestSerializerTest.java | 4 +-- .../RegisterTMResponseSerializerTest.java | 4 +-- .../BranchCommitRequestSerializerTest.java | 4 +-- .../BranchCommitResponseSerializerTest.java | 4 +-- .../BranchRegisterRequestSerializerTest.java | 4 +-- .../BranchRegisterResponseSerializerTest.java | 4 +-- .../BranchReportRequestSerializerTest.java | 4 +-- .../BranchReportResponseSerializerTest.java | 4 +-- .../BranchRollbackRequestSerializerTest.java | 4 +-- .../BranchRollbackResponseSerializerTest.java | 4 +-- .../GlobalBeginRequestSerializerTest.java | 4 +-- .../GlobalBeginResponseSerializerTest.java | 4 +-- .../GlobalCommitRequestCodecTest.java | 4 +-- .../GlobalCommitResponseSerializerTest.java | 4 +-- .../GlobalLockQueryRequestSerializerTest.java | 4 +-- ...GlobalLockQueryResponseSerializerTest.java | 4 +-- .../GlobalRollbackRequestCodecTest.java | 4 +-- .../GlobalRollbackResponseSerializerTest.java | 4 +-- .../GlobalStatusRequestCodecTest.java | 4 +-- .../GlobalStatusResponseSerializerTest.java | 4 +-- .../UndoLogDeleteRequestSerializerTest.java | 4 +-- 33 files changed, 79 insertions(+), 96 deletions(-) delete mode 100644 core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolVersionMap.java diff --git a/core/src/main/java/io/seata/core/protocol/Version.java b/core/src/main/java/io/seata/core/protocol/Version.java index bdf77b26e3e..9a629e2c00a 100644 --- a/core/src/main/java/io/seata/core/protocol/Version.java +++ b/core/src/main/java/io/seata/core/protocol/Version.java @@ -89,9 +89,7 @@ public static void checkVersion(String version) throws IncompatibleVersionExcept long current = convertVersion(CURRENT); long clientVersion = convertVersion(version); long divideVersion = convertVersion(VERSION_0_7_1); - if ( -// (current > divideVersion && clientVersion < divideVersion) || - (current < divideVersion && clientVersion > divideVersion)) { + if (current < divideVersion && clientVersion > divideVersion) { throw new IncompatibleVersionException("incompatible client version:" + version); } } diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java index db859581dda..7865b6dd6bc 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolDecoder.java @@ -103,7 +103,7 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception } return decoder.decodeFrame(frame); } finally { - if(!isV0(version)){ + if (!isV0(version)) { frame.release(); } } diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java index 4142375bf3d..49bee28311a 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java +++ b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolEncoder.java @@ -48,7 +48,7 @@ public class CompatibleProtocolEncoder extends MessageToByteEncoder { private static Map protocolEncoderMap; - public CompatibleProtocolEncoder(){ + public CompatibleProtocolEncoder() { super(); protocolEncoderMap = ImmutableMap.builder() .put(ProtocolConstants.VERSION_0, new ProtocolEncoderV0()) @@ -67,7 +67,7 @@ public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) { throw new IllegalArgumentException("Unknown version: " + version); } - encoder.encode(rpcMessage,out); + encoder.encode(rpcMessage, out); } else { throw new UnsupportedOperationException("Not support this class:" + msg.getClass()); } diff --git a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolVersionMap.java b/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolVersionMap.java deleted file mode 100644 index 8e39abb4ccd..00000000000 --- a/core/src/main/java/io/seata/core/rpc/netty/CompatibleProtocolVersionMap.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.seata.core.rpc.netty; - -import io.seata.core.protocol.IncompatibleVersionException; -import io.seata.core.protocol.ProtocolConstants; -import io.seata.core.protocol.Version; - -/** - * ? - * - * @author Bughue - * @date 2023/9/20 - **/ -public class CompatibleProtocolVersionMap { - - -} diff --git a/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java b/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java index 712128a8b7e..45895b677a1 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java +++ b/core/src/main/java/io/seata/core/rpc/netty/ProtocolRpcMessage.java @@ -29,18 +29,18 @@ public interface ProtocolRpcMessage { void rpcMsg2ProtocolMsg(RpcMessage rpcMessage); static String getVersion(Object body) { - if(body instanceof AbstractIdentifyRequest){ - return ((AbstractIdentifyRequest) body).getVersion(); - }else { + if (body instanceof AbstractIdentifyRequest) { + return ((AbstractIdentifyRequest) body).getVersion(); + } else { //todo? return null; } } - static void setVersion(Object body, String version){ - if(body instanceof AbstractIdentifyRequest){ + static void setVersion(Object body, String version) { + if (body instanceof AbstractIdentifyRequest) { ((AbstractIdentifyRequest) body).setVersion(version); - }else { + } else { //todo? } } diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java index cafe52d0694..ac0a8d319f0 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolRpcMessageV0.java @@ -157,24 +157,24 @@ public void setMessageType(byte messageType) { } @Override - public RpcMessage protocolMsg2RpcMsg(){ + public RpcMessage protocolMsg2RpcMsg() { RpcMessage rpcMessage = new RpcMessage(); rpcMessage.setMessageType(this.messageType); rpcMessage.setCompressor(CompressorType.NONE.getCode()); - byte codecType = this.isSeataCodec? SerializerType.SEATA.getCode():SerializerType.HESSIAN.getCode(); + byte codecType = this.isSeataCodec ? SerializerType.SEATA.getCode() : SerializerType.HESSIAN.getCode(); rpcMessage.setCodec(codecType); - if(this.isHeartbeat){ - if(this.isRequest){ + if (this.isHeartbeat) { + if (this.isRequest) { rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST); - }else { + } else { rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE); } - }else { - if(this.isRequest){ + } else { + if (this.isRequest) { rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY); - }else { + } else { rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESPONSE); } } @@ -191,16 +191,17 @@ public void rpcMsg2ProtocolMsg(RpcMessage rpcMessage) { this.id = rpcMessage.getId(); this.isRequest = isRequest(rpcMessage.getMessageType()); this.isHeartbeat = isHeartbeat(rpcMessage.getMessageType()); - this.isSeataCodec = rpcMessage.getCodec() ==SerializerType.SEATA.getCode(); + this.isSeataCodec = rpcMessage.getCodec() == SerializerType.SEATA.getCode(); this.messageType = rpcMessage.getMessageType(); } - private boolean isHeartbeat(byte msgType){ - return msgType==ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST - || msgType ==ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE; + private boolean isHeartbeat(byte msgType) { + return msgType == ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST + || msgType == ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE; } - private boolean isRequest(byte msgType){ - return msgType==ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY - || msgType ==ProtocolConstants.MSGTYPE_RESQUEST_SYNC; + + private boolean isRequest(byte msgType) { + return msgType == ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY + || msgType == ProtocolConstants.MSGTYPE_RESQUEST_SYNC; } } diff --git a/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java b/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java index caa7e2bc630..78161048046 100644 --- a/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java +++ b/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java @@ -50,7 +50,7 @@ public static Serializer load(SerializerType type, byte version) throws Enhanced } if (type == SerializerType.SEATA) { return EnhancedServiceLoader.load(Serializer.class, type.name(), new Object[]{version}); - }else { + } else { return EnhancedServiceLoader.load(Serializer.class, type.name()); } } diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java index 1d8219991db..c102342f71a 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java @@ -23,7 +23,7 @@ import io.seata.core.protocol.BatchResultMessage; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.BranchCommitResponse; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -39,7 +39,7 @@ public class BatchResultMessageSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); @Test diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java index 891f602147e..5e9fff4a211 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java @@ -15,12 +15,12 @@ */ package io.seata.serializer.seata.protocol; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.AbstractResultMessage; import io.seata.core.protocol.MergeResultMessage; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.GlobalBeginResponse; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -35,7 +35,7 @@ public class MergeResultMessageSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java index 546ead2fdc5..3e0fc3b7994 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java @@ -21,7 +21,7 @@ import io.seata.core.protocol.AbstractMessage; import io.seata.core.protocol.MergedWarpMessage; import io.seata.core.protocol.transaction.GlobalBeginRequest; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -37,7 +37,7 @@ public class MergedWarpMessageSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java index 13d3182aadc..c2c27b06228 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java @@ -15,8 +15,8 @@ */ package io.seata.serializer.seata.protocol; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.RegisterRMRequest; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -31,7 +31,7 @@ public class RegisterRMRequestSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java index b82e58f84e6..8b58f9f44e9 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java @@ -15,9 +15,9 @@ */ package io.seata.serializer.seata.protocol; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.RegisterRMResponse; import io.seata.core.protocol.ResultCode; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -33,7 +33,7 @@ public class RegisterRMResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java index 672c946aafe..99ed2a61374 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java @@ -16,9 +16,9 @@ package io.seata.serializer.seata.protocol; import io.netty.buffer.ByteBuf; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.AbstractIdentifyRequest; import io.seata.core.protocol.RegisterTMRequest; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -37,7 +37,7 @@ public class RegisterTMRequestSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); private static RegisterTMRequest registerTMRequest; private static AbstractIdentifyRequest air; diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java index d018d4f03b2..a2a968e296c 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java @@ -15,9 +15,9 @@ */ package io.seata.serializer.seata.protocol; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.RegisterTMResponse; import io.seata.core.protocol.ResultCode; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +32,7 @@ public class RegisterTMResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java index bc6cc7a97ba..8cadec8fb41 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchCommitRequest; import org.junit.jupiter.api.Test; @@ -32,7 +32,7 @@ public class BranchCommitRequestSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java index 9645ca36bde..7ed87e201b3 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.BranchStatus; import io.seata.core.protocol.ResultCode; @@ -34,7 +34,7 @@ public class BranchCommitResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java index f8897b984ab..81e844f4d8b 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchRegisterRequest; import org.junit.jupiter.api.Test; @@ -32,7 +32,7 @@ public class BranchRegisterRequestSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java index a239420fa3b..23a277daa9c 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.BranchRegisterResponse; @@ -33,7 +33,7 @@ public class BranchRegisterResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java index 8ff6bbfa7e2..fb8fcd00c82 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.model.BranchStatus; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchReportRequest; @@ -33,7 +33,7 @@ public class BranchReportRequestSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java index 1f810655a58..41140639c5a 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.BranchReportResponse; @@ -33,7 +33,7 @@ public class BranchReportResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java index f49b14c7bc2..41ad6db2cdf 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchRollbackRequest; import org.junit.jupiter.api.Test; @@ -32,7 +32,7 @@ public class BranchRollbackRequestSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java index 3a75972cb1c..8276be9dad6 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.BranchStatus; import io.seata.core.protocol.ResultCode; @@ -34,7 +34,7 @@ public class BranchRollbackResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java index 0f9f4badced..4167ed2a929 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.transaction.GlobalBeginRequest; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public class GlobalBeginRequestSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java index c5a6efabd24..cc2ec27675c 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.GlobalBeginResponse; @@ -32,7 +32,7 @@ public class GlobalBeginResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java index cbfc8eb0582..885568ff46b 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.transaction.GlobalCommitRequest; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public class GlobalCommitRequestCodecTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java index d54ca92de56..310a5cfc52f 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.GlobalStatus; import io.seata.core.protocol.ResultCode; @@ -33,7 +33,7 @@ public class GlobalCommitResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java index 446746644c3..2a1ac53e925 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.GlobalLockQueryRequest; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public class GlobalLockQueryRequestSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java index 9456b6dd58b..706197808b5 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.GlobalLockQueryResponse; @@ -33,7 +33,7 @@ public class GlobalLockQueryResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java index 1b493c99796..06a54065855 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.transaction.GlobalRollbackRequest; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public class GlobalRollbackRequestCodecTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java index 2ac992dd8ff..cd8849e6f41 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.GlobalStatus; import io.seata.core.protocol.ResultCode; @@ -34,7 +34,7 @@ public class GlobalRollbackResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java index d3b0804f89b..37f52de98e3 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.transaction.GlobalStatusRequest; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public class GlobalStatusRequestCodecTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java index 2d67d80ff7e..cc2cba4f460 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.GlobalStatus; import io.seata.core.protocol.ResultCode; @@ -33,7 +33,7 @@ public class GlobalStatusResponseSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java index 444f3281115..742efe229cc 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java @@ -15,7 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; -import io.seata.serializer.seata.protocol.v1.SeataV1Serializer; +import io.seata.serializer.seata.SeataSerializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.UndoLogDeleteRequest; import org.junit.jupiter.api.Test; @@ -32,7 +32,7 @@ public class UndoLogDeleteRequestSerializerTest { /** * The Seata codec. */ - SeataV1Serializer seataSerializer = new SeataV1Serializer(); + SeataSerializer seataSerializer = new SeataSerializer(); /** * Test codec. From 8577d01732d916c35fa9d9db5d45e7a2151b0a23 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 15 Nov 2023 16:17:10 +0800 Subject: [PATCH 17/22] test fix --- .../seata/protocol/BatchResultMessageSerializerTest.java | 3 ++- .../seata/protocol/MergeResultMessageSerializerTest.java | 3 ++- .../seata/protocol/MergedWarpMessageSerializerTest.java | 3 ++- .../seata/protocol/RegisterRMRequestSerializerTest.java | 3 ++- .../seata/protocol/RegisterRMResponseSerializerTest.java | 3 ++- .../seata/protocol/RegisterTMRequestSerializerTest.java | 3 ++- .../seata/protocol/RegisterTMResponseSerializerTest.java | 3 ++- .../transaction/BranchCommitRequestSerializerTest.java | 3 ++- .../transaction/BranchCommitResponseSerializerTest.java | 3 ++- .../transaction/BranchRegisterRequestSerializerTest.java | 3 ++- .../transaction/BranchRegisterResponseSerializerTest.java | 3 ++- .../transaction/BranchReportRequestSerializerTest.java | 3 ++- .../transaction/BranchReportResponseSerializerTest.java | 3 ++- .../transaction/BranchRollbackRequestSerializerTest.java | 3 ++- .../transaction/BranchRollbackResponseSerializerTest.java | 3 ++- .../protocol/transaction/GlobalBeginRequestSerializerTest.java | 3 ++- .../transaction/GlobalBeginResponseSerializerTest.java | 3 ++- .../protocol/transaction/GlobalCommitRequestCodecTest.java | 3 ++- .../transaction/GlobalCommitResponseSerializerTest.java | 3 ++- .../transaction/GlobalLockQueryRequestSerializerTest.java | 3 ++- .../transaction/GlobalLockQueryResponseSerializerTest.java | 3 ++- .../protocol/transaction/GlobalRollbackRequestCodecTest.java | 3 ++- .../transaction/GlobalRollbackResponseSerializerTest.java | 3 ++- .../protocol/transaction/GlobalStatusRequestCodecTest.java | 3 ++- .../transaction/GlobalStatusResponseSerializerTest.java | 3 ++- .../transaction/UndoLogDeleteRequestSerializerTest.java | 3 ++- 26 files changed, 52 insertions(+), 26 deletions(-) diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java index c102342f71a..2b45f775c1f 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/BatchResultMessageSerializerTest.java @@ -24,6 +24,7 @@ import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.BranchCommitResponse; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -39,7 +40,7 @@ public class BatchResultMessageSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); @Test diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java index 5e9fff4a211..c99e215ad74 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergeResultMessageSerializerTest.java @@ -15,6 +15,7 @@ */ package io.seata.serializer.seata.protocol; +import io.seata.core.protocol.ProtocolConstants; import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.AbstractResultMessage; @@ -35,7 +36,7 @@ public class MergeResultMessageSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java index 3e0fc3b7994..fb6867ff3f3 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/MergedWarpMessageSerializerTest.java @@ -22,6 +22,7 @@ import io.seata.core.protocol.MergedWarpMessage; import io.seata.core.protocol.transaction.GlobalBeginRequest; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -37,7 +38,7 @@ public class MergedWarpMessageSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java index c2c27b06228..d15d99487d1 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMRequestSerializerTest.java @@ -15,6 +15,7 @@ */ package io.seata.serializer.seata.protocol; +import io.seata.core.protocol.ProtocolConstants; import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.RegisterRMRequest; import org.junit.jupiter.api.Test; @@ -31,7 +32,7 @@ public class RegisterRMRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java index 8b58f9f44e9..3097f1092e3 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterRMResponseSerializerTest.java @@ -15,6 +15,7 @@ */ package io.seata.serializer.seata.protocol; +import io.seata.core.protocol.ProtocolConstants; import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.RegisterRMResponse; import io.seata.core.protocol.ResultCode; @@ -33,7 +34,7 @@ public class RegisterRMResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java index 99ed2a61374..45ff9f76cd0 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMRequestSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol; import io.netty.buffer.ByteBuf; +import io.seata.core.protocol.ProtocolConstants; import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.AbstractIdentifyRequest; import io.seata.core.protocol.RegisterTMRequest; @@ -37,7 +38,7 @@ public class RegisterTMRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); private static RegisterTMRequest registerTMRequest; private static AbstractIdentifyRequest air; diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java index a2a968e296c..4414e6409d8 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/RegisterTMResponseSerializerTest.java @@ -15,6 +15,7 @@ */ package io.seata.serializer.seata.protocol; +import io.seata.core.protocol.ProtocolConstants; import io.seata.serializer.seata.SeataSerializer; import io.seata.core.protocol.RegisterTMResponse; import io.seata.core.protocol.ResultCode; @@ -32,7 +33,7 @@ public class RegisterTMResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java index 8cadec8fb41..856c6523498 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitRequestSerializerTest.java @@ -15,6 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; +import io.seata.core.protocol.ProtocolConstants; import io.seata.serializer.seata.SeataSerializer; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchCommitRequest; @@ -32,7 +33,7 @@ public class BranchCommitRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java index 7ed87e201b3..04c745f250a 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchCommitResponseSerializerTest.java @@ -15,6 +15,7 @@ */ package io.seata.serializer.seata.protocol.transaction; +import io.seata.core.protocol.ProtocolConstants; import io.seata.serializer.seata.SeataSerializer; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.BranchStatus; @@ -34,7 +35,7 @@ public class BranchCommitResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java index 81e844f4d8b..c591745549f 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterRequestSerializerTest.java @@ -19,6 +19,7 @@ import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchRegisterRequest; import org.junit.jupiter.api.Test; +import io.seata.core.protocol.ProtocolConstants; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +33,7 @@ public class BranchRegisterRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java index 23a277daa9c..b49445124f8 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRegisterResponseSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.BranchRegisterResponse; @@ -33,7 +34,7 @@ public class BranchRegisterResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java index fb8fcd00c82..2a707c83d16 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportRequestSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.model.BranchStatus; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchReportRequest; @@ -33,7 +34,7 @@ public class BranchReportRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java index 41140639c5a..9db8725c96f 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchReportResponseSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.BranchReportResponse; @@ -33,7 +34,7 @@ public class BranchReportResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java index 41ad6db2cdf..881026a1d7e 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackRequestSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.BranchRollbackRequest; import org.junit.jupiter.api.Test; @@ -32,7 +33,7 @@ public class BranchRollbackRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java index 8276be9dad6..c4b2576cea9 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/BranchRollbackResponseSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.BranchStatus; import io.seata.core.protocol.ResultCode; @@ -34,7 +35,7 @@ public class BranchRollbackResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java index 4167ed2a929..7d1eac32059 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginRequestSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.protocol.transaction.GlobalBeginRequest; import org.junit.jupiter.api.Test; @@ -31,7 +32,7 @@ public class GlobalBeginRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java index cc2ec27675c..1fccf739f99 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalBeginResponseSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.GlobalBeginResponse; @@ -32,7 +33,7 @@ public class GlobalBeginResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java index 885568ff46b..5dba1f8d5cd 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitRequestCodecTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.protocol.transaction.GlobalCommitRequest; import org.junit.jupiter.api.Test; @@ -31,7 +32,7 @@ public class GlobalCommitRequestCodecTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java index 310a5cfc52f..0cbae829bfc 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalCommitResponseSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.GlobalStatus; import io.seata.core.protocol.ResultCode; @@ -33,7 +34,7 @@ public class GlobalCommitResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java index 2a1ac53e925..d1b5428bd47 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryRequestSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.GlobalLockQueryRequest; import org.junit.jupiter.api.Test; @@ -31,7 +32,7 @@ public class GlobalLockQueryRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java index 706197808b5..491be34f16b 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalLockQueryResponseSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.protocol.ResultCode; import io.seata.core.protocol.transaction.GlobalLockQueryResponse; @@ -33,7 +34,7 @@ public class GlobalLockQueryResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java index 06a54065855..03a8db4eb3c 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackRequestCodecTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.protocol.transaction.GlobalRollbackRequest; import org.junit.jupiter.api.Test; @@ -31,7 +32,7 @@ public class GlobalRollbackRequestCodecTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java index cd8849e6f41..56a383a9e3e 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalRollbackResponseSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.GlobalStatus; import io.seata.core.protocol.ResultCode; @@ -34,7 +35,7 @@ public class GlobalRollbackResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java index 37f52de98e3..a63f4a5f549 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusRequestCodecTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.protocol.transaction.GlobalStatusRequest; import org.junit.jupiter.api.Test; @@ -31,7 +32,7 @@ public class GlobalStatusRequestCodecTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java index cc2cba4f460..1320be5bcb7 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/GlobalStatusResponseSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.GlobalStatus; import io.seata.core.protocol.ResultCode; @@ -33,7 +34,7 @@ public class GlobalStatusResponseSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. diff --git a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java index 742efe229cc..808353addd1 100644 --- a/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java +++ b/serializer/seata-serializer-seata/src/test/java/io/seata/serializer/seata/protocol/transaction/UndoLogDeleteRequestSerializerTest.java @@ -16,6 +16,7 @@ package io.seata.serializer.seata.protocol.transaction; import io.seata.serializer.seata.SeataSerializer; +import io.seata.core.protocol.ProtocolConstants; import io.seata.core.model.BranchType; import io.seata.core.protocol.transaction.UndoLogDeleteRequest; import org.junit.jupiter.api.Test; @@ -32,7 +33,7 @@ public class UndoLogDeleteRequestSerializerTest { /** * The Seata codec. */ - SeataSerializer seataSerializer = new SeataSerializer(); + SeataSerializer seataSerializer = new SeataSerializer(ProtocolConstants.VERSION_1); /** * Test codec. From e0bf2d0e795b06ae5f2273193d18bd84a6a8d4af Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Thu, 16 Nov 2023 17:30:37 +0800 Subject: [PATCH 18/22] code style --- core/src/main/java/io/seata/core/protocol/Version.java | 2 +- .../seata/core/rpc/netty/AbstractNettyRemotingServer.java | 2 +- .../java/io/seata/core/rpc/netty/v0/MessageCodecV0.java | 6 ++---- .../java/io/seata/core/rpc/netty/v0/ProtocolEncoderV0.java | 6 +++--- .../io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java | 4 +--- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/io/seata/core/protocol/Version.java b/core/src/main/java/io/seata/core/protocol/Version.java index 9a629e2c00a..01d9dc7db4f 100644 --- a/core/src/main/java/io/seata/core/protocol/Version.java +++ b/core/src/main/java/io/seata/core/protocol/Version.java @@ -155,7 +155,7 @@ public static byte calcProtocolVersion(String sdkVersion) throws IncompatibleVer long v0 = convertVersion(VERSION_0_7_1); if (version <= v0) { return ProtocolConstants.VERSION_0; - }else { + } else { return ProtocolConstants.VERSION_1; } } diff --git a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java index b84f8fc936b..e67232cd62b 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java +++ b/core/src/main/java/io/seata/core/rpc/netty/AbstractNettyRemotingServer.java @@ -173,7 +173,7 @@ public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exce if (msg instanceof ProtocolRpcMessage) { rpcMessage = ((ProtocolRpcMessage) msg).protocolMsg2RpcMsg(); processMessage(ctx, rpcMessage); - }else { + } else { LOGGER.error("rpcMessage type error"); } } diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java b/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java index da241f2666a..19217333f42 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/MessageCodecV0.java @@ -16,15 +16,13 @@ package io.seata.core.rpc.netty.v0; import io.netty.buffer.ByteBuf; -import io.seata.core.protocol.AbstractIdentifyRequest; -import io.seata.core.protocol.AbstractMessage; import io.seata.core.protocol.MessageTypeAware; /** * The interface Message codec. * - * @author jimin.jm @alibaba-inc.com - * @date 2018 /9/14 + * @author Bughue + * @date 2023/11/01 */ public interface MessageCodecV0 extends MessageTypeAware { diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolEncoderV0.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolEncoderV0.java index 5c1cf3f05de..d64f9ac24d5 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolEncoderV0.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolEncoderV0.java @@ -84,12 +84,12 @@ public void encode(RpcMessage message, ByteBuf out) { Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codec), ProtocolConstants.VERSION_0); bodyBytes = serializer.serialize(msg.getBody()); - if(msg.isSeataCodec()){ - if(msg.getBody() instanceof MessageTypeAware){ + if (msg.isSeataCodec()) { + if (msg.getBody() instanceof MessageTypeAware) { short typeCode = ((MessageTypeAware) msg.getBody()).getTypeCode(); out.writeShort(typeCode); } - }else { + } else { out.writeShort(bodyBytes.length); } out.writeLong(msg.getId()); diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java index 7d95937b9b0..d6778f31296 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolRpcMessageV1.java @@ -16,7 +16,6 @@ package io.seata.core.rpc.netty.v1; import io.seata.common.util.StringUtils; -import io.seata.core.protocol.AbstractIdentifyRequest; import io.seata.core.protocol.RpcMessage; import io.seata.core.rpc.netty.ProtocolRpcMessage; @@ -30,7 +29,6 @@ * @date 2023/8/1 **/ public class ProtocolRpcMessageV1 implements ProtocolRpcMessage { - private int id; private byte messageType; private byte codec; @@ -175,7 +173,7 @@ public String toString() { } @Override - public RpcMessage protocolMsg2RpcMsg(){ + public RpcMessage protocolMsg2RpcMsg() { RpcMessage rpcMessage = new RpcMessage(); rpcMessage.setId(this.id); rpcMessage.setMessageType(this.messageType); From bcec6ca029569ea680e1cd2fa14841dfbd9f3f5d Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Thu, 16 Nov 2023 19:21:49 +0800 Subject: [PATCH 19/22] code style --- .../main/java/io/seata/core/rpc/netty/v0/ProtocolDecoderV0.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolDecoderV0.java b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolDecoderV0.java index e0ea927daa3..44c265b80cd 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolDecoderV0.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v0/ProtocolDecoderV0.java @@ -16,7 +16,6 @@ package io.seata.core.rpc.netty.v0; import io.netty.buffer.ByteBuf; -import io.seata.common.loader.EnhancedServiceLoader; import io.seata.core.protocol.HeartbeatMessage; import io.seata.core.protocol.ProtocolConstants; From 5e5d5d785e4df206c80eb317e8194e2f4432f7a6 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Thu, 30 Nov 2023 14:44:59 +0800 Subject: [PATCH 20/22] classloader-version fix --- .../core/rpc/netty/v1/ProtocolEncoderV1.java | 2 + .../serializer/SerializerServiceLoader.java | 25 +++- .../serializer/seata/MessageCodecFactory.java | 22 ++- .../serializer/seata/SeataSerializer.java | 46 +----- .../protocol/v0/BatchResultMessageCodec.java | 17 ++- .../protocol/v0/MergeResultMessageCodec.java | 17 ++- .../protocol/v0/MergedWarpMessageCodec.java | 17 ++- .../protocol/v0/MessageCodecFactoryV0.java | 3 - .../protocol/v1/MessageCodecFactoryV1.java | 2 +- test-mock/pom.xml | 33 +++++ test-mock/test-client-v0/pom.xml | 55 +++++++ .../java/io/seata/core/rpc.netty/Action1.java | 25 ++++ .../io/seata/core/rpc.netty/Action1Impl.java | 33 +++++ .../seata/core/rpc.netty/MockConstants.java | 24 ++-- .../seata/core/rpc.netty/RmClientTestV0.java | 75 ++++++++++ .../seata/core/rpc.netty/TmClientTestV0.java | 78 ++++++++++ .../src/main/resources/file.conf | 22 +++ .../src/main}/resources/logback.xml | 0 .../src/main/resources/registry.conf | 30 ++++ test-mock/test-client-v1-1.6.0/pom.xml | 38 +++++ .../java/io/seata/core/rpc/netty/Action1.java | 25 ++++ .../io/seata/core/rpc/netty/Action1Impl.java | 33 +++++ .../seata/core/rpc/netty/MockConstants.java | 28 ++++ .../core/rpc/netty/RmClientTestV160.java | 80 +++++++++++ .../core/rpc/netty/TmClientTestV160.java | 75 ++++++++++ .../src/main/resources/file.conf | 21 +++ .../src/main/resources/registry.conf | 30 ++++ test-mock/test-client-v1/pom.xml | 56 ++++++++ .../java/io/seata/core/rpc/netty/Action1.java | 25 ++++ .../io/seata/core/rpc/netty/Action1Impl.java | 35 +++++ .../seata/core/rpc/netty/MockConstants.java | 28 ++++ .../seata/core/rpc/netty/RmClientTestV1.java | 71 ++++++++++ .../seata/core/rpc/netty/TmClientTestV1.java | 75 ++++++++++ .../src/main/resources/file.conf | 21 +++ .../src/main/resources/registry.conf | 30 ++++ .../test-mock-server}/pom.xml | 20 ++- .../io/seata/mockserver/MockCoordinator.java | 134 ++++++++++++++++++ .../mockserver}/MockNettyRemotingServer.java | 67 +++------ .../java/io/seata/mockserver/MockServer.java | 70 +++++++++ .../java/io/seata/mockserver/call/CallRm.java | 106 ++++++++++++++ .../processor/MockHeartbeatProcessor.java | 25 ++++ .../processor/MockOnReqProcessor.java | 78 ++++++++++ .../processor/MockOnRespProcessor.java | 55 +++++++ .../processor/MockRegisterProcessor.java | 78 ++++++++++ .../processor/MockRemotingProcessor.java | 52 +++++++ .../src/main/resources/application.yml | 53 +++++++ .../src/main/resources/logback-spring.xml | 110 ++++++++++++++ .../seata/mock/protocol/MockNettyClient.java | 86 ----------- .../mock/protocol/MockRemotingProcessor.java | 34 ----- .../mock/protocol/rm/v1/MockRmClient.java | 21 --- .../mock/protocol/tm/v1/MockTmClient.java | 46 ------ .../src/test/resources/README.md | 2 - 52 files changed, 1928 insertions(+), 306 deletions(-) create mode 100644 test-mock/pom.xml create mode 100644 test-mock/test-client-v0/pom.xml create mode 100644 test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/Action1.java create mode 100644 test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/Action1Impl.java rename test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockServerApplication.java => test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/MockConstants.java (55%) create mode 100644 test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/RmClientTestV0.java create mode 100644 test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/TmClientTestV0.java create mode 100644 test-mock/test-client-v0/src/main/resources/file.conf rename {test-protocol-mock-server/src/test => test-mock/test-client-v0/src/main}/resources/logback.xml (100%) create mode 100644 test-mock/test-client-v0/src/main/resources/registry.conf create mode 100644 test-mock/test-client-v1-1.6.0/pom.xml create mode 100644 test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/Action1.java create mode 100644 test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/Action1Impl.java create mode 100644 test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/MockConstants.java create mode 100644 test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/RmClientTestV160.java create mode 100644 test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/TmClientTestV160.java create mode 100644 test-mock/test-client-v1-1.6.0/src/main/resources/file.conf create mode 100644 test-mock/test-client-v1-1.6.0/src/main/resources/registry.conf create mode 100644 test-mock/test-client-v1/pom.xml create mode 100644 test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/Action1.java create mode 100644 test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/Action1Impl.java create mode 100644 test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/MockConstants.java create mode 100644 test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/RmClientTestV1.java create mode 100644 test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/TmClientTestV1.java create mode 100644 test-mock/test-client-v1/src/main/resources/file.conf create mode 100644 test-mock/test-client-v1/src/main/resources/registry.conf rename {test-protocol-mock-server => test-mock/test-mock-server}/pom.xml (72%) create mode 100644 test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockCoordinator.java rename {test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tc => test-mock/test-mock-server/src/main/java/io/seata/mockserver}/MockNettyRemotingServer.java (62%) create mode 100644 test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockServer.java create mode 100644 test-mock/test-mock-server/src/main/java/io/seata/mockserver/call/CallRm.java create mode 100644 test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockHeartbeatProcessor.java create mode 100644 test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockOnReqProcessor.java create mode 100644 test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockOnRespProcessor.java create mode 100644 test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockRegisterProcessor.java create mode 100644 test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockRemotingProcessor.java create mode 100644 test-mock/test-mock-server/src/main/resources/application.yml create mode 100644 test-mock/test-mock-server/src/main/resources/logback-spring.xml delete mode 100644 test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java delete mode 100644 test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockRemotingProcessor.java delete mode 100644 test-protocol-mock-server/src/main/java/io/seata/mock/protocol/rm/v1/MockRmClient.java delete mode 100644 test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java delete mode 100644 test-protocol-mock-server/src/test/resources/README.md diff --git a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolEncoderV1.java b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolEncoderV1.java index 0710ddb58e1..91030c82b4f 100644 --- a/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolEncoderV1.java +++ b/core/src/main/java/io/seata/core/rpc/netty/v1/ProtocolEncoderV1.java @@ -114,6 +114,8 @@ public void encode(RpcMessage message, ByteBuf out) { } catch (Throwable e) { LOGGER.error("Encode request error!", e); + // todo + throw e; } } } diff --git a/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java b/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java index 78161048046..d1d30363d3d 100644 --- a/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java +++ b/core/src/main/java/io/seata/core/serializer/SerializerServiceLoader.java @@ -19,6 +19,9 @@ import io.seata.common.loader.EnhancedServiceNotFoundException; import io.seata.common.util.ReflectionUtil; +import java.util.HashMap; +import java.util.Map; + /** * The Service Loader for the interface {@link Serializer} * @@ -29,6 +32,7 @@ public final class SerializerServiceLoader { private SerializerServiceLoader() { } + private static Map serializerMap = new HashMap<>(); private static final String PROTOBUF_SERIALIZER_CLASS_NAME = "io.seata.serializer.protobuf.ProtobufSerializer"; @@ -48,10 +52,25 @@ public static Serializer load(SerializerType type, byte version) throws Enhanced "Please manually reference 'io.seata:seata-serializer-protobuf' dependency ", e); } } + + String key = serialzerKey(type, version); + Serializer serializer = serializerMap.get(key); + if (serializer == null) { + if (type == SerializerType.SEATA) { + serializer = EnhancedServiceLoader.load(Serializer.class, type.name(), new Object[]{version}); + } else { + serializer = EnhancedServiceLoader.load(Serializer.class, type.name()); + } + serializerMap.put(key,serializer); + } + return serializer; + + } + + private static String serialzerKey(SerializerType type, byte version){ if (type == SerializerType.SEATA) { - return EnhancedServiceLoader.load(Serializer.class, type.name(), new Object[]{version}); - } else { - return EnhancedServiceLoader.load(Serializer.class, type.name()); + return type.name() + version; } + return type.name(); } } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java index b3aa78a3164..a45c792b233 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/MessageCodecFactory.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.seata.serializer.seata; import io.seata.core.protocol.AbstractMessage; @@ -31,6 +46,11 @@ import io.seata.core.protocol.transaction.GlobalStatusResponse; import io.seata.core.protocol.transaction.UndoLogDeleteRequest; +/** + * The type Message codec factory v0. + * + * @author Bughue + */ public abstract class MessageCodecFactory { public abstract MessageSeataCodec getMessageCodec(short typeCode); @@ -146,7 +166,7 @@ protected static AbstractMessage getMergeRequestInstanceByCode(int typeCode) { * @param typeCode the type code * @return the merge response instance by code */ - protected static AbstractMessage getMergeResponseInstanceByCode(int typeCode) { + public static AbstractMessage getMergeResponseInstanceByCode(int typeCode) { switch (typeCode) { case MessageType.TYPE_GLOBAL_BEGIN_RESULT: return new GlobalBeginResponse(); diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java index e77f94a1582..cdc6e6c0e5c 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java @@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.seata.common.loader.LoadLevel; +import io.seata.common.loader.Scope; import io.seata.core.protocol.AbstractMessage; import io.seata.core.protocol.ProtocolConstants; import io.seata.core.serializer.Serializer; @@ -32,13 +33,13 @@ * * @author zhangsen */ -@LoadLevel(name = "SEATA") +@LoadLevel(name = "SEATA", scope = Scope.PROTOTYPE) public class SeataSerializer implements Serializer { MessageCodecFactory factory; byte protocolVersion ; static Map FACTORY_MAP = ImmutableMap.builder() -// .put(ProtocolConstants.VERSION_0, new ?()) + .put(ProtocolConstants.VERSION_0, new MessageCodecFactoryV1()) .put(ProtocolConstants.VERSION_1, new MessageCodecFactoryV1()) .build(); @@ -53,7 +54,7 @@ public byte[] serialize(T t) { throw new IllegalArgumentException("AbstractMessage isn't available."); } AbstractMessage abstractMessage = (AbstractMessage)t; - //typecode + //type code short typecode = abstractMessage.getTypeCode(); //msg codec MessageSeataCodec messageCodec = factory.getMessageCodec(typecode); @@ -103,43 +104,4 @@ public T deserialize(byte[] bytes) { messageCodec.decode(abstractMessage, in); return (T)abstractMessage; } - -// public Class getCodecClass(short typeCode){ -// Pair, Class> pair = classMap.get(typeCode); -// if(pair !=null && pair.fst !=null){ -// return pair.fst; -// }else { -// return null; -// } -// } -// -// public Class getMessageClass(short typeCode){ -// Pair, Class> pair = classMap.get(typeCode); -// if(pair !=null && pair.snd !=null){ -// return pair.snd; -// }else { -// return null; -// } -// } - -// protected AbstractMessage getMessageByType(short typecode) { -// try { -// return getMessageClass(typecode).newInstance(); -// } catch (InstantiationException e) { -// throw new RuntimeException(e); -// } catch (IllegalAccessException e) { -// throw new RuntimeException(e); -// } -// } -// -// protected MessageSeataCodec getCodecByType(short typecode) { -// try { -// return getCodecClass(typecode).newInstance(); -// } catch (InstantiationException e) { -// throw new RuntimeException(e); -// } catch (IllegalAccessException e) { -// throw new RuntimeException(e); -// } -// } - } diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/BatchResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/BatchResultMessageCodec.java index a530d4b4e68..10cf8e76449 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/BatchResultMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/BatchResultMessageCodec.java @@ -1,7 +1,22 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.seata.serializer.seata.protocol.v0; /** - * ? + * the type BatchResultMessage Codec * * @author Bughue * @date 2023/9/21 diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergeResultMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergeResultMessageCodec.java index 00b88110223..8084d47d024 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergeResultMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergeResultMessageCodec.java @@ -1,7 +1,22 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.seata.serializer.seata.protocol.v0; /** - * ? + * the type MergeResultMessage Codec * * @author Bughue * @date 2023/9/21 diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedWarpMessageCodec.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedWarpMessageCodec.java index 1a3b6600cbd..5c2d37e0dcb 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedWarpMessageCodec.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MergedWarpMessageCodec.java @@ -1,7 +1,22 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.seata.serializer.seata.protocol.v0; /** - * ? + * the type MergedWarpMessage Codec * * @author Bughue * @date 2023/9/21 diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MessageCodecFactoryV0.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MessageCodecFactoryV0.java index 0205c91820d..cf879cc441d 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MessageCodecFactoryV0.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v0/MessageCodecFactoryV0.java @@ -15,9 +15,6 @@ */ package io.seata.serializer.seata.protocol.v0; -import io.seata.core.protocol.AbstractMessage; -import io.seata.core.protocol.MergeResultMessage; -import io.seata.core.protocol.MergedWarpMessage; import io.seata.core.protocol.MessageType; import io.seata.serializer.seata.MessageSeataCodec; import io.seata.serializer.seata.protocol.v1.MessageCodecFactoryV1; diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MessageCodecFactoryV1.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MessageCodecFactoryV1.java index 6e14490fc2e..d6e7131327c 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MessageCodecFactoryV1.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/protocol/v1/MessageCodecFactoryV1.java @@ -150,7 +150,7 @@ protected static MessageSeataCodec getMergeRequestMessageSeataCodec(int typeCode * @param typeCode the type code * @return the merge response instance by code */ - protected static MessageSeataCodec getMergeResponseMessageSeataCodec(int typeCode) { + public static MessageSeataCodec getMergeResponseMessageSeataCodec(int typeCode) { switch (typeCode) { case MessageType.TYPE_GLOBAL_BEGIN_RESULT: return new GlobalBeginResponseCodec(); diff --git a/test-mock/pom.xml b/test-mock/pom.xml new file mode 100644 index 00000000000..a50a96b742a --- /dev/null +++ b/test-mock/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + io.seata + seata-build + ${revision} + ../build/pom.xml + + seata-mock + pom + seata-mock + seata-mock + + + skip-submodule + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + \ No newline at end of file diff --git a/test-mock/test-client-v0/pom.xml b/test-mock/test-client-v0/pom.xml new file mode 100644 index 00000000000..24dd4538ef5 --- /dev/null +++ b/test-mock/test-client-v0/pom.xml @@ -0,0 +1,55 @@ + + + + + 4.0.0 + + + io.seata + seata-test-client-v0 + 0.6.1 + + seata-test-client-v0 + test for Seata protocol(v0) + + + + io.seata + seata-all + 0.6.1 + + + ch.qos.logback + logback-classic + 1.2.12 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/Action1.java b/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/Action1.java new file mode 100644 index 00000000000..a7ec40200b5 --- /dev/null +++ b/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/Action1.java @@ -0,0 +1,25 @@ +package io.seata.core.rpc.netty; + +import io.seata.rm.tcc.api.BusinessActionContext; +import io.seata.rm.tcc.api.BusinessActionContextParameter; +import io.seata.rm.tcc.api.LocalTCC; +import io.seata.rm.tcc.api.TwoPhaseBusinessAction; + +import java.util.Map; + +@LocalTCC +public interface Action1 { + + @TwoPhaseBusinessAction(name = "mock-action", commitMethod = "commitTcc", rollbackMethod = "cancel" +// , useTCCFence = true + ) + String insert(@BusinessActionContextParameter Long reqId, + @BusinessActionContextParameter(paramName = "params") Map params + ); + + + boolean commitTcc(BusinessActionContext actionContext); + + + boolean cancel(BusinessActionContext actionContext); +} diff --git a/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/Action1Impl.java b/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/Action1Impl.java new file mode 100644 index 00000000000..7f7dec97da6 --- /dev/null +++ b/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/Action1Impl.java @@ -0,0 +1,33 @@ +package io.seata.core.rpc.netty; + + +import io.seata.rm.tcc.api.BusinessActionContext; +import org.springframework.stereotype.Service; + +import java.util.Map; + + +@Service +public class Action1Impl implements Action1 { + + @Override + public String insert(Long reqId,Map params) { + System.out.println("prepare"); + return "prepare"; + } + + + @Override + public boolean commitTcc(BusinessActionContext actionContext) { + System.out.println("commitTcc"); + return true; + } + + @Override + public boolean cancel(BusinessActionContext actionContext) { + System.out.println("cancel"); + return true; + } + + +} diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockServerApplication.java b/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/MockConstants.java similarity index 55% rename from test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockServerApplication.java rename to test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/MockConstants.java index 05eb05e3959..3ea151e2902 100644 --- a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockServerApplication.java +++ b/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/MockConstants.java @@ -13,20 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.mock.protocol; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -import java.io.IOException; +package io.seata.core.rpc.netty; /** - * @author spilledyear@outlook.com - */ -@SpringBootApplication(scanBasePackages = {"io.seata.mock.protocol"}) -public class MockServerApplication { - public static void main(String[] args) throws IOException { - // run the spring-boot application - SpringApplication.run(MockServerApplication.class, args); - } + * Mock Constants + * + * @author minghua.xie + * @date 2023/11/21 + **/ +public class MockConstants { + public static final String APPLICATION_ID = "my_app_test"; + public static final String SERVICE_GROUP = "default"; + public static final String SERVER_ADDRESS = "0.0.0.0:8091"; } diff --git a/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/RmClientTestV0.java b/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/RmClientTestV0.java new file mode 100644 index 00000000000..0c0a3e9779a --- /dev/null +++ b/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/RmClientTestV0.java @@ -0,0 +1,75 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + +import io.seata.core.context.RootContext; +import io.seata.core.exception.TransactionException; +import io.seata.core.model.BranchStatus; +import io.seata.core.model.BranchType; +import io.seata.core.protocol.HeartbeatMessage; +import io.seata.rm.DefaultResourceManager; +import io.seata.rm.RMClient; +import io.seata.rm.tcc.remoting.RemotingParser; +import io.seata.rm.tcc.remoting.parser.DefaultRemotingParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.TimeoutException; + +/** + * rm client test + * + * @author minghua.xie + * @date 2023/11/21 + **/ +public class RmClientTestV0 { + + protected static final Logger LOGGER = LoggerFactory.getLogger(RmClientTestV0.class); + + public static void main(String[] args) throws TransactionException { + + RMClient.init(MockConstants.APPLICATION_ID, MockConstants.SERVICE_GROUP); + DefaultResourceManager rm = DefaultResourceManager.get(); + + //register:TYPE_REG_RM = 103 , TYPE_REG_RM_RESULT = 104 + String rid = "mock-action"; + Action1 target = new Action1Impl(); + + DefaultRemotingParser.get().parserRemotingServiceInfo(target, rid); + LOGGER.info("[VO] registerResource ok"); + + //branchRegister:TYPE_BRANCH_REGISTER = 11 , TYPE_BRANCH_REGISTER_RESULT = 12 + Long branchId = rm.branchRegister(BranchType.AT, rid, "1", "1", "1", "1"); + LOGGER.info("[VO] branchRegister ok, branchId=" + branchId); + + // branchReport:TYPE_BRANCH_STATUS_REPORT = 13 , TYPE_BRANCH_STATUS_REPORT_RESULT = 14 + // TYPE_SEATA_MERGE = 59 , TYPE_SEATA_MERGE_RESULT = 60 + rm.branchReport(BranchType.AT, "1", branchId, BranchStatus.PhaseTwo_Committed, ""); + LOGGER.info("[VO] branchReport ok"); + + //lockQuery:TYPE_GLOBAL_LOCK_QUERY = 21 , TYPE_GLOBAL_LOCK_QUERY_RESULT = 22 + RootContext.bind("1"); + boolean b = rm.lockQuery(BranchType.AT, rid, "1", "1"); + LOGGER.info("[VO] lockQuery ok, result=" + b); + + + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } +} diff --git a/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/TmClientTestV0.java b/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/TmClientTestV0.java new file mode 100644 index 00000000000..2200a062e5b --- /dev/null +++ b/test-mock/test-client-v0/src/main/java/io/seata/core/rpc.netty/TmClientTestV0.java @@ -0,0 +1,78 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + + +import io.netty.channel.Channel; +import io.seata.core.model.GlobalStatus; +import io.seata.core.model.TransactionManager; +import io.seata.core.protocol.HeartbeatMessage; +import io.seata.tm.DefaultTransactionManager; +import io.seata.tm.TransactionManagerHolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TmClient Test + * + * @author minghua.xie + * @date 2023/11/10 + **/ +public class TmClientTestV0 { + protected static final Logger LOGGER = LoggerFactory.getLogger(TmClientTestV0.class); + + + public static void main(String[] args) throws Exception { + LOGGER.info("[VO] TM begin"); + + TmRpcClient tmRpcClient = TmRpcClient.getInstance(MockConstants.APPLICATION_ID, MockConstants.SERVICE_GROUP); + tmRpcClient.init(); + TransactionManager tm = TransactionManagerHolder.get(); + + //register:TYPE_REG_CLT = 101 , TYPE_REG_CLT_RESULT = 102 + Channel channel = tmRpcClient.connect(MockConstants.SERVER_ADDRESS); + LOGGER.info("[VO] TM register ok:channel=" + channel); + TmRpcClient.getInstance().sendRequest(channel, HeartbeatMessage.PING); + LOGGER.info("[VO] TM heartbeat ok "); + + //globalBegin:TYPE_GLOBAL_BEGIN = 1 , TYPE_GLOBAL_BEGIN_RESULT = 2 + String xid = tm.begin(MockConstants.APPLICATION_ID, MockConstants.SERVICE_GROUP, "test", 60000); + LOGGER.info("[VO] globalBegin ok:xid=" + xid); + + if (xid == null) { + xid = "6"; + } + + //globalCommit:TYPE_GLOBAL_COMMIT = 7 , TYPE_GLOBAL_COMMIT_RESULT = 8 + GlobalStatus commit = tm.commit(xid); + LOGGER.info("[VO] globalCommit ok:" + commit); + + //globalRollback:TYPE_GLOBAL_ROLLBACK = 9 , TYPE_GLOBAL_ROLLBACK_RESULT = 10 + GlobalStatus rollback = tm.rollback(xid); + LOGGER.info("[VO] globalRollback ok:" + rollback); + + + //getStatus:TYPE_GLOBAL_STATUS = 15 , TYPE_GLOBAL_STATUS_RESULT = 16 + GlobalStatus status = tm.getStatus(xid); + LOGGER.info("[VO] getStatus ok:" + status); + + //globalReport:TYPE_GLOBAL_REPORT = 17 , TYPE_GLOBAL_REPORT_RESULT = 18 +// GlobalStatus globalReport = tm.globalReport(xid, GlobalStatus.Committed); +// LOGGER.info("globalReport ok:" + globalReport); + + } + +} diff --git a/test-mock/test-client-v0/src/main/resources/file.conf b/test-mock/test-client-v0/src/main/resources/file.conf new file mode 100644 index 00000000000..360636f2166 --- /dev/null +++ b/test-mock/test-client-v0/src/main/resources/file.conf @@ -0,0 +1,22 @@ + # Copyright 1999-2019 Seata.io Group. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +service { + #transaction service group mapping + vgroupMapping.default = "default" + vgroup_mapping.default = "default" + #only support when registry.type=file, please don't set multiple addresses + default.grouplist = "127.0.0.1:8091" + #disable seata + disableGlobalTransaction = false +} \ No newline at end of file diff --git a/test-protocol-mock-server/src/test/resources/logback.xml b/test-mock/test-client-v0/src/main/resources/logback.xml similarity index 100% rename from test-protocol-mock-server/src/test/resources/logback.xml rename to test-mock/test-client-v0/src/main/resources/logback.xml diff --git a/test-mock/test-client-v0/src/main/resources/registry.conf b/test-mock/test-client-v0/src/main/resources/registry.conf new file mode 100644 index 00000000000..7870e78a687 --- /dev/null +++ b/test-mock/test-client-v0/src/main/resources/registry.conf @@ -0,0 +1,30 @@ +# Copyright 1999-2019 Seata.io Group. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +registry { + # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa + type = "file" + + file { + name = "file.conf" + } +} + +config { + # file、nacos 、apollo、zk、consul、etcd3 + type = "file" + + file { + name = "file.conf" + } +} \ No newline at end of file diff --git a/test-mock/test-client-v1-1.6.0/pom.xml b/test-mock/test-client-v1-1.6.0/pom.xml new file mode 100644 index 00000000000..997ccd3175c --- /dev/null +++ b/test-mock/test-client-v1-1.6.0/pom.xml @@ -0,0 +1,38 @@ + + + + + 4.0.0 + + io.seata + seata-test-client-v1-1.6.0 + 1.6.0 + seata-test-client-v1-1.6.0 + test for Seata protocol(v1-1.6.0) + + + + io.seata + seata-all + 1.6.0 + + + + + \ No newline at end of file diff --git a/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/Action1.java b/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/Action1.java new file mode 100644 index 00000000000..a7ec40200b5 --- /dev/null +++ b/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/Action1.java @@ -0,0 +1,25 @@ +package io.seata.core.rpc.netty; + +import io.seata.rm.tcc.api.BusinessActionContext; +import io.seata.rm.tcc.api.BusinessActionContextParameter; +import io.seata.rm.tcc.api.LocalTCC; +import io.seata.rm.tcc.api.TwoPhaseBusinessAction; + +import java.util.Map; + +@LocalTCC +public interface Action1 { + + @TwoPhaseBusinessAction(name = "mock-action", commitMethod = "commitTcc", rollbackMethod = "cancel" +// , useTCCFence = true + ) + String insert(@BusinessActionContextParameter Long reqId, + @BusinessActionContextParameter(paramName = "params") Map params + ); + + + boolean commitTcc(BusinessActionContext actionContext); + + + boolean cancel(BusinessActionContext actionContext); +} diff --git a/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/Action1Impl.java b/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/Action1Impl.java new file mode 100644 index 00000000000..7f7dec97da6 --- /dev/null +++ b/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/Action1Impl.java @@ -0,0 +1,33 @@ +package io.seata.core.rpc.netty; + + +import io.seata.rm.tcc.api.BusinessActionContext; +import org.springframework.stereotype.Service; + +import java.util.Map; + + +@Service +public class Action1Impl implements Action1 { + + @Override + public String insert(Long reqId,Map params) { + System.out.println("prepare"); + return "prepare"; + } + + + @Override + public boolean commitTcc(BusinessActionContext actionContext) { + System.out.println("commitTcc"); + return true; + } + + @Override + public boolean cancel(BusinessActionContext actionContext) { + System.out.println("cancel"); + return true; + } + + +} diff --git a/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/MockConstants.java b/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/MockConstants.java new file mode 100644 index 00000000000..8960115aa4e --- /dev/null +++ b/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/MockConstants.java @@ -0,0 +1,28 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + +/** + * Mock Constants + * + * @author minghua.xie + * @date 2023/11/21 + **/ +public class MockConstants { + public static final String APPLICATION_ID = "my_app_test"; + public static final String SERVICE_GROUP = "default_tx_group"; + public static final String SERVER_ADDRESS = "0.0.0.0:8091"; +} diff --git a/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/RmClientTestV160.java b/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/RmClientTestV160.java new file mode 100644 index 00000000000..3075002b308 --- /dev/null +++ b/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/RmClientTestV160.java @@ -0,0 +1,80 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + +import io.seata.core.context.RootContext; +import io.seata.core.exception.TransactionException; +import io.seata.core.model.BranchStatus; +import io.seata.core.model.BranchType; +import io.seata.core.protocol.HeartbeatMessage; +import io.seata.rm.DefaultResourceManager; +import io.seata.rm.RMClient; +import io.seata.rm.tcc.remoting.RemotingParser; +import io.seata.rm.tcc.remoting.parser.DefaultRemotingParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * rm client test + * + * @author minghua.xie + * @date 2023/11/21 + **/ +public class RmClientTestV160 { + + protected static final Logger LOGGER = LoggerFactory.getLogger(RmClientTestV160.class); + + public static void main(String[] args) throws TransactionException { + RMClient.init(MockConstants.APPLICATION_ID, MockConstants.SERVICE_GROUP); + DefaultResourceManager rm = DefaultResourceManager.get(); + + //register:TYPE_REG_RM = 103 , TYPE_REG_RM_RESULT = 104 + String rid = "mock-action"; + Action1 target = new Action1Impl(); + + RemotingParser remotingParser = DefaultRemotingParser.get().isRemoting(target, rid); + if (remotingParser == null) { + throw new RuntimeException("not support remoting"); + } + DefaultRemotingParser.get().parserRemotingServiceInfo(target, rid, remotingParser); + LOGGER.info("registerResource ok"); + + //branchRegister:TYPE_BRANCH_REGISTER = 11 , TYPE_BRANCH_REGISTER_RESULT = 12 + Long branchId = rm.branchRegister(BranchType.AT, rid, "1", "1", "1", "1"); + LOGGER.info("branchRegister ok, branchId=" + branchId); + + + // branchReport:TYPE_BRANCH_STATUS_REPORT = 13 , TYPE_BRANCH_STATUS_REPORT_RESULT = 14 + // TYPE_SEATA_MERGE = 59 , TYPE_SEATA_MERGE_RESULT = 60 + rm.branchReport(BranchType.AT, "1", branchId, BranchStatus.PhaseTwo_Committed, ""); + LOGGER.info("branchReport ok"); + + //lockQuery:TYPE_GLOBAL_LOCK_QUERY = 21 , TYPE_GLOBAL_LOCK_QUERY_RESULT = 22 + RootContext.bind("1"); + boolean b = rm.lockQuery(BranchType.AT, rid, "1", "1"); + LOGGER.info("lockQuery ok, result=" + b); + + RmNettyRemotingClient remotingClient = RmNettyRemotingClient.getInstance(); + remotingClient.getClientChannelManager().getChannels().forEach( + (key, value) -> RmNettyRemotingClient.getInstance().sendAsyncRequest(value, HeartbeatMessage.PING)); + + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } +} diff --git a/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/TmClientTestV160.java b/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/TmClientTestV160.java new file mode 100644 index 00000000000..bc0c54d4a1f --- /dev/null +++ b/test-mock/test-client-v1-1.6.0/src/main/java/io/seata/core/rpc/netty/TmClientTestV160.java @@ -0,0 +1,75 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + + +import io.netty.channel.Channel; +import io.seata.core.model.GlobalStatus; +import io.seata.core.model.TransactionManager; +import io.seata.tm.DefaultTransactionManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TmClient Test + * + * @author minghua.xie + * @date 2023/11/10 + **/ +public class TmClientTestV160 { + + protected static final Logger LOGGER = LoggerFactory.getLogger(TmClientTestV160.class); + public static void main(String[] args) throws Exception { + + TmNettyRemotingClient tmNettyRemotingClient = TmNettyRemotingClient.getInstance( + MockConstants.APPLICATION_ID, MockConstants.SERVICE_GROUP); + tmNettyRemotingClient.init(); + TransactionManager tm = new DefaultTransactionManager(); + + //register:TYPE_REG_CLT = 101 , TYPE_REG_CLT_RESULT = 102 + Channel channel = TmNettyRemotingClient.getInstance().getClientChannelManager() + .acquireChannel(MockConstants.SERVER_ADDRESS); + LOGGER.info("TM register ok:channel=" + channel); + + //globalBegin:TYPE_GLOBAL_BEGIN = 1 , TYPE_GLOBAL_BEGIN_RESULT = 2 + String xid = tm.begin(MockConstants.APPLICATION_ID, + MockConstants.SERVICE_GROUP, "test", 60000); + LOGGER.info("globalBegin ok:xid=" + xid); + + if (xid == null) { + xid = "6"; + } + + //globalCommit:TYPE_GLOBAL_COMMIT = 7 , TYPE_GLOBAL_COMMIT_RESULT = 8 + GlobalStatus commit = tm.commit(xid); + LOGGER.info("globalCommit ok:" + commit); + + //globalRollback:TYPE_GLOBAL_ROLLBACK = 9 , TYPE_GLOBAL_ROLLBACK_RESULT = 10 + GlobalStatus rollback = tm.rollback(xid); + LOGGER.info("globalRollback ok:" + rollback); + + + //getStatus:TYPE_GLOBAL_STATUS = 15 , TYPE_GLOBAL_STATUS_RESULT = 16 + GlobalStatus status = tm.getStatus(xid); + LOGGER.info("getStatus ok:" + status); + + //globalReport:TYPE_GLOBAL_REPORT = 17 , TYPE_GLOBAL_REPORT_RESULT = 18 + GlobalStatus globalReport = tm.globalReport(xid, GlobalStatus.Committed); + LOGGER.info("globalReport ok:" + globalReport); + + } + +} diff --git a/test-mock/test-client-v1-1.6.0/src/main/resources/file.conf b/test-mock/test-client-v1-1.6.0/src/main/resources/file.conf new file mode 100644 index 00000000000..a06899c4a03 --- /dev/null +++ b/test-mock/test-client-v1-1.6.0/src/main/resources/file.conf @@ -0,0 +1,21 @@ + # Copyright 1999-2019 Seata.io Group. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +service { + #transaction service group mapping + vgroupMapping.default_tx_group = "default" + #only support when registry.type=file, please don't set multiple addresses + default.grouplist = "127.0.0.1:8091" + #disable seata + disableGlobalTransaction = false +} \ No newline at end of file diff --git a/test-mock/test-client-v1-1.6.0/src/main/resources/registry.conf b/test-mock/test-client-v1-1.6.0/src/main/resources/registry.conf new file mode 100644 index 00000000000..7870e78a687 --- /dev/null +++ b/test-mock/test-client-v1-1.6.0/src/main/resources/registry.conf @@ -0,0 +1,30 @@ +# Copyright 1999-2019 Seata.io Group. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +registry { + # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa + type = "file" + + file { + name = "file.conf" + } +} + +config { + # file、nacos 、apollo、zk、consul、etcd3 + type = "file" + + file { + name = "file.conf" + } +} \ No newline at end of file diff --git a/test-mock/test-client-v1/pom.xml b/test-mock/test-client-v1/pom.xml new file mode 100644 index 00000000000..358d9f67f1d --- /dev/null +++ b/test-mock/test-client-v1/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + + io.seata + seata-mock + ${revision} + + + seata-test-client-v1 + test for Seata protocol(v1-2.0.0) + + + + 8 + 8 + UTF-8 + + + + + ${project.groupId} + seata-all + ${project.version} + + + slf4j-log4j12 + org.slf4j + + + log4j + log4j + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/Action1.java b/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/Action1.java new file mode 100644 index 00000000000..a7ec40200b5 --- /dev/null +++ b/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/Action1.java @@ -0,0 +1,25 @@ +package io.seata.core.rpc.netty; + +import io.seata.rm.tcc.api.BusinessActionContext; +import io.seata.rm.tcc.api.BusinessActionContextParameter; +import io.seata.rm.tcc.api.LocalTCC; +import io.seata.rm.tcc.api.TwoPhaseBusinessAction; + +import java.util.Map; + +@LocalTCC +public interface Action1 { + + @TwoPhaseBusinessAction(name = "mock-action", commitMethod = "commitTcc", rollbackMethod = "cancel" +// , useTCCFence = true + ) + String insert(@BusinessActionContextParameter Long reqId, + @BusinessActionContextParameter(paramName = "params") Map params + ); + + + boolean commitTcc(BusinessActionContext actionContext); + + + boolean cancel(BusinessActionContext actionContext); +} diff --git a/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/Action1Impl.java b/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/Action1Impl.java new file mode 100644 index 00000000000..6ea822f2cf8 --- /dev/null +++ b/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/Action1Impl.java @@ -0,0 +1,35 @@ +package io.seata.core.rpc.netty; + + +import io.seata.rm.tcc.api.BusinessActionContext; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Map; + + +@Service +public class Action1Impl implements Action1 { + + @Override + public String insert(Long reqId,Map params) { + System.out.println("prepare"); + return "prepare"; + } + + + @Override + public boolean commitTcc(BusinessActionContext actionContext) { + System.out.println("commitTcc"); + return true; + } + + @Override + public boolean cancel(BusinessActionContext actionContext) { + System.out.println("cancel"); + return true; + } + + +} diff --git a/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/MockConstants.java b/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/MockConstants.java new file mode 100644 index 00000000000..8960115aa4e --- /dev/null +++ b/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/MockConstants.java @@ -0,0 +1,28 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + +/** + * Mock Constants + * + * @author minghua.xie + * @date 2023/11/21 + **/ +public class MockConstants { + public static final String APPLICATION_ID = "my_app_test"; + public static final String SERVICE_GROUP = "default_tx_group"; + public static final String SERVER_ADDRESS = "0.0.0.0:8091"; +} diff --git a/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/RmClientTestV1.java b/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/RmClientTestV1.java new file mode 100644 index 00000000000..71667541822 --- /dev/null +++ b/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/RmClientTestV1.java @@ -0,0 +1,71 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + +import io.seata.core.context.RootContext; +import io.seata.core.exception.TransactionException; +import io.seata.core.model.BranchStatus; +import io.seata.core.model.BranchType; +import io.seata.core.protocol.HeartbeatMessage; +import io.seata.integration.tx.api.interceptor.parser.DefaultResourceRegisterParser; +import io.seata.rm.DefaultResourceManager; +import io.seata.rm.RMClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * rm client test + * + * @author minghua.xie + * @date 2023/11/21 + **/ +public class RmClientTestV1 { + protected static final Logger LOGGER = LoggerFactory.getLogger(RmClientTestV1.class); + public static void main(String[] args) throws TransactionException { + RMClient.init(MockConstants.APPLICATION_ID, MockConstants.SERVICE_GROUP); + DefaultResourceManager rm = DefaultResourceManager.get(); + + //register:TYPE_REG_RM = 103 , TYPE_REG_RM_RESULT = 104 + String rid = "mock-action"; + Action1 target = new Action1Impl(); + DefaultResourceRegisterParser.get().registerResource(target, rid); + LOGGER.info("registerResource ok"); + + //branchRegister:TYPE_BRANCH_REGISTER = 11 , TYPE_BRANCH_REGISTER_RESULT = 12 + Long branchId = rm.branchRegister(BranchType.AT, rid, "1", "1", "1", "1"); + LOGGER.info("branchRegister ok, branchId=" + branchId); + + + // branchReport:TYPE_BRANCH_STATUS_REPORT = 13 , TYPE_BRANCH_STATUS_REPORT_RESULT = 14 + // TYPE_SEATA_MERGE = 59 , TYPE_SEATA_MERGE_RESULT = 60 + rm.branchReport(BranchType.AT, "1", branchId, BranchStatus.PhaseTwo_Committed, ""); + LOGGER.info("branchReport ok"); + + //lockQuery:TYPE_GLOBAL_LOCK_QUERY = 21 , TYPE_GLOBAL_LOCK_QUERY_RESULT = 22 + RootContext.bind("1"); + boolean b = rm.lockQuery(BranchType.AT, rid, "1", "1"); + LOGGER.info("lockQuery ok, result=" + b); + + RmNettyRemotingClient remotingClient = RmNettyRemotingClient.getInstance(); + remotingClient.getClientChannelManager().getChannels().forEach( + (key, value) -> RmNettyRemotingClient.getInstance().sendAsyncRequest(value, HeartbeatMessage.PING)); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } +} diff --git a/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/TmClientTestV1.java b/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/TmClientTestV1.java new file mode 100644 index 00000000000..655c0011bc8 --- /dev/null +++ b/test-mock/test-client-v1/src/main/java/io/seata/core/rpc/netty/TmClientTestV1.java @@ -0,0 +1,75 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.core.rpc.netty; + + +import io.netty.channel.Channel; +import io.seata.core.model.GlobalStatus; +import io.seata.core.model.TransactionManager; +import io.seata.tm.DefaultTransactionManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TmClient Test + * + * @author minghua.xie + * @date 2023/11/10 + **/ +public class TmClientTestV1 { + + protected static final Logger LOGGER = LoggerFactory.getLogger(TmClientTestV1.class); + public static void main(String[] args) throws Exception { + + TmNettyRemotingClient tmNettyRemotingClient = TmNettyRemotingClient.getInstance( + MockConstants.APPLICATION_ID, MockConstants.SERVICE_GROUP); + tmNettyRemotingClient.init(); + TransactionManager tm = new DefaultTransactionManager(); + + //register:TYPE_REG_CLT = 101 , TYPE_REG_CLT_RESULT = 102 + Channel channel = TmNettyRemotingClient.getInstance().getClientChannelManager() + .acquireChannel(MockConstants.SERVER_ADDRESS); + LOGGER.info("TM register ok:channel=" + channel); + + //globalBegin:TYPE_GLOBAL_BEGIN = 1 , TYPE_GLOBAL_BEGIN_RESULT = 2 + String xid = tm.begin(MockConstants.APPLICATION_ID, + MockConstants.SERVICE_GROUP, "test", 60000); + LOGGER.info("globalBegin ok:xid=" + xid); + + if (xid == null) { + xid = "6"; + } + + //globalCommit:TYPE_GLOBAL_COMMIT = 7 , TYPE_GLOBAL_COMMIT_RESULT = 8 + GlobalStatus commit = tm.commit(xid); + LOGGER.info("globalCommit ok:" + commit); + + //globalRollback:TYPE_GLOBAL_ROLLBACK = 9 , TYPE_GLOBAL_ROLLBACK_RESULT = 10 + GlobalStatus rollback = tm.rollback(xid); + LOGGER.info("globalRollback ok:" + rollback); + + + //getStatus:TYPE_GLOBAL_STATUS = 15 , TYPE_GLOBAL_STATUS_RESULT = 16 + GlobalStatus status = tm.getStatus(xid); + LOGGER.info("getStatus ok:" + status); + + //globalReport:TYPE_GLOBAL_REPORT = 17 , TYPE_GLOBAL_REPORT_RESULT = 18 + GlobalStatus globalReport = tm.globalReport(xid, GlobalStatus.Committed); + LOGGER.info("globalReport ok:" + globalReport); + + } + +} diff --git a/test-mock/test-client-v1/src/main/resources/file.conf b/test-mock/test-client-v1/src/main/resources/file.conf new file mode 100644 index 00000000000..a06899c4a03 --- /dev/null +++ b/test-mock/test-client-v1/src/main/resources/file.conf @@ -0,0 +1,21 @@ + # Copyright 1999-2019 Seata.io Group. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +service { + #transaction service group mapping + vgroupMapping.default_tx_group = "default" + #only support when registry.type=file, please don't set multiple addresses + default.grouplist = "127.0.0.1:8091" + #disable seata + disableGlobalTransaction = false +} \ No newline at end of file diff --git a/test-mock/test-client-v1/src/main/resources/registry.conf b/test-mock/test-client-v1/src/main/resources/registry.conf new file mode 100644 index 00000000000..7870e78a687 --- /dev/null +++ b/test-mock/test-client-v1/src/main/resources/registry.conf @@ -0,0 +1,30 @@ +# Copyright 1999-2019 Seata.io Group. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +registry { + # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa + type = "file" + + file { + name = "file.conf" + } +} + +config { + # file、nacos 、apollo、zk、consul、etcd3 + type = "file" + + file { + name = "file.conf" + } +} \ No newline at end of file diff --git a/test-protocol-mock-server/pom.xml b/test-mock/test-mock-server/pom.xml similarity index 72% rename from test-protocol-mock-server/pom.xml rename to test-mock/test-mock-server/pom.xml index 6fdc4a271c9..154b949dbac 100644 --- a/test-protocol-mock-server/pom.xml +++ b/test-mock/test-mock-server/pom.xml @@ -19,13 +19,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> io.seata - seata-parent + seata-mock ${revision} 4.0.0 - seata-test-protocol-mock-server + seata-mock-server jar - seata-test-protocol-mock-server ${project.version} + seata-test-protocol-mock-server test for Seata protocol @@ -42,9 +42,19 @@ - ${project.groupId} - seata-core + io.seata + seata-server ${project.version} + + + slf4j-log4j12 + org.slf4j + + + log4j + log4j + + diff --git a/test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockCoordinator.java b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockCoordinator.java new file mode 100644 index 00000000000..196b1f6872c --- /dev/null +++ b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockCoordinator.java @@ -0,0 +1,134 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.mockserver; + +import io.seata.core.exception.TransactionException; +import io.seata.core.model.BranchStatus; +import io.seata.core.model.GlobalStatus; +import io.seata.core.protocol.AbstractMessage; +import io.seata.core.protocol.AbstractResultMessage; +import io.seata.core.protocol.ProtocolConstants; +import io.seata.core.protocol.ResultCode; +import io.seata.core.protocol.Version; +import io.seata.core.protocol.transaction.*; +import io.seata.core.rpc.Disposable; +import io.seata.core.rpc.RemotingServer; +import io.seata.core.rpc.RpcContext; +import io.seata.core.rpc.TransactionMessageHandler; +import io.seata.core.rpc.netty.ChannelManager; +import io.seata.mockserver.call.CallRm; +import io.seata.serializer.seata.MessageCodecFactory; +import io.seata.serializer.seata.MessageSeataCodec; +import io.seata.serializer.seata.protocol.v1.MessageCodecFactoryV1; +import io.seata.server.AbstractTCInboundHandler; + +/** + * Mock Coordinator + * + * @author minghua.xie + * @date 2023/11/14 + **/ +public class MockCoordinator extends AbstractTCInboundHandler implements TransactionMessageHandler, Disposable { + + RemotingServer remotingServer; + @Override + public void destroy() { + + } + + @Override + public AbstractResultMessage onRequest(AbstractMessage request, RpcContext context) { + if (!(request instanceof AbstractTransactionRequestToTC)) { + throw new IllegalArgumentException(); + } + AbstractTransactionRequestToTC transactionRequest = (AbstractTransactionRequestToTC) request; + transactionRequest.setTCInboundHandler(this); + + return transactionRequest.handle(context); + } + + @Override + public void onResponse(AbstractResultMessage response, RpcContext context) { + response.setResultCode(ResultCode.Success); + } + + @Override + protected void doGlobalBegin(GlobalBeginRequest request, GlobalBeginResponse response, RpcContext rpcContext) throws TransactionException { + response.setXid("666"); + response.setResultCode(ResultCode.Success); + } + + @Override + protected void doGlobalCommit(GlobalCommitRequest request, GlobalCommitResponse response, RpcContext rpcContext) throws TransactionException { + response.setGlobalStatus(GlobalStatus.Committed); + response.setResultCode(ResultCode.Success); + } + + @Override + protected void doGlobalRollback(GlobalRollbackRequest request, GlobalRollbackResponse response, RpcContext rpcContext) throws TransactionException { + response.setGlobalStatus(GlobalStatus.Rollbacked); + response.setResultCode(ResultCode.Success); + } + + @Override + protected void doBranchRegister(BranchRegisterRequest request, BranchRegisterResponse response, RpcContext rpcContext) throws TransactionException { + response.setBranchId(9L); + response.setResultCode(ResultCode.Success); + + String resourceId = request.getResourceId(); + String clientId = rpcContext.getClientId(); + + Thread thread = new Thread(() -> { + try { + Thread.sleep(1000); + BranchStatus commit = CallRm.branchCommit(remotingServer, resourceId, clientId); + BranchStatus rollback = CallRm.branchRollback(remotingServer, resourceId, clientId); + if (ProtocolConstants.VERSION_0 != Version.calcProtocolVersion(rpcContext.getVersion())) { + CallRm.deleteUndoLog(remotingServer, resourceId, clientId); + } + } catch (Exception e) { + e.printStackTrace(); + } + }); + thread.start(); + } + + @Override + protected void doBranchReport(BranchReportRequest request, BranchReportResponse response, RpcContext rpcContext) throws TransactionException { + response.setResultCode(ResultCode.Success); + } + + @Override + protected void doLockCheck(GlobalLockQueryRequest request, GlobalLockQueryResponse response, RpcContext rpcContext) throws TransactionException { + response.setResultCode(ResultCode.Success); + } + + @Override + protected void doGlobalStatus(GlobalStatusRequest request, GlobalStatusResponse response, RpcContext rpcContext) throws TransactionException { + response.setGlobalStatus(GlobalStatus.Committed); + response.setResultCode(ResultCode.Success); + } + + @Override + protected void doGlobalReport(GlobalReportRequest request, GlobalReportResponse response, RpcContext rpcContext) throws TransactionException { + response.setGlobalStatus(GlobalStatus.Committed); + response.setResultCode(ResultCode.Success); + } + + public void setRemotingServer(RemotingServer remotingServer) { + this.remotingServer = remotingServer; + } +} diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tc/MockNettyRemotingServer.java b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockNettyRemotingServer.java similarity index 62% rename from test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tc/MockNettyRemotingServer.java rename to test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockNettyRemotingServer.java index 82223c6576f..cf51d7218db 100644 --- a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tc/MockNettyRemotingServer.java +++ b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockNettyRemotingServer.java @@ -13,35 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.seata.mock.protocol.tc; +package io.seata.mockserver; import io.netty.channel.Channel; -import io.seata.common.thread.NamedThreadFactory; -import io.seata.core.protocol.AbstractMessage; -import io.seata.core.protocol.AbstractResultMessage; import io.seata.core.protocol.MessageType; -import io.seata.core.protocol.RegisterRMRequest; -import io.seata.core.protocol.RegisterRMResponse; -import io.seata.core.protocol.RegisterTMRequest; -import io.seata.core.protocol.RegisterTMResponse; -import io.seata.core.rpc.RpcContext; -import io.seata.core.rpc.ShutdownHook; import io.seata.core.rpc.TransactionMessageHandler; import io.seata.core.rpc.netty.AbstractNettyRemotingServer; import io.seata.core.rpc.netty.NettyServerConfig; -import io.seata.core.rpc.processor.server.RegRmProcessor; -import io.seata.core.rpc.processor.server.RegTmProcessor; import io.seata.core.rpc.processor.server.ServerHeartbeatProcessor; -import io.seata.core.rpc.processor.server.ServerOnRequestProcessor; -import io.seata.core.rpc.processor.server.ServerOnResponseProcessor; -import io.seata.mock.protocol.MockRemotingProcessor; +import io.seata.mockserver.processor.MockHeartbeatProcessor; +import io.seata.mockserver.processor.MockOnReqProcessor; +import io.seata.mockserver.processor.MockOnRespProcessor; +import io.seata.mockserver.processor.MockRemotingProcessor; +import io.seata.mockserver.processor.MockRegisterProcessor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; /** * The mock netty remoting server. @@ -52,17 +40,23 @@ public class MockNettyRemotingServer extends AbstractNettyRemotingServer { private static final Logger LOGGER = LoggerFactory.getLogger(MockNettyRemotingServer.class); + private TransactionMessageHandler handler; + + public void setHandler(TransactionMessageHandler transactionMessageHandler) { + this.handler = transactionMessageHandler; + } @Override public void init() { // registry processor registerProcessor(); + super.init(); } /** * Instantiates a new Rpc remoting server. * - * @param messageExecutor the message executor + * @param messageExecutor the message executor */ public MockNettyRemotingServer(ThreadPoolExecutor messageExecutor) { super(messageExecutor, new NettyServerConfig()); @@ -77,25 +71,9 @@ public void destroyChannel(String serverAddress, Channel channel) { channel.close(); } - private TransactionMessageHandler getHandler(){ - return new TransactionMessageHandler() { - @Override - public AbstractResultMessage onRequest(AbstractMessage request, RpcContext context) { - return null; - } - - @Override - public void onResponse(AbstractResultMessage response, RpcContext context) { - - } - }; - } - private void registerProcessor() { // 1. registry on request message processor - ServerOnRequestProcessor onRequestProcessor = - new ServerOnRequestProcessor(this, getHandler()); - ShutdownHook.getInstance().addDisposable(onRequestProcessor); + MockOnReqProcessor onRequestProcessor = new MockOnReqProcessor(this, handler); super.registerProcessor(MessageType.TYPE_BRANCH_REGISTER, onRequestProcessor, messageExecutor); super.registerProcessor(MessageType.TYPE_BRANCH_STATUS_REPORT, onRequestProcessor, messageExecutor); super.registerProcessor(MessageType.TYPE_GLOBAL_BEGIN, onRequestProcessor, messageExecutor); @@ -107,21 +85,20 @@ private void registerProcessor() { super.registerProcessor(MessageType.TYPE_SEATA_MERGE, onRequestProcessor, messageExecutor); // 2. registry on response message processor - ServerOnResponseProcessor onResponseProcessor = - new ServerOnResponseProcessor(getHandler(), getFutures()); + MockOnRespProcessor onResponseProcessor = new MockOnRespProcessor(this, handler,getFutures()); super.registerProcessor(MessageType.TYPE_BRANCH_COMMIT_RESULT, onResponseProcessor, messageExecutor); super.registerProcessor(MessageType.TYPE_BRANCH_ROLLBACK_RESULT, onResponseProcessor, messageExecutor); - // 3. registry rm message processor - MockRemotingProcessor regRmProcessor = new MockRemotingProcessor( - RegisterRMResponse.class,this); + // 3. registry rm reg processor + MockRegisterProcessor regRmProcessor = new MockRegisterProcessor(this, MockRegisterProcessor.Role.RM); super.registerProcessor(MessageType.TYPE_REG_RM, regRmProcessor, messageExecutor); - // 4. registry tm message processor - MockRemotingProcessor regTmProcessor = new MockRemotingProcessor( - RegisterTMResponse.class,this); + + // 4. registry tm reg processor + MockRegisterProcessor regTmProcessor = new MockRegisterProcessor(this, MockRegisterProcessor.Role.TM); super.registerProcessor(MessageType.TYPE_REG_CLT, regTmProcessor, null); + // 5. registry heartbeat message processor - ServerHeartbeatProcessor heartbeatMessageProcessor = new ServerHeartbeatProcessor(this); + MockHeartbeatProcessor heartbeatMessageProcessor = new MockHeartbeatProcessor(this,handler); super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, heartbeatMessageProcessor, null); } diff --git a/test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockServer.java b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockServer.java new file mode 100644 index 00000000000..3a7e6297f38 --- /dev/null +++ b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/MockServer.java @@ -0,0 +1,70 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.mockserver; + +import io.seata.common.XID; +import io.seata.common.thread.NamedThreadFactory; +import io.seata.common.util.NetUtil; +import io.seata.server.UUIDGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import java.lang.management.ManagementFactory; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * The type Mock Server. + * + * @author Bughue + */ +@SpringBootApplication +public class MockServer { + + protected static final Logger LOGGER = LoggerFactory.getLogger(MockServer.class); + + /** + * The entry point of application. + * + * @param args the input arguments + */ + public static void main(String[] args) { + SpringApplication.run(MockServer.class, args); + + ThreadPoolExecutor workingThreads = new ThreadPoolExecutor(50, + 50, 500, TimeUnit.SECONDS, + new LinkedBlockingQueue<>(20000), + new NamedThreadFactory("ServerHandlerThread", 500), new ThreadPoolExecutor.CallerRunsPolicy()); + + MockNettyRemotingServer nettyRemotingServer = new MockNettyRemotingServer(workingThreads); + + // set registry + XID.setIpAddress(NetUtil.getLocalIp()); + XID.setPort(8092); + // init snowflake for transactionId, branchId + UUIDGenerator.init(1L); + + MockCoordinator coordinator = new MockCoordinator(); + coordinator.setRemotingServer(nettyRemotingServer); + nettyRemotingServer.setHandler(coordinator); + nettyRemotingServer.init(); + + LOGGER.info("pid info: "+ ManagementFactory.getRuntimeMXBean().getName()); + } +} diff --git a/test-mock/test-mock-server/src/main/java/io/seata/mockserver/call/CallRm.java b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/call/CallRm.java new file mode 100644 index 00000000000..b693fb9a3a0 --- /dev/null +++ b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/call/CallRm.java @@ -0,0 +1,106 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.mockserver.call; + +import io.netty.channel.Channel; +import io.seata.core.model.BranchStatus; +import io.seata.core.model.BranchType; +import io.seata.core.protocol.transaction.AbstractBranchEndRequest; +import io.seata.core.protocol.transaction.BranchCommitRequest; +import io.seata.core.protocol.transaction.BranchCommitResponse; +import io.seata.core.protocol.transaction.BranchRollbackRequest; +import io.seata.core.protocol.transaction.BranchRollbackResponse; +import io.seata.core.protocol.transaction.UndoLogDeleteRequest; +import io.seata.core.rpc.RemotingServer; +import io.seata.core.rpc.netty.ChannelManager; + +import java.util.concurrent.TimeoutException; + +/** + * call rm + * + * @author minghua.xie + * @date 2023/11/21 + **/ +public class CallRm { + + /** + * call branchCommit :TYPE_BRANCH_COMMIT = 3 , TYPE_BRANCH_COMMIT_RESULT = 4 + * + * @param remotingServer + * @return + */ + public static BranchStatus branchCommit(RemotingServer remotingServer, String resourceId, String clientId) { + BranchCommitRequest request = new BranchCommitRequest(); + setReq(request, resourceId); + + try { + BranchCommitResponse response = (BranchCommitResponse) remotingServer.sendSyncRequest( + resourceId, clientId, request, false); + return response.getBranchStatus(); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + } + + + /** + * call branchRollback :TYPE_BRANCH_ROLLBACK = 5 , TYPE_BRANCH_ROLLBACK_RESULT = 6 + * + * @param remotingServer + * @return + */ + public static BranchStatus branchRollback(RemotingServer remotingServer, String resourceId, String clientId) { + BranchRollbackRequest request = new BranchRollbackRequest(); + setReq(request, resourceId); + + try { + BranchRollbackResponse response = (BranchRollbackResponse) remotingServer.sendSyncRequest( + resourceId, clientId, request, false); + return response.getBranchStatus(); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + } + + /** + * call deleteUndoLog :TYPE_RM_DELETE_UNDOLOG = 111 + * + * @param remotingServer + * @return + */ + public static void deleteUndoLog(RemotingServer remotingServer, String resourceId, String clientId) { + UndoLogDeleteRequest request = new UndoLogDeleteRequest(); + request.setResourceId(resourceId); + request.setSaveDays((short) 1); + request.setBranchType(BranchType.TCC); + try { + Channel channel = ChannelManager.getChannel(resourceId, clientId, false); + remotingServer.sendAsyncRequest(channel, request); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static void setReq(AbstractBranchEndRequest request, String resourceId) { + request.setXid("1"); + request.setBranchId(1L); + request.setResourceId(resourceId); + request.setApplicationData("{\"k\":\"v\"}"); + request.setBranchType(BranchType.TCC); + // todo AT SAGA + } +} diff --git a/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockHeartbeatProcessor.java b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockHeartbeatProcessor.java new file mode 100644 index 00000000000..ba49135ebd9 --- /dev/null +++ b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockHeartbeatProcessor.java @@ -0,0 +1,25 @@ +package io.seata.mockserver.processor; + +import io.netty.channel.ChannelHandlerContext; +import io.seata.core.protocol.HeartbeatMessage; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.RemotingServer; +import io.seata.core.rpc.TransactionMessageHandler; + +/** + * ? + * + * @author minghua.xie + * @date 2023/11/29 + **/ +public class MockHeartbeatProcessor extends MockRemotingProcessor{ + public MockHeartbeatProcessor(RemotingServer remotingServer, TransactionMessageHandler handler) { + super(remotingServer, handler); + } + + @Override + public void process(ChannelHandlerContext ctx, RpcMessage rpcMessage) throws Exception { + super.process(ctx, rpcMessage); + remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), HeartbeatMessage.PONG); + } +} diff --git a/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockOnReqProcessor.java b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockOnReqProcessor.java new file mode 100644 index 00000000000..4e72dbd2d83 --- /dev/null +++ b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockOnReqProcessor.java @@ -0,0 +1,78 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.mockserver.processor; + +import io.netty.channel.ChannelHandlerContext; +import io.seata.core.protocol.AbstractMessage; +import io.seata.core.protocol.AbstractResultMessage; +import io.seata.core.protocol.MergeResultMessage; +import io.seata.core.protocol.MergedWarpMessage; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.RemotingServer; +import io.seata.core.rpc.RpcContext; +import io.seata.core.rpc.TransactionMessageHandler; +import io.seata.core.rpc.netty.ChannelManager; +import io.seata.core.rpc.processor.server.ServerOnRequestProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Mock Remoting Processor + * + * @author minghua.xie + * @date 2023/11/14 + **/ +public class MockOnReqProcessor extends MockRemotingProcessor { + protected static final Logger LOGGER = LoggerFactory.getLogger(MockOnReqProcessor.class); + + + public MockOnReqProcessor(RemotingServer remotingServer, TransactionMessageHandler handler) { + super(remotingServer, handler); + } + @Override + public void process(ChannelHandlerContext ctx, RpcMessage rpcMessage) throws Exception { + super.process(ctx, rpcMessage); + Object message = rpcMessage.getBody(); + + RpcContext rpcContext = ChannelManager.getContextFromIdentified(ctx.channel()); + + // the batch send request message + if (message instanceof MergedWarpMessage) { + MergedWarpMessage mmsg = (MergedWarpMessage) message; + MergeResultMessage resultMessage = new MergeResultMessage(); + List resList = new ArrayList<>(); + for (int i = 0; i < mmsg.msgs.size(); i++) { + AbstractMessage msg = mmsg.msgs.get(i); + resList.add(handler.onRequest(msg, rpcContext)); + } + AbstractResultMessage[] resultMsgs = Arrays.copyOf(resList.toArray(), resList.size(), AbstractResultMessage[].class); + resultMessage.setMsgs(resultMsgs); + remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), resultMessage); + LOGGER.info("sendAsyncResponse: {}", resultMessage); + } else { + final AbstractMessage msg = (AbstractMessage) message; + AbstractResultMessage result = handler.onRequest(msg, rpcContext); + remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), result); + LOGGER.info("sendAsyncResponse: {}", result); + } + } + + +} diff --git a/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockOnRespProcessor.java b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockOnRespProcessor.java new file mode 100644 index 00000000000..a88b312473e --- /dev/null +++ b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockOnRespProcessor.java @@ -0,0 +1,55 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.mockserver.processor; + +import io.netty.channel.ChannelHandlerContext; +import io.seata.core.protocol.MessageFuture; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.RemotingServer; +import io.seata.core.rpc.TransactionMessageHandler; +import io.seata.core.rpc.netty.ChannelManager; +import io.seata.core.rpc.processor.RemotingProcessor; + +import java.util.concurrent.ConcurrentMap; + +/** + * Mock Remoting Processor + * + * @author minghua.xie + * @date 2023/11/14 + **/ +public class MockOnRespProcessor extends MockRemotingProcessor { + + private ConcurrentMap futures; + + + public MockOnRespProcessor(RemotingServer remotingServer, TransactionMessageHandler handler + , ConcurrentMap futures) { + super(remotingServer, handler); + this.futures = futures; + } + + @Override + public void process(ChannelHandlerContext ctx, RpcMessage rpcMessage) throws Exception { + super.process(ctx, rpcMessage); + MessageFuture messageFuture = futures.remove(rpcMessage.getId()); + if (messageFuture != null) { + messageFuture.setResultMessage(rpcMessage.getBody()); + } + } + + +} diff --git a/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockRegisterProcessor.java b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockRegisterProcessor.java new file mode 100644 index 00000000000..fea7a6a8bf0 --- /dev/null +++ b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockRegisterProcessor.java @@ -0,0 +1,78 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.mockserver.processor; + +import io.netty.channel.ChannelHandlerContext; +import io.seata.core.protocol.HeartbeatMessage; +import io.seata.core.protocol.RegisterRMRequest; +import io.seata.core.protocol.RegisterRMResponse; +import io.seata.core.protocol.RegisterTMRequest; +import io.seata.core.protocol.RegisterTMResponse; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.protocol.Version; +import io.seata.core.rpc.RemotingServer; +import io.seata.core.rpc.netty.ChannelManager; +import io.seata.core.rpc.processor.RemotingProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Mock Remoting Processor + * + * @author minghua.xie + * @date 2023/11/14 + **/ +public class MockRegisterProcessor implements RemotingProcessor { + + protected static final Logger LOGGER = LoggerFactory.getLogger(MockRegisterProcessor.class); + private RemotingServer remotingServer; + private Role role; + + public MockRegisterProcessor(RemotingServer remotingServer, Role role) { + this.remotingServer = remotingServer; + this.role = role; + } + + @Override + public void process(ChannelHandlerContext ctx, RpcMessage rpcMessage) throws Exception { + if (role == Role.TM) { + RegisterTMRequest message = (RegisterTMRequest) rpcMessage.getBody(); + LOGGER.info("message = " + message); + + ChannelManager.registerTMChannel(message, ctx.channel()); + Version.putChannelVersion(ctx.channel(), message.getVersion()); + + RegisterTMResponse resp = new RegisterTMResponse(); + remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), resp); + LOGGER.info("sendAsyncResponse: {}", resp); + } else if (role == Role.RM) { + RegisterRMRequest message = (RegisterRMRequest) rpcMessage.getBody(); + LOGGER.info("message = " + message); + + ChannelManager.registerRMChannel(message, ctx.channel()); + Version.putChannelVersion(ctx.channel(), message.getVersion()); + + RegisterRMResponse resp = new RegisterRMResponse(); + remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), resp); + LOGGER.info("sendAsyncResponse: {}", resp); + } + } + + + public static enum Role { + TM, RM + } +} diff --git a/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockRemotingProcessor.java b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockRemotingProcessor.java new file mode 100644 index 00000000000..011c0cb7afd --- /dev/null +++ b/test-mock/test-mock-server/src/main/java/io/seata/mockserver/processor/MockRemotingProcessor.java @@ -0,0 +1,52 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.seata.mockserver.processor; + +import io.netty.channel.ChannelHandlerContext; +import io.seata.core.protocol.RpcMessage; +import io.seata.core.rpc.RemotingServer; +import io.seata.core.rpc.TransactionMessageHandler; +import io.seata.core.rpc.processor.RemotingProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Mock Remoting Processor + * + * @author minghua.xie + * @date 2023/11/14 + **/ +public class MockRemotingProcessor implements RemotingProcessor { + + protected static final Logger LOGGER = LoggerFactory.getLogger(MockRemotingProcessor.class); + protected RemotingServer remotingServer; + protected final TransactionMessageHandler handler; + + + public MockRemotingProcessor(RemotingServer remotingServer, TransactionMessageHandler handler) { + this.remotingServer = remotingServer; + this.handler = handler; + } + + @Override + public void process(ChannelHandlerContext ctx, RpcMessage rpcMessage) throws Exception { + Object message = rpcMessage.getBody(); + LOGGER.info("process message : " + message); + + } + + +} diff --git a/test-mock/test-mock-server/src/main/resources/application.yml b/test-mock/test-mock-server/src/main/resources/application.yml new file mode 100644 index 00000000000..37cee3e20bf --- /dev/null +++ b/test-mock/test-mock-server/src/main/resources/application.yml @@ -0,0 +1,53 @@ +# Copyright 1999-2019 Seata.io Group. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${log.home:${user.home}/logs/seata} + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata +seata: + config: + # support: nacos, consul, apollo, zk, etcd3 + type: file + registry: + # support: nacos, eureka, redis, zk, consul, etcd3, sofa + type: file + store: + # support: file 、 db 、 redis 、 raft + mode: file + # server: + # service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/metadata/v1/** diff --git a/test-mock/test-mock-server/src/main/resources/logback-spring.xml b/test-mock/test-mock-server/src/main/resources/logback-spring.xml new file mode 100644 index 00000000000..490141ac6c5 --- /dev/null +++ b/test-mock/test-mock-server/src/main/resources/logback-spring.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + 0 + 2048 + true + + + + + true + 0 + 2048 + true + + + + true + 0 + 1024 + true + + + + true + 0 + 1024 + true + + + + + + + + + + + + + + + + + + + diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java deleted file mode 100644 index fad37c5fcc1..00000000000 --- a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockNettyClient.java +++ /dev/null @@ -1,86 +0,0 @@ -package io.seata.mock.protocol; - -import io.netty.channel.Channel; -import io.netty.util.concurrent.EventExecutorGroup; -import io.seata.core.protocol.AbstractMessage; -import io.seata.core.protocol.MessageType; -import io.seata.core.rpc.netty.AbstractNettyRemotingClient; -import io.seata.core.rpc.netty.NettyClientConfig; -import io.seata.core.rpc.netty.NettyPoolKey; -import io.seata.core.rpc.processor.client.ClientHeartbeatProcessor; - -import java.util.concurrent.ThreadPoolExecutor; -import java.util.function.Function; - -/** - * mock client - * - * @author minghua.xie - * @date 2023/11/10 - **/ -public class MockNettyClient extends AbstractNettyRemotingClient { - public MockNettyClient(NettyClientConfig nettyClientConfig, EventExecutorGroup eventExecutorGroup, ThreadPoolExecutor messageExecutor, NettyPoolKey.TransactionRole transactionRole) { - super(nettyClientConfig, eventExecutorGroup, messageExecutor, transactionRole); - } - - @Override - public void onRegisterMsgSuccess(String serverAddress, Channel channel, Object response, AbstractMessage requestMessage) { - - } - - @Override - public void onRegisterMsgFail(String serverAddress, Channel channel, Object response, AbstractMessage requestMessage) { - - } - - @Override - protected Function getPoolKeyFunction() { - return null; - } - - @Override - protected String getTransactionServiceGroup() { - return null; - } - - @Override - protected boolean isEnableClientBatchSendRequest() { - return false; - } - - @Override - protected long getRpcRequestTimeout() { - return 0; - } - - - private void registerProcessor() { -// ClientHeartbeatProcessor clientHeartbeatProcessor = new ClientHeartbeatProcessor(); -// super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, clientHeartbeatProcessor, null); -// -// ; -// super.registerProcessor(MessageType.TYPE_SEATA_MERGE_RESULT, new MockRemotingProcessor<>(), null); -// super.registerProcessor(MessageType.TYPE_BATCH_RESULT_MSG, onResponseProcessor, null); -// super.registerProcessor(MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT, onResponseProcessor, null); -// -// -// super.registerProcessor(MessageType.TYPE_REG_RM_RESULT, onResponseProcessor, null); -// super.registerProcessor(MessageType.TYPE_RM_DELETE_UNDOLOG, rmUndoLogProcessor, messageExecutor); -// super.registerProcessor(MessageType.TYPE_BRANCH_COMMIT, rmBranchCommitProcessor, messageExecutor); -// super.registerProcessor(MessageType.TYPE_BRANCH_ROLLBACK, rmBranchRollbackProcessor, messageExecutor); -// super.registerProcessor(MessageType.TYPE_BRANCH_REGISTER_RESULT, onResponseProcessor, null); -// super.registerProcessor(MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT, onResponseProcessor, null); -// -// -// super.registerProcessor(MessageType.TYPE_GLOBAL_BEGIN_RESULT, onResponseProcessor, null); -// super.registerProcessor(MessageType.TYPE_GLOBAL_COMMIT_RESULT, onResponseProcessor, null); -// super.registerProcessor(MessageType.TYPE_GLOBAL_REPORT_RESULT, onResponseProcessor, null); -// super.registerProcessor(MessageType.TYPE_GLOBAL_ROLLBACK_RESULT, onResponseProcessor, null); -// super.registerProcessor(MessageType.TYPE_GLOBAL_STATUS_RESULT, onResponseProcessor, null); -// super.registerProcessor(MessageType.TYPE_REG_CLT_RESULT, onResponseProcessor, null); -// super.registerProcessor(MessageType.TYPE_BATCH_RESULT_MSG, onResponseProcessor, null); -// // 2.registry heartbeat message processor -// ClientHeartbeatProcessor clientHeartbeatProcessor = new ClientHeartbeatProcessor(); -// super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, clientHeartbeatProcessor, null); - } -} diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockRemotingProcessor.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockRemotingProcessor.java deleted file mode 100644 index ddacffc3eb3..00000000000 --- a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/MockRemotingProcessor.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.seata.mock.protocol; - -import io.netty.channel.ChannelHandlerContext; -import io.seata.core.protocol.RpcMessage; -import io.seata.core.rpc.RemotingServer; -import io.seata.core.rpc.processor.RemotingProcessor; - -/** - * Mock Remoting Processor - * - * @author minghua.xie - * @date 2023/11/14 - **/ -public class MockRemotingProcessor implements RemotingProcessor { - - private Class clazz; - private RemotingServer remotingServer; - - public MockRemotingProcessor(Class clazz, RemotingServer remotingServer) { - this.clazz = clazz; - this.remotingServer = remotingServer; - } - - @Override - public void process(ChannelHandlerContext ctx, RpcMessage rpcMessage) throws Exception { - REQ message = (REQ) rpcMessage.getBody(); - System.out.println("message = " + message); - - RESP resp = clazz.newInstance(); - remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), resp); - } - - -} diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/rm/v1/MockRmClient.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/rm/v1/MockRmClient.java deleted file mode 100644 index 327699ab7f7..00000000000 --- a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/rm/v1/MockRmClient.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.seata.mock.protocol.rm.v1; - -import io.netty.util.concurrent.EventExecutorGroup; -import io.seata.core.rpc.netty.NettyClientConfig; -import io.seata.core.rpc.netty.NettyPoolKey; -import io.seata.mock.protocol.MockNettyClient; - -import java.util.concurrent.ThreadPoolExecutor; - -/** - * ? - * - * @author minghua.xie - * @date 2023/11/10 - **/ -public class MockRmClient extends MockNettyClient { - public MockRmClient(NettyClientConfig nettyClientConfig, EventExecutorGroup eventExecutorGroup, ThreadPoolExecutor messageExecutor, NettyPoolKey.TransactionRole transactionRole) { - super(nettyClientConfig, eventExecutorGroup, messageExecutor, transactionRole); - } - -} diff --git a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java b/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java deleted file mode 100644 index bdbc6092162..00000000000 --- a/test-protocol-mock-server/src/main/java/io/seata/mock/protocol/tm/v1/MockTmClient.java +++ /dev/null @@ -1,46 +0,0 @@ -package io.seata.mock.protocol.tm.v1; - -import io.netty.channel.Channel; -import io.netty.util.concurrent.EventExecutorGroup; -import io.seata.core.protocol.AbstractMessage; -import io.seata.core.protocol.MessageType; -import io.seata.core.rpc.netty.AbstractNettyRemotingClient; -import io.seata.core.rpc.netty.NettyClientConfig; -import io.seata.core.rpc.netty.NettyPoolKey; -import io.seata.core.rpc.processor.client.ClientHeartbeatProcessor; -import io.seata.core.rpc.processor.client.ClientOnResponseProcessor; -import io.seata.mock.protocol.MockNettyClient; - -import java.util.concurrent.ThreadPoolExecutor; -import java.util.function.Function; - -/** - * ? - * - * @author minghua.xie - * @date 2023/11/10 - **/ -public class MockTmClient extends MockNettyClient { - public MockTmClient(NettyClientConfig nettyClientConfig, EventExecutorGroup eventExecutorGroup, ThreadPoolExecutor messageExecutor, NettyPoolKey.TransactionRole transactionRole) { - super(nettyClientConfig, eventExecutorGroup, messageExecutor, transactionRole); - } - - @Override - public void init() { - super.init(); - // 1.registry TC response processor - ClientOnResponseProcessor onResponseProcessor = - new ClientOnResponseProcessor(mergeMsgMap, super.getFutures(), getTransactionMessageHandler()); - super.registerProcessor(MessageType.TYPE_SEATA_MERGE_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_GLOBAL_BEGIN_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_GLOBAL_COMMIT_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_GLOBAL_REPORT_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_GLOBAL_ROLLBACK_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_GLOBAL_STATUS_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_REG_CLT_RESULT, onResponseProcessor, null); - super.registerProcessor(MessageType.TYPE_BATCH_RESULT_MSG, onResponseProcessor, null); - // 2.registry heartbeat message processor - ClientHeartbeatProcessor clientHeartbeatProcessor = new ClientHeartbeatProcessor(); - super.registerProcessor(MessageType.TYPE_HEARTBEAT_MSG, clientHeartbeatProcessor, null); - } -} diff --git a/test-protocol-mock-server/src/test/resources/README.md b/test-protocol-mock-server/src/test/resources/README.md deleted file mode 100644 index fc7352a038a..00000000000 --- a/test-protocol-mock-server/src/test/resources/README.md +++ /dev/null @@ -1,2 +0,0 @@ -## seata 多版本协议 mock server -## \ No newline at end of file From 93386458d12b2df092f6b2b5abe86f4dd0db4e43 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Thu, 30 Nov 2023 14:48:23 +0800 Subject: [PATCH 21/22] mock test --- .../main/java/io/seata/serializer/seata/SeataSerializer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java index cdc6e6c0e5c..9662eeb1844 100644 --- a/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java +++ b/serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java @@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.seata.common.loader.LoadLevel; +import io.seata.common.util.BufferUtils; import io.seata.common.loader.Scope; import io.seata.core.protocol.AbstractMessage; import io.seata.core.protocol.ProtocolConstants; @@ -75,7 +76,7 @@ public byte[] serialize(T t) { } byteBuffer.put(body); - byteBuffer.flip(); + BufferUtils.flip(byteBuffer); byte[] content = new byte[byteBuffer.limit()]; byteBuffer.get(content); return content; From bb41c7f62aeb350630d78027dc93f0641f31e4d8 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Thu, 30 Nov 2023 14:58:15 +0800 Subject: [PATCH 22/22] log --- test-mock/test-client-v1-1.6.0/pom.xml | 5 +++++ test-mock/test-client-v1/pom.xml | 20 +++++--------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/test-mock/test-client-v1-1.6.0/pom.xml b/test-mock/test-client-v1-1.6.0/pom.xml index 997ccd3175c..3720e04ba93 100644 --- a/test-mock/test-client-v1-1.6.0/pom.xml +++ b/test-mock/test-client-v1-1.6.0/pom.xml @@ -32,6 +32,11 @@ seata-all 1.6.0 + + ch.qos.logback + logback-classic + 1.2.12 + diff --git a/test-mock/test-client-v1/pom.xml b/test-mock/test-client-v1/pom.xml index 358d9f67f1d..29a79394b56 100644 --- a/test-mock/test-client-v1/pom.xml +++ b/test-mock/test-client-v1/pom.xml @@ -36,21 +36,11 @@ - - - - - - - - - - - - - - - + + ch.qos.logback + logback-classic + 1.2.12 + \ No newline at end of file