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

Support to use classes registered in bootstrap context #325

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

ryanjbaxter
Copy link
Contributor

Fixes #324

@ryanjbaxter ryanjbaxter added this to the 3.1.5 milestone Dec 20, 2023
@ryanjbaxter ryanjbaxter removed this from the 3.1.5 milestone Dec 20, 2023
Copy link
Member

@spencergibb spencergibb left a comment

Choose a reason for hiding this comment

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

Assuming OP's sample works with this, then LGTM. context.getOrElse() FTW!

() -> null, () -> null);
InstanceSerializer<ZookeeperInstance> serializer = new JsonInstanceSerializer<>(ZookeeperInstance.class);
ZookeeperDiscoveryProperties discoveryProperties = binder.bind(ZookeeperDiscoveryProperties.PREFIX, Bindable
CuratorFramework curatorFramework = context.getOrElse(CuratorFramework.class, CuratorFactory.curatorFramework(properties, retryPolicy, Stream::of,
Copy link

@pantherdd pantherdd Dec 20, 2023

Choose a reason for hiding this comment

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

Would we ever reach the orElse here? I mean even before the lambda gets registered, that will later create this ZookeeperFunction, the code has already called CuratorFactory.registerCurator. (I may be missing some use-case though.)

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 was probably being over cautious here, there is no harm though.

Copy link

@pantherdd pantherdd Dec 20, 2023

Choose a reason for hiding this comment

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

Apart from being a bit confusing to readers (who may expect this line to be creating their CuratorFramework instance), won't this getOrElse code always end up running the CuratorFactory.curatorFramework(...) call? If so, that would always build another CuratorFramework instance, start it, and block while it connects (or fails to do so), only to then throw it away (without a close() call). When this instance can't connect, it may also write a considerable amount of misleading logs, that could become red herrings when debugging some issue. Not sure if the curatorFramework(...) method could also throw an exception or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would only call CuratorFactory.curatorFramework if there was not one already present in the BootstrapContext.

I don't see how it would start 2...

Copy link

@pantherdd pantherdd Dec 21, 2023

Choose a reason for hiding this comment

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

I may be missing something, but my thinking was that:

  1. the parameters of this getOrElse call have to be evaluated first by the JVM, meaning that CuratorFactory.curatorFramework(...) is executed, building & starting the new CuratorFramework, then
  2. the JVM passes this new CuratorFramework into getOrElse as the other parameter, then
  3. getOrElse itself gets executed, where it will simply ignore the other parameter when it realizes that there's already a CuratorFramework in the BootstrapContext.

@pantherdd
Copy link

pantherdd commented Jan 24, 2024

For the record, this was superseded by #328 as the final solution to #324.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in 3.1.4: customizations to the CuratorFramework instance are now silently ignored
4 participants