Skip to content

Commit

Permalink
chore(java): rename copyTrackingRef to copyRef (#1748)
Browse files Browse the repository at this point in the history
## What does this PR do?

rename copyTrackingRef to copyRef

## Related issues
#1679 
#1747


## 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.
-->
  • Loading branch information
chaokunyang authored Jul 24, 2024
1 parent 1e2a528 commit 7b6e9ed
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion java/fury-core/src/main/java/org/apache/fury/Fury.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Fury(FuryBuilder builder, ClassLoader classLoader) {
config = new Config(builder);
this.language = config.getLanguage();
this.refTracking = config.trackingRef();
this.copyRefTracking = config.copyTrackingRef();
this.copyRefTracking = config.copyRef();
this.shareMeta = config.isMetaShareEnabled();
compressInt = config.compressInt();
longEncoding = config.longEncoding();
Expand Down
20 changes: 14 additions & 6 deletions java/fury-core/src/main/java/org/apache/fury/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Config implements Serializable {
private final boolean basicTypesRefIgnored;
private final boolean stringRefIgnored;
private final boolean timeRefIgnored;
private final boolean copyTrackingRef;
private final boolean copyRef;
private final boolean codeGenEnabled;
private final boolean checkClassVersion;
private final CompatibleMode compatibleMode;
Expand Down Expand Up @@ -66,7 +66,7 @@ public Config(FuryBuilder builder) {
basicTypesRefIgnored = !trackingRef || builder.basicTypesRefIgnored;
stringRefIgnored = !trackingRef || builder.stringRefIgnored;
timeRefIgnored = !trackingRef || builder.timeRefIgnored;
copyTrackingRef = builder.copyTrackingRef;
copyRef = builder.copyRef;
compressString = builder.compressString;
compressInt = builder.compressInt;
longEncoding = builder.longEncoding;
Expand Down Expand Up @@ -101,8 +101,16 @@ public boolean trackingRef() {
return trackingRef;
}

public boolean copyTrackingRef() {
return copyTrackingRef;
/**
* Returns true if copy value by ref, and false copy by value.
*
* <p>If this option is false, shared reference will be copied into different object, and circular
* reference copy will raise stack overflow exception.
*
* <p>If this option is enabled, the copy performance will be slower.
*/
public boolean copyRef() {
return copyRef;
}

public boolean isBasicTypesRefIgnored() {
Expand Down Expand Up @@ -253,7 +261,7 @@ public boolean equals(Object o) {
&& basicTypesRefIgnored == config.basicTypesRefIgnored
&& stringRefIgnored == config.stringRefIgnored
&& timeRefIgnored == config.timeRefIgnored
&& copyTrackingRef == config.copyTrackingRef
&& copyRef == config.copyRef
&& codeGenEnabled == config.codeGenEnabled
&& checkClassVersion == config.checkClassVersion
&& checkJdkClassSerializable == config.checkJdkClassSerializable
Expand Down Expand Up @@ -283,7 +291,7 @@ public int hashCode() {
basicTypesRefIgnored,
stringRefIgnored,
timeRefIgnored,
copyTrackingRef,
copyRef,
codeGenEnabled,
checkClassVersion,
compatibleMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public final class FuryBuilder {
boolean checkClassVersion = false;
Language language = Language.JAVA;
boolean trackingRef = false;
boolean copyTrackingRef = false;
boolean copyRef = false;
boolean basicTypesRefIgnored = true;
boolean stringRefIgnored = true;
boolean timeRefIgnored = true;
Expand Down Expand Up @@ -99,9 +99,16 @@ public FuryBuilder withRefTracking(boolean trackingRef) {
return this;
}

/** Whether track {@link Fury#copy(Object)} circular references. */
public FuryBuilder withCopyRefTracking(boolean copyTrackingRef) {
this.copyTrackingRef = copyTrackingRef;
/**
* Whether track {@link Fury#copy(Object)} shared or circular references.
*
* <p>If this option is false, shared reference will be copied into different object, and circular
* reference copy will raise stack overflow exception.
*
* <p>If this option is enabled, the copy performance will be slower.
*/
public FuryBuilder withRefCopy(boolean copyRef) {
this.copyRef = copyRef;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

public class FuryCopyTest extends FuryTestBase {

private final Fury fury = builder().withCopyRefTracking(true).withCodegen(false).build();
private final Fury fury = builder().withRefCopy(true).withCodegen(false).build();

@Test
public void immutableObjectCopyTest() {
Expand Down Expand Up @@ -131,7 +131,7 @@ public void threadLocalCopyTest() {
ExecutorService executor = Executors.newSingleThreadExecutor();
AtomicReference<Throwable> ex = new AtomicReference<>();
ThreadLocalFury threadLocalFury =
builder().withCodegen(false).withCopyRefTracking(true).buildThreadLocalFury();
builder().withCodegen(false).withRefCopy(true).buildThreadLocalFury();
threadLocalFury.register(BeanA.class);
assetEqualsButNotSame(threadLocalFury.copy(beanA));
executor.execute(
Expand All @@ -151,7 +151,7 @@ public void threadpoolCopyTest() throws InterruptedException {
AtomicBoolean flag = new AtomicBoolean(false);
ThreadSafeFury threadSafeFury =
builder()
.withCopyRefTracking(true)
.withRefCopy(true)
.withCodegen(false)
.withAsyncCompilation(true)
.buildThreadSafeFuryPool(5, 10);
Expand Down

0 comments on commit 7b6e9ed

Please sign in to comment.