This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-fury.git


The following commit(s) were added to refs/heads/main by this push:
     new 9687fd8e feat(java): Support CopyOnWriteArrayListSerializer (#1613)
9687fd8e is described below

commit 9687fd8e97938d07cedff2197ebdc4bcbff15c75
Author: 李舒畅 <lsc...@hotmail.com>
AuthorDate: Wed May 8 23:21:58 2024 +0800

    feat(java): Support CopyOnWriteArrayListSerializer (#1613)
    
    
    
    ## What does this PR do?
    
    <!-- Describe the purpose of this PR. -->
    
    Support CopyOnWriteArrayListSerializer
    
    ## Related issues
    
    <!--
    Is there any related issue? Please attach here.
    
    - #xxxx0
    - #xxxx1
    - #xxxx2
    -->
    
    
    ## Does this PR introduce any user-facing change?
    
    <!--
    If any user-facing interface changes, please [open an
    issue](https://github.com/apache/incubator-fury/issues/new/choose)
    describing the need to do so and update the document if necessary.
    -->
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    
    ## Benchmark
    
    <!--
    When the PR has an impact on performance (if you don't know whether the
    PR will have an impact on performance, you can submit the PR first, and
    if it will have impact on performance, the code reviewer will explain
    it), be sure to attach a benchmark data here.
    -->
---
 .../collection/CollectionSerializers.java          | 25 ++++++++++++++++++++++
 .../fury-core/native-image.properties              |  1 +
 .../collection/CollectionSerializersTest.java      | 11 ++++++++++
 3 files changed, 37 insertions(+)

diff --git 
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/CollectionSerializers.java
 
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/CollectionSerializers.java
index 744eddfa..7e149508 100644
--- 
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/CollectionSerializers.java
+++ 
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/CollectionSerializers.java
@@ -39,6 +39,7 @@ import java.util.SortedSet;
 import java.util.TreeSet;
 import java.util.Vector;
 import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.CopyOnWriteArrayList;
 import org.apache.fury.Fury;
 import org.apache.fury.config.Language;
 import org.apache.fury.exception.FuryException;
@@ -255,6 +256,27 @@ public class CollectionSerializers {
     }
   }
 
+  public static class CopyOnWriteArrayListSerializer
+      extends CollectionSerializer<CopyOnWriteArrayList> {
+
+    public CopyOnWriteArrayListSerializer(Fury fury, 
Class<CopyOnWriteArrayList> type) {
+      super(fury, type);
+    }
+
+    @Override
+    public Collection newCollection(MemoryBuffer buffer) {
+      int numElements = buffer.readVarUint32Small7();
+      setNumElements(numElements);
+      return new CollectionContainer<>(numElements);
+    }
+
+    @Override
+    public CopyOnWriteArrayList onCollectionRead(Collection collection) {
+      Object[] elements = ((CollectionContainer) collection).elements;
+      return new CopyOnWriteArrayList(elements);
+    }
+  }
+
   public static final class EmptySetSerializer extends 
CollectionSerializer<Set<?>> {
 
     public EmptySetSerializer(Fury fury, Class<Set<?>> cls) {
@@ -624,5 +646,8 @@ public class CollectionSerializers {
     fury.registerSerializer(BitSet.class, new BitSetSerializer(fury, 
BitSet.class));
     fury.registerSerializer(
         PriorityQueue.class, new PriorityQueueSerializer(fury, 
PriorityQueue.class));
+    fury.registerSerializer(
+        CopyOnWriteArrayList.class,
+        new CopyOnWriteArrayListSerializer(fury, CopyOnWriteArrayList.class));
   }
 }
diff --git 
a/java/fury-core/src/main/resources/META-INF/native-image/org.apache.fury/fury-core/native-image.properties
 
b/java/fury-core/src/main/resources/META-INF/native-image/org.apache.fury/fury-core/native-image.properties
index 8a14afa9..2733515f 100644
--- 
a/java/fury-core/src/main/resources/META-INF/native-image/org.apache.fury/fury-core/native-image.properties
+++ 
b/java/fury-core/src/main/resources/META-INF/native-image/org.apache.fury/fury-core/native-image.properties
@@ -22,6 +22,7 @@ 
Args=--initialize-at-build-time=org.apache.fury.memory.MemoryBuffer,\
     org.apache.fury.serializer.collection.UnmodifiableSerializers$Offset,\
     org.apache.fury.serializer.collection.SynchronizedSerializers$Offset,\
     
org.apache.fury.serializer.collection.CollectionSerializers$ArraysAsListSerializer,\
+    
org.apache.fury.serializer.collection.CollectionSerializers$CopyOnWriteArrayListSerializer,\
     org.apache.fury.serializer.collection.MapSerializers$EnumMapSerializer,\
     org.apache.fury.serializer.JdkProxySerializer,\
     org.apache.fury.serializer.StringSerializer$Offset,\
diff --git 
a/java/fury-core/src/test/java/org/apache/fury/serializer/collection/CollectionSerializersTest.java
 
b/java/fury-core/src/test/java/org/apache/fury/serializer/collection/CollectionSerializersTest.java
index d7cd2944..83bbfcd8 100644
--- 
a/java/fury-core/src/test/java/org/apache/fury/serializer/collection/CollectionSerializersTest.java
+++ 
b/java/fury-core/src/test/java/org/apache/fury/serializer/collection/CollectionSerializersTest.java
@@ -52,6 +52,7 @@ import java.util.TreeSet;
 import java.util.Vector;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.stream.LongStream;
 import lombok.AllArgsConstructor;
@@ -263,6 +264,16 @@ public class CollectionSerializersTest extends 
FuryTestBase {
         CollectionSerializers.PriorityQueueSerializer.class);
   }
 
+  @Test
+  public void testCopyOnWriteArrayList() {
+    final CopyOnWriteArrayList<String> list =
+        new CopyOnWriteArrayList<>(new String[] {"a", "b", "c"});
+    Assert.assertEquals(list, serDe(getJavaFury(), list));
+    Assert.assertEquals(
+        
getJavaFury().getClassResolver().getSerializerClass(CopyOnWriteArrayList.class),
+        CollectionSerializers.CopyOnWriteArrayListSerializer.class);
+  }
+
   @Test
   public void testSerializeJavaBlockingQueue() {
     Fury fury =


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@fury.apache.org
For additional commands, e-mail: commits-h...@fury.apache.org

Reply via email to