-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Arc: declare a synthetic, runtime-initialized bean as eagerly initialized (if conditions met) #41466
Comments
You added a link to a Zulip discussion, please make sure the description of the issue is comprehensive and doesn't require accessing Zulip This message is automatically generated by a bot. |
I think that's the gist of it @Ladicek @manofthepeace @mkouba ... please let me know if anything is missing or unclear :) |
That would be awsome, we are implementing an application that can work with both postgres OR elastic, and we can't decide at compile time which will be chosen at runtime... Really eager to have this availbale (that would allow us to trash a whole bunch of code !) |
I think that was meant for @manovotn :) |
It was, autocompletion slipped. Sorry :) |
Note this was envisioned strictly as a feature for Quarkus extensions, as applications can't define synthetic beans. You're right that it could help applications eventually though, since this feature will make it easier to support Once that's there, I think you will essentially need to:
|
could this be used for case where today i.e. #7148 |
No, that's a completely different problem. Here, we're making it possible for a bean to become "inactive", throwing an exception when someone tries to create an instance anyway. |
Description
Some Quarkus extensions would need Arc to expose the ability to declare a synthetic, runtime-initialized bean as initialized on startup -- under some circumstances.
Briefly, here's the situation:
Datasource
beans are defined at build time, when we have incomplete information about the runtime environment.And here's the need:
quarkus.datasource.active
is set to false"Note that this is not specific to datasources: other extensions need a similar feature (Hibernate ORM) and some may need it in the future (MongoDB client, Elasticsearch client, ...).
For more information about the problem, see:
And see this mind map:
Implementation ideas
Here are the conclusions of our last conversation.
The feature below only make sense for runtime-initialized,
@ApplicationScoped
, synthetic bean definitions. Eager initialization probably doesn't make much sense for singletons -- which are already initialized eagerly and are not proxied -- and for other scopes and pseudo-scopes (how would you initialize a@Dependent
or@RequestScoped
bean eagerly?).We could add two methods to
io.quarkus.arc.deployment.SyntheticBeanBuildItem.ExtendedBeanConfigurator
(names are placeholders subject to bikeshedding):activeIf(condition)
: tells Arc that this bean is only "active" (~initializable) if the provided condition is met. Default is always active.initializeEagerly()
: tells Arc that this bean should be initialized:The type of
condition
would be, depending on implementation needs (TBD):RuntimeValue<BooleanSupplier>
(returnstrue
if the condition is met)RuntimeValue<Runnable>
(checks the condition, if not met throws with meaningful, actionable message)RuntimeValue<Condition>
whereCondition
is defined as:Additionally, we will need to implement two new behaviors:
InactiveBeanException
?) if theactiveIf
condition is not met, or wrap any exception thrown by initialization.In practice, we'll probably use this for datasources by setting the
activeIf
condition to something like "quarkus.datasource[.name].active is unset OR set to true" -- but it could be more complicated, we'll have to check. We'll also have to adapt some code that currently retrieves the datasources through various ways.In the future we'll want to trigger initialization on startup even if a bean is only used in other synthetic beans (e.g. a datasource in a Hibernate ORM persistence unit), but that will require more work as we'll want to ignore synthetic consumers that are themselves inactive.
The text was updated successfully, but these errors were encountered: