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/fury.git


The following commit(s) were added to refs/heads/main by this push:
     new 8add13c7 fix(java): ClassLoaderFuryPooled#setFactoryCallback cannot 
effect old Fury (#1946)
8add13c7 is described below

commit 8add13c7967735f2fbe45ad879f4e071db0faa55
Author: Shuchang Li <[email protected]>
AuthorDate: Wed Nov 20 11:35:20 2024 +0800

    fix(java): ClassLoaderFuryPooled#setFactoryCallback cannot effect old Fury 
(#1946)
    
    
    
    ## What does this PR do?
    
    ClassLoaderFuryPooled#setFactoryCallback cannot effect old fury.
    so if
    `org.apache.fury.pool.FuryPooledObjectFactory#classLoaderFuryPooledCache`
    expired, new classLoaderFuryPooled can not effected by custom
    factoryCallback
    
    <!-- Describe the purpose of this PR. -->
    
    ## 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/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.
    -->
    
    Co-authored-by: shuchang.li <[email protected]>
---
 .../org/apache/fury/pool/ClassLoaderFuryPooled.java     |  3 ++-
 .../org/apache/fury/pool/ClassLoaderFuryPooledTest.java | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git 
a/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java 
b/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java
index c1ad2ada..ececce99 100644
--- 
a/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java
+++ 
b/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java
@@ -123,6 +123,7 @@ public class ClassLoaderFuryPooled {
   }
 
   void setFactoryCallback(Consumer<Fury> factoryCallback) {
-    this.factoryCallback = factoryCallback;
+    this.factoryCallback = this.factoryCallback.andThen(factoryCallback);
+    allFury.keySet().forEach(factoryCallback);
   }
 }
diff --git 
a/java/fury-core/src/test/java/org/apache/fury/pool/ClassLoaderFuryPooledTest.java
 
b/java/fury-core/src/test/java/org/apache/fury/pool/ClassLoaderFuryPooledTest.java
index 9e148e78..c039342f 100644
--- 
a/java/fury-core/src/test/java/org/apache/fury/pool/ClassLoaderFuryPooledTest.java
+++ 
b/java/fury-core/src/test/java/org/apache/fury/pool/ClassLoaderFuryPooledTest.java
@@ -83,6 +83,23 @@ public class ClassLoaderFuryPooledTest {
     }
   }
 
+  @Test
+  public void testFuryAfterSetFactoryCallback() {
+    int minPoolSize = 4;
+    ClassLoaderFuryPooled pooled = getPooled(minPoolSize, 6);
+
+    try {
+      pooled.setFactoryCallback(
+          fury -> {
+            throw new RuntimeException();
+          });
+      pooled.getFury();
+      Assert.fail();
+    } catch (RuntimeException e) {
+      // Success
+    }
+  }
+
   @Test
   public void testGetFuryAwait() throws InterruptedException {
     int minPoolSize = 3;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to