-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Improve the way runtime configuration is injected into CDI producers #4842
Comments
Could you add some pseudocode example? I'm not sure I'm following... a real example would be even better ;-). CC @manovotn |
He goes a very simple attempt: Let's say that in the runtime module you have:
Then in the build-time module an implementation would be generated simply extends Does that make sense if you compare it say to the links I have added in the description? |
I'm sorry I missed the links ;-). Hm, I don't see a problem here - you could set the configuration on a bean in a RUNTIME_INIT build step (lazy/eager init should not matter here). In other words, the |
Well, actually I'm not sure whether |
The bytecode recorder can "serialize" and deserialize the runtime config (since it's just a pojo), which is why it's being used via the pattern you saw in the links. |
Now I am the one that doesn't follow 😆 |
The recorder uses If it is the former, then you shouldn't have issues, you are the first one to touch the bean and you immediately provide config. |
@manovotn I am assuming that things currently work because of the former scenario you describe. However, if the producer where to eagerly produce a bean because some other bean needed to inject it, then wouldn't the fact that the runtime configuration is injected into the producer after it's created be sort of a race condition? I think that is what people have been experiencing. Does that make sense? |
So the bean that needs some kind of initialization should react appropriately and the client bean should not use it until it's fully initialized. If an extension needs to use bean A that needs some init there should be a build item that signals that bean A was initialized -> this would ensure the build step will be executed after A is fully initialized. WDYT?
I don't like this very much. It's harder to debug/understand. |
I think I understand what you mean, however I sense a mismatch here between the CDI world and the Quarkus world.
I agree that it's both harder to understand and debug. But if ask @Sanne I assume that he would say that current state of things has made it difficult for him to debug as well :) |
So I think you could use the |
I'll need to |
Well, it's not documented because we don't feel it's stable/mature enough. |
Understood, thanks. I'll play around with it when are past 1.0 and see if it fits the bill for what we want here. |
FYI the @geoand Pls could you review this issue and let us know if it fits your needs? |
@mkouba will do, thanks for the heads up! |
@mkouba I have to hand it to you! |
Description
Currently the way injection of Runtime Configuration into CDI producers works by utilizing a Quarkus Recorder (that "records" the configuration object) and sets a field of the producer class (see for example: AbstractDataSourceProducer and AgroalRecorder).
This only works if the bean being produced by the producer method is not produced eagerly. If the bean needs to be produced eagerly the runtime configuration is null and things break.
However this is not evident to extension authors.
Implementation ideas
One way around the problem that would be independent of the how the laziness of the produced bean, would be have each extension generate a producer (most likely extending an abstract) that basically creates the runtime config object in bytecode. This is obviously not trivial to do, but it would be lift all the haze around the interaction between configuration and CDI producers.
We could perhaps even provide some kind of utility - most likely utilizing code from the config infrastructure.
cc @Sanne @mkouba
The text was updated successfully, but these errors were encountered: