Skip to content

Commit

Permalink
fix codecSuffix
Browse files Browse the repository at this point in the history
  • Loading branch information
chaokunyang committed Sep 24, 2024
1 parent 435ed3d commit 7126ef6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,10 @@ public String codecClassName(Class<?> beanClass) {
} else {
nameBuilder.append("Fury");
}
nameBuilder.append("Codec");
nameBuilder.append("Codec").append(codecSuffix());
Map<String, Integer> subGenerator =
idGenerator.computeIfAbsent(nameBuilder.toString(), k -> new ConcurrentHashMap<>());
String key =
codecSuffix()
+ "_"
+ fury.getConfig().getConfigHash()
+ "_"
+ CodeGenerator.getClassUniqueId(beanClass);
String key = fury.getConfig().getConfigHash() + "_" + CodeGenerator.getClassUniqueId(beanClass);
Integer id = subGenerator.get(key);
if (id == null) {
synchronized (subGenerator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import static org.apache.fury.builder.Generated.GeneratedMetaSharedSerializer.SERIALIZER_FIELD_NAME;

import java.util.Collection;
import java.util.Map;
import java.util.SortedMap;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.fury.Fury;
import org.apache.fury.builder.Generated.GeneratedMetaSharedSerializer;
import org.apache.fury.codegen.CodeGenerator;
Expand Down Expand Up @@ -86,11 +88,19 @@ public MetaSharedCodecBuilder(TypeRef<?> beanType, Fury fury, ClassDef classDef)
new ObjectCodecOptimizer(beanClass, grouper, !fury.isBasicTypesRefIgnored(), ctx);
}

private final Map<Long, Integer> idGenerator = new ConcurrentHashMap<>();

@Override
protected String codecSuffix() {
// For every class def sent from different peer, if the class def are different, then
// a new serializer needs being generated.
return "MetaShared" + classDef.getId();
Integer id = idGenerator.get(classDef.getId());
if (id == null) {
synchronized (idGenerator) {
id = idGenerator.computeIfAbsent(classDef.getId(), k -> idGenerator.size());
}
}
return "MetaShared" + id;
}

@Override
Expand Down

0 comments on commit 7126ef6

Please sign in to comment.