-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(java): Support copy capabilities for some classes without no-argument constructors #1794
feat(java): Support copy capabilities for some classes without no-argument constructors #1794
Conversation
…no_arg_class_copy
…ub.com/zhaommmmomo/fury into feat/support_without_no_arg_class_copy
@Override | ||
public Object copy(Object value) { | ||
Serializer serializer = classClassInfoHolderMap.get(value.getClass()).objectSerializer; | ||
return fury.copyObject(value, serializer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to invoke resolve method?
@@ -439,6 +441,28 @@ protected <K, V> void copyEntry(Map<K, V> originMap, Map<K, V> newMap) { | |||
} | |||
} | |||
|
|||
protected <K, V> void copyEntry(Map<K, V> originMap, Builder<K, V> builder) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we overwrite this method, we shoud add @Override
annotation
@Override | ||
public T copy(T originCollection) { | ||
if (slotsSerializers.length == 0) { | ||
return super.copy(originCollection); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will return an object of super class type, which is not right
if (slotsSerializers.length == 0) { | ||
return super.copy(originCollection); | ||
} | ||
return (T) slotsSerializers[0].copy(originCollection); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return an object of first field
|
||
@Override | ||
public T copy(T originMap) { | ||
if (slotsSerializers.length == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issues
@@ -79,6 +79,21 @@ public void copyElements(T originCollection, Collection newCollection) { | |||
} | |||
} | |||
|
|||
public void copyElements(T originCollection, Object[] elements) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add @Override
annotation
@Override | ||
public ByteBuffer copy(ByteBuffer value) { | ||
ByteBuffer dst = ByteBuffer.allocate(value.capacity()); | ||
dst.put(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dst.put(value); | |
dst.put(value.duplicate()); |
We need to duplicate
, otherwise it will update offset in ByteBuffer
@@ -44,6 +44,13 @@ public void write(MemoryBuffer buffer, ByteBuffer value) { | |||
fury.writeBufferObject(buffer, new BufferObject.ByteBufferBufferObject(value)); | |||
} | |||
|
|||
@Override | |||
public ByteBuffer copy(ByteBuffer value) { | |||
ByteBuffer dst = ByteBuffer.allocate(value.capacity()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ByteBuffer dst = ByteBuffer.allocate(value.capacity()); | |
ByteBuffer dst = ByteBuffer.allocate(value.remaining()); |
Preconditions.checkNotNull(interfaces); | ||
Preconditions.checkNotNull(invocationHandler); | ||
Object proxy = Proxy.newProxyInstance(fury.getClassLoader(), interfaces, STUB_HANDLER); | ||
Platform.putObject(proxy, PROXY_HANDLER_FIELD_OFFSET, invocationHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Platform.putObject(proxy, PROXY_HANDLER_FIELD_OFFSET, invocationHandler); | |
Object proxy = Proxy.newProxyInstance(fury.getClassLoader(), interfaces, STUB_HANDLER); | |
fury.reference(value, proxy); | |
Platform.putObject(proxy, PROXY_HANDLER_FIELD_OFFSET, | |
fury.copyObject(invocationHandler)); |
@@ -542,6 +542,35 @@ public Collection newCollection() { | |||
} | |||
} | |||
|
|||
public void copyElements(Collection originCollection, Collection newCollection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CollectionSerializer has same method, could we remove that method?
@Override | ||
public T copy(T originCollection) { | ||
if (objectSerializer == null) { | ||
objectSerializer = new ObjectSerializer<>(fury, type, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we update ObjectSerializer
:
public ObjectSerializer(Fury fury, Class<T> cls, boolean resolveParent) {
super(fury, cls);
// avoid recursive building serializers.
// Use `setSerializerIfAbsent` to avoid overwriting existing serializer for class when used
// as data serializer.
if (resolveParent) {
classResolver.setSerializerIfAbsent(cls, this);
}
Very nice work, thank you @zhaommmmomo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this is not an easy work, thanks for your contribution @zhaommmmomo
This is what I should do |
What does this PR do?
Some classes with no-argument constructors will report an error when calling
copy()
.This pr:
Related issues
#1777
#1679
Does this PR introduce any user-facing change?
Benchmark