Skip to content
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): ThreadSafeFury add getClassResolver method #1780

Merged
merged 12 commits into from
Aug 3, 2024

Conversation

funky-eyes
Copy link
Contributor

What does this PR do?

Because using ThreadSafeFury cannot get ClassResolver, so I submitted this pr to increase some checklistener and other behavior

Related issues

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

ThreadLocalFury threadLocalFury =
builder().withCodegen(false).withRefCopy(true).buildThreadLocalFury();
ThreadLocalFury threadLocalFury = builder().withCodegen(false).withRefCopy(true).buildThreadLocalFury();
threadLocalFury.getClassResolver().setClassChecker((classResolver, className1) -> true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't set set class checker for other fury instance. We could set Class checker when building threadsafefury by creating threadlocalfury directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't set set class checker for other fury instance. We could set Class checker when building threadsafefury by creating threadlocalfury directly

I believe that in some cases, adding check listeners and serializers involves dynamically adding or modifying them at runtime, which cannot be predicted with absolute certainty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, maybe we need to add setClassChecker to BaseFury/ThreadSafeFur directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, maybe we need to add setClassChecker to BaseFury/ThreadSafeFur directly.

That's a good idea. I will make modifications based on this suggestion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@LiangliangSui
Copy link
Contributor

Hi @funky-eyes , the rust ci failure is not related to your changes, I will fix this soon, track the ci failure issue at #1781

@funky-eyes
Copy link
Contributor Author

Hi @funky-eyes , the rust ci failure is not related to your changes, I will fix this soon, track the ci failure issue at #1781

thx

public ClassResolver getClassResolver() {
return bindingThreadLocal.get().get().getClassResolver();
public void setClassChecker(ClassChecker classChecker) {
bindingThreadLocal.get().get().getClassResolver().setClassChecker(classChecker);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use processCallback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use processCallback

I don't quite understand what you mean. Could you give me an example?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can take setSerializerFactory as an example:

  public void setSerializerFactory(SerializerFactory serializerFactory) {
    processCallback(fury -> fury.setSerializerFactory(serializerFactory));
  }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe we can add following API for extending:

public void configureClassResolver(Consumer<ClassResolver> apply);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can take setSerializerFactory as an example:

  public void setSerializerFactory(SerializerFactory serializerFactory) {
    processCallback(fury -> fury.setSerializerFactory(serializerFactory));
  }

I feel doing it this way might be simpler.

}

@Override
public SerializerFactory getSerializerFactory() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not provide this api. It may return different object when classloader changes or we invoke It from another thread

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct; I will proceed with the corrections

@@ -265,6 +267,16 @@ public ClassLoader getClassLoader() {
return bindingThreadLocal.get().getClassLoader();
}

@Override
public ClassChecker getClassChecker() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement this in AbstractThreadSafeFury

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement this in AbstractThreadSafeFury

AbstractThreadSafeFury does not have bindingThreadLocal, so it seems unable to implement this interface.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can invoke processCallback instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can invoke processCallback instead

processCallback ReturnType is void

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can create ClassChecker first and set it to Fury. Then you don't need to add any API to Fury. We won't add such API to get Classchecker or ClassResolver/SerializerFactory

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can only allow set ClassChecker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can only allow set ClassChecker

ok

@funky-eyes funky-eyes closed this Aug 3, 2024
@funky-eyes funky-eyes reopened this Aug 3, 2024
Copy link
Collaborator

@chaokunyang chaokunyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chaokunyang chaokunyang merged commit 407b658 into apache:main Aug 3, 2024
60 of 63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants