Skip to content

Commit

Permalink
codec map match
Browse files Browse the repository at this point in the history
  • Loading branch information
Bughue committed Nov 14, 2024
1 parent cca29e6 commit 2826e7c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public interface MultiVersionCodec {
* version range (begin, end]
*/
class VersionRange {
String begin;
String end;
private String begin;
private String end;

public VersionRange(String begin, String end) {
this.begin = begin;
Expand All @@ -23,5 +23,13 @@ public VersionRange(String end) {
this.begin = "0";
this.end = end;
}

public String getBegin() {
return begin;
}

public String getEnd() {
return end;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import org.apache.seata.core.protocol.IncompatibleVersionException;
import org.apache.seata.core.protocol.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
* the type MultiVersionCodecHelper
*
* @author minghua.xie
* @date 2024/11/6
**/
public class MultiVersionCodecHelper {

private static final Logger LOGGER = LoggerFactory.getLogger(MultiVersionCodecHelper.class);

public static MessageSeataCodec match(String v, MessageSeataCodec messageCodec) {
try {
if (!(messageCodec instanceof MultiVersionCodec)) {
Expand All @@ -21,13 +23,13 @@ public static MessageSeataCodec match(String v, MessageSeataCodec messageCodec)
Map<MultiVersionCodec.VersionRange, MessageSeataCodec> map = ((MultiVersionCodec) messageCodec).oldVersionCodec();
long version = Version.convertVersion(v);
for (MultiVersionCodec.VersionRange range : map.keySet()) {
if (version > Version.convertVersion(range.begin) &&
version <= Version.convertVersion(range.end)) {
if (version > Version.convertVersion(range.getBegin()) &&
version <= Version.convertVersion(range.getEnd())) {
return map.get(version);
}
}
} catch (IncompatibleVersionException e) {
// todo 【我的todo】
LOGGER.error("match version error", e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Class<?> getMessageClassType() {
public Map<MultiVersionCodec.VersionRange, MessageSeataCodec> oldVersionCodec() {
return Collections.singletonMap(
// todo 【我的todo】
new MultiVersionCodec.VersionRange("2.2.0"),
new MultiVersionCodec.VersionRange("2.1.0"),
new MessageSeataCodec() {
@Override
public Class<?> getMessageClassType() {
Expand Down

0 comments on commit 2826e7c

Please sign in to comment.