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

4.x: Supplier in builder #7402

Merged
merged 3 commits into from Aug 21, 2023

Conversation

tomas-langer
Copy link
Member

Description

A blueprint can now define a Supplier<T>. If this type is @Configured and the method has @ConfiguredOption, the supplier will be used directly from Config (if used).
This means the supplier will provide the latest value if changes are enabled in config.

Added appropriate test with a mutable configuration.

Resolves #7323
May require rebase after #7400 is merged

Documentation

This enhancement adds support for a typed Supplier in prototype blueprints (Helidon builder).
The following blueprint:

@Prototype.Blueprint
@Configured
interface SupplierBeanBlueprint {
    @ConfiguredOption
    Supplier<String> stringSupplier();
}

will work with io.helidon.config.Config that has support for changes (using polling, file watcher, or an event based config source) in the following way:

  • if the SupplierBean is created with config (such as SupplierBean.create(Config) or SupplierBean.Builder.config(Config) is used), the returning supplier will always provide the latest known value from the configuration key string-supplier

Of course the supplier can also be set explicitly (SupplierBean.Builder.stringSupplier(() -> "someValue)) - in this case, the supplier that is provided by user will be used

@tomas-langer tomas-langer added 4.x Version 4.x builder Related to the builder support labels Aug 18, 2023
@tomas-langer tomas-langer self-assigned this Aug 18, 2023
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Aug 18, 2023
@@ -284,4 +284,41 @@ default Stream<T> stream() {
return asOptional().stream();
}

/**
* Returns a supplier of a typed value. The semantics depend on implementation, this may always return the
* same value, or it may provide latest value if changes are enabled.
Copy link
Member

Choose a reason for hiding this comment

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

link to something here to support "if changes are enabled".

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a clear statement "the semantics depend on implementation" - I cannot link to a type that is an implementation of this interface.

@tomas-langer tomas-langer merged commit 4fb65f2 into helidon-io:main Aug 21, 2023
12 checks passed
@tomas-langer tomas-langer deleted the 7323-supplier-in-builders branch August 21, 2023 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x builder Related to the builder support OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants