Skip to content

Commit

Permalink
rename UserContextResolver to UserContext
Browse files Browse the repository at this point in the history
  • Loading branch information
MrChang0 committed May 8, 2024
1 parent 5866955 commit 6d86bcf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,8 @@ public void writeClassDefs(MemoryBuffer buffer) {

/** write user context by register order. */
public void writeUserContext(MemoryBuffer buffer) {
final Map<String, UserContext> userContextResolvers =
fury.getSerializationContext().getUserContextResolvers();
for (UserContext userContext : userContextResolvers.values()) {
final Map<String, UserContext> userContexts = fury.getSerializationContext().getUserContexts();
for (UserContext userContext : userContexts.values()) {
userContext.write(buffer);
}
}
Expand Down Expand Up @@ -1457,9 +1456,8 @@ public void readClassDefs(MemoryBuffer buffer) {

/** read user context by register order. */
public void readUserContext(MemoryBuffer buffer) {
final Map<String, UserContext> userContextResolvers =
fury.getSerializationContext().getUserContextResolvers();
for (UserContext userContext : userContextResolvers.values()) {
final Map<String, UserContext> userContexts = fury.getSerializationContext().getUserContexts();
for (UserContext userContext : userContexts.values()) {
userContext.read(buffer);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public final class SerializationContext {
private final IdentityHashMap<Object, Object> objects = new IdentityHashMap<>();
private MetaContext metaContext;
private final Map<String, UserContext> userContextResolvers = new LinkedHashMap<>();
private final Map<String, UserContext> userContexts = new LinkedHashMap<>();

/** Return the previous value associated with <tt>key</tt>, or <tt>null</tt>. */
public Object add(Object key, Object value) {
Expand Down Expand Up @@ -62,21 +62,21 @@ public void setMetaContext(MetaContext metaContext) {
this.metaContext = metaContext;
}

public Map<String, UserContext> getUserContextResolvers() {
return userContextResolvers;
public Map<String, UserContext> getUserContexts() {
return userContexts;
}

public void registerUserContextResolver(String name, UserContext userContext) {
Preconditions.checkState(!userContextResolvers.containsKey(name));
userContextResolvers.put(name, userContext);
Preconditions.checkState(!userContexts.containsKey(name));
userContexts.put(name, userContext);
}

public void reset() {
if (objects.size() > 0) {
objects.clear();
}
metaContext = null;
for (UserContext userContext : userContextResolvers.values()) {
for (UserContext userContext : userContexts.values()) {
userContext.reset();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,24 @@ public FooSerializer(Fury fury, Class<Foo> type) {

@Override
public void write(MemoryBuffer buffer, Foo value) {
final Map<String, UserContext> userContextResolvers =
fury.getSerializationContext().getUserContextResolvers();
final Map<String, UserContext> userContexts =
fury.getSerializationContext().getUserContexts();
for (int i = 0; i < NUM; i++) {
final StringUserContext userContextResolver =
(StringUserContext) userContextResolvers.get(String.valueOf(i));
userContextResolver.data = getData(i);
final StringUserContext userContext =
(StringUserContext) userContexts.get(String.valueOf(i));
userContext.data = getData(i);
}
serializer.write(buffer, value);
}

@Override
public Foo read(MemoryBuffer buffer) {
final Map<String, UserContext> userContextResolvers =
fury.getSerializationContext().getUserContextResolvers();
final Map<String, UserContext> userContexts =
fury.getSerializationContext().getUserContexts();
for (int i = 0; i < NUM; i++) {
final StringUserContext userContextResolver =
(StringUserContext) userContextResolvers.get(String.valueOf(i));
Assert.assertEquals(userContextResolver.data, getData(i));
final StringUserContext userContext =
(StringUserContext) userContexts.get(String.valueOf(i));
Assert.assertEquals(userContext.data, getData(i));
}
return serializer.read(buffer);
}
Expand All @@ -110,9 +110,9 @@ public void checkShareUserContext() {
fury.registerSerializer(Foo.class, FooSerializer.class);
List<StringUserContext> resolvers = new ArrayList<>(NUM);
for (int i = 0; i < NUM; i++) {
final StringUserContext userContextResolver = new StringUserContext(fury);
final StringUserContext userContext = new StringUserContext(fury);
fury.registerUserContext(String.valueOf(i), StringUserContext::new);
resolvers.add(userContextResolver);
resolvers.add(userContext);
}
final Foo o = Foo.create();
final byte[] bytes = fury.serialize(o);
Expand Down

0 comments on commit 6d86bcf

Please sign in to comment.