Skip to content

Conversation

@flyrain
Copy link
Contributor

@flyrain flyrain commented Jun 3, 2025

This is the first step to consolidate call context. After this change, you can already use PolarisCallContext to get a RealmContext. To finish the consolidation, here are follow-ups.

  • Make PolarisCallContext extend CallContext
  • Cleanup the tests which call CallContext.of(), then remove the method.
  • Promote methods in PolarisCallContext to the interface CallContext, like getMetaStore()
  • Change the method parameters to use CallContext instead of PolarisCallContext as much as possible. For example, EntitiesResult createEntitiesIfNotExist( @Nonnull PolarisCallContext callCtx, ...)

Copy link
Contributor

@dimas-b dimas-b left a comment

Choose a reason for hiding this comment

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

Thanks, @flyrain ! This refactoring looks reasonable to me... Just one comment about Clock

this.metaStore = metaStore;
this.diagServices = diagServices;
this.configurationStore = new PolarisConfigurationStore() {};
this.clock = Clock.system(ZoneId.systemDefault());
Copy link
Contributor

Choose a reason for hiding this comment

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

why not Clock.systemUTC()?

Copy link
Contributor Author

@flyrain flyrain Jun 4, 2025

Choose a reason for hiding this comment

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

This was a copy from the deprecated method, see line 90. I'm OK to change it to UTC. I'd suggest to make that change in a separate PR, as it isn't related to the refactor in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok to defer, but we must not forget... IIRC we already have a mix of clocks in the codebase. It'd be nice to have a uniform pattern.

* low-level services required to process that request
*/
public class PolarisCallContext {
public class PolarisCallContext implements CallContext {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why not go the other way? It seems like it would be easier to have CallContext extend PolarisCallContext, since it can immediately implement all the methods just by delegating to the current PolarisCallContext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's also a nice idea, however, it will need to change CallContext from an interface to a class, which isn't trivial -- all anonymous classes have to go. Besides, it's reasonable to keep CallContext as an interface, while PolarisCallContext as an impl. I also list the step 3 which promotes methods in PolarisCallContext to the interface CallContext, like getMetaStore(). This will even clean up more, so that, PolarisCallContext doesn't have to return itself from the method getPolarisCallContext().

adutra
adutra previously approved these changes Jun 4, 2025
Copy link
Contributor

@adutra adutra left a comment

Choose a reason for hiding this comment

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

The changes LGTM and definitely bring a nice simplification.

I just think that there is one last follow-up step that we should consider: getting rid of CallContext and PolarisCallContext completely.

As you know, this was attempted before, but I'll admit it was done too hastily. But the intent is still relevant imho: CallContext is progressively becoming an empty interface, and PolarisCallContext does not have any business logic attached to it.

Moreover, PolarisCallContext has 3 application-scoped beans, but also one non-CDI bean that is realm-dependent. Because of that, PolarisCallContext itself must be in request scope. Besides, not all injectees require access to all of these beans. By de-entangling those beans and injecting them one by one, we would loosen the coupling between components and maybe even promote some beans from request scope to application scope.

@github-project-automation github-project-automation bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Jun 4, 2025
dimas-b
dimas-b previously approved these changes Jun 4, 2025
@flyrain
Copy link
Contributor Author

flyrain commented Jun 4, 2025

PolarisCallContext has 3 application-scoped beans, but also one non-CDI bean that is realm-dependent. Because of that, PolarisCallContext itself must be in request scope. Besides, not all injectees require access to all of these beans. By de-entangling those beans and injecting them one by one, we would loosen the coupling between components and maybe even promote some beans from request scope to application scope.

+1, let's keep improving on it.

eric-maynard
eric-maynard previously approved these changes Jun 4, 2025
@flyrain flyrain dismissed stale reviews from eric-maynard, dimas-b, and adutra via c4a9c44 June 4, 2025 17:10
@flyrain flyrain merged commit 0a8d8b8 into apache:main Jun 4, 2025
9 checks passed
@github-project-automation github-project-automation bot moved this from Ready to merge to Done in Basic Kanban Board Jun 4, 2025
@HonahX HonahX mentioned this pull request Jun 4, 2025
HonahX pushed a commit that referenced this pull request Jun 5, 2025
After pr #1806, the original constructor is marked as deprecated and is not suppose to be used anymore.
This PR removes the usage of the old constructors.
HonahX added a commit that referenced this pull request Jun 5, 2025
This PR is a follow-up of #1806 to remove all usage of CallContext.of() in tests and the method itself
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.

5 participants