-
Notifications
You must be signed in to change notification settings - Fork 6
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
lazy load jsonParser and yamlParser FlagFileParser #35
base: main
Are you sure you want to change the base?
lazy load jsonParser and yamlParser FlagFileParser #35
Conversation
Hi @jtjeferreira and thank you for contributing! If we are going to support excluding certain file formats, we should implement a solution that treats JSON and YAML as equals in the design. It should also be impossible at runtime to get to an unsupported parser's code even if another parser is removed from the code (perhaps in a future update). What do you think of the following approach?
By moving the match logic into the parsers and iterating, all formats are treated as equals and non-supported formats never have their code executed. We may need to do some optimizing of when the reader is reset / recreated since now this will do a reader pass per format instead of |
First of all, sorry for the late response. I think that is an elegant approach, but I think it is a bit over-engineered (it looks like you are proposing a plugin system) for the value of this feature.
I think that even with the approach you suggest, we still need to use runtime exceptions for the case when we want to parse YAML, but the yaml parser is not present. |
Hi again @jtjeferreira . We discussed on team briefly and the consensus was the following:
Perhaps the If you would like to iterate with this feedback we can review again once your changes are pushed. Alternatively we can file a ticket for a modification. That would get prioritized according to current work demands and may be some time (likely at least a month). Let us know your thoughts! Thank you. |
I don't think we need to worry about the static abstract class FlagFileParser {
private static final FlagFileParser jsonParser = new JsonFlagFileParser();
private static final FlagFileParser yamlParser = new YamlFlagFileParser(); and the easiest way that I could think of to make the parsers lazy (but keep them singletons), was to use a "holder class" |
static final FlagFileParser INSTANCE = new JsonFlagFileParser(); | ||
} | ||
static class YamlParserHolder { | ||
static final FlagFileParser INSTANCE = new YamlFlagFileParser(); |
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.
should be private with a getter so it only gets initialized on access as opposed to having direct reference to variable.
I want to be able to use the thin jar without the snakeyaml dependency, since I don't need to parse yaml files, just json files.
If I try that I get the following exception:
This PR avoids loading the
YamlFlagFileParser
by using a holder class idiom for lazy initialization of a static field.Requirements
Related issues
n/a
Describe the solution you've provided
The solution is to lazy load the
YamlFlagFileParser
(and theJsonFlagFileParser
) so they are only initialised if neededDescribe alternatives you've considered
n/a
Additional context
n/a