-
Notifications
You must be signed in to change notification settings - Fork 1.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
Factory to populate Config object from well-known locations #16386
Conversation
It allows to load config from an external file and then customize it programmatically. This is useful when embedding Hazelcast into managed environments: When a runtime container wants to create an instance as if it was created via `Hazelcast.newHazelcastInstance()`, but it wants to inject an instance of `ManagedContext` into Hazelcast configuration. Without this capability all containers have to duplicate the `Config` location strategy: "First try this, then that, etc." Related to spring-projects/spring-boot#19487 TODO: Tests
I realize it's VERY late in the dev cycle, so this is more for a consideration. I wonder what does Zoltan think about this change. |
* | ||
* @return Config created from a file when exists, otherwise default. | ||
*/ | ||
public static Config load() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a great name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no problem with the name. It explains that the config is loaded and this implies some files being checked. Unless you can come up with a better name, I would leave it as it is.
run-lab-run |
Additional reasoning behind this change (copy and pasted from a conversation with @mmedenjak) A runtime container typically wants to either:
#1 works without any problem, obviously. |
Does this fix #16400? |
@mmedenjak it does not. |
run-lab-run |
The builders are public for the reason you mentioned: it's a flexible API letting the users to build the config from any source, mostly through the Exposing the locator logic on a public API is a good step I believe. Since we have the convenient As an additional thought, since we have convenient WDYT? |
if (xmlConfigLocator.locateFromSystemProperty()) { | ||
// 1. Try loading XML config from the configuration provided in system property | ||
config = new XmlConfigBuilder(xmlConfigLocator).build(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these empty lines required?
* Populate Hazelcast <code>Config</code> object from an external configuration file. | ||
* It tries to load Hazelcast configuration from a list of well-known locations. | ||
* When no location contains Hazelcast configuration then it returns default. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a note that the same mechanism is used when you call Hazelcast.newHazelcastInstance() ?
I like this API. It is simple from a user perspective. It doesn't expose anything that shouldn't be exposed. So I give my thumbs up. I would like to see a note that calling
Is exactly the same as:
|
…experiments/populate-config-from-default
Closing this one. I'll open a new PR with this in a moment. |
It allows to load config from an external file and then customize
it programmatically. This is useful when embedding Hazelcast into
managed environments: When a runtime container wants to create an
instance as if it was created via
Hazelcast.newHazelcastInstance()
,but it wants to inject an instance of
ManagedContext
into Hazelcastconfiguration.
Without this capability all containers have to duplicate the
Config
location strategy: "First try this, then that, etc."
Related to spring-projects/spring-boot#19487
TODO: Tests