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
Add ConfigRecognizer API #16958
Merged
mmedenjak
merged 3 commits into
hazelcast:master
from
blazember:4.1/config/distinction-api
Jun 26, 2020
Merged
Add ConfigRecognizer API #16958
mmedenjak
merged 3 commits into
hazelcast:master
from
blazember:4.1/config/distinction-api
Jun 26, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit introduces the ConfigRecognition API that is meant to recognize if a provided declarative configuration is recognized by the rules defined in a given implementation. The main use case for this implementation is to recognize member, client and failover client XML and YAML configurations just by looking into the content of the configuration, without building any actual configuration. Along with the API the following three implementations are added: - MemberConfigRecognizer for recognizing member XML and YAML configurations - ClientConfigRecognizer for recognizing client XML and YAML configurations - ClientFailoverConfigRecognizer for recognizing failover client XML and YAML configurations All the three are extensible with custom recognizers so that even those configurations can be recognized that would otherwise remain unrecognized with the built-in set of recognizers that recognizes XML and YAML configurations by checking the root node in the provided configuration. The API recognizes configuration provided in InputStreams only, while the ConfigBuilder implementations can be built from files defined by their location and URLs too. The reason for lacking the support for these two options is that both are easy to convert to InputStreams and that handling errors caused by non-existing resources, missing privileges etc should be handled outside of this API with potentially having more contextual information. The built-in implementations honour parse errors with unrecognized configuration. The reason is that the provided InputStream can be tested both for XML and YAML configuration and at least one is expected to lead to parse errors. Implements hazelcast#16866
blazember
force-pushed
the
4.1/config/distinction-api
branch
from
May 11, 2020 22:38
e0be301
to
9457ddc
Compare
blazember
commented
May 12, 2020
hazelcast/src/main/java/com/hazelcast/internal/config/ConfigStreamRecognizer.java
Outdated
Show resolved
Hide resolved
alparslanavci
approved these changes
Jun 16, 2020
mmedenjak
reviewed
Jun 19, 2020
mmedenjak
reviewed
Jun 19, 2020
boolean recognized = false; | ||
for (ConfigRecognizer recognizer : recognizers) { | ||
configStream.reset(); | ||
recognized = recognized || recognizer.isRecognized(configStream); |
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.
Minor: can we exit early if it was recognized?
mmedenjak
approved these changes
Jun 19, 2020
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.
Looks really nice 💯
sancar
approved these changes
Jun 26, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces the
ConfigRecognition
API that is meant torecognize if a provided declarative configuration is recognized by the
rules defined in a given implementation. The main use case for this
implementation is to recognize member, client and failover client XML
and YAML configurations just by looking into the content of the
configuration, without building any actual configuration.
Along with the API the following three implementations are added:
MemberConfigRecognizer
for recognizing member XML and YAMLconfigurations
ClientConfigRecognizer
for recognizing client XML and YAMLconfigurations
ClientFailoverConfigRecognizer
for recognizing failover client XML andYAML configurations
All the three are extensible with custom recognizers so that even those
configurations can be recognized that would otherwise remain
unrecognized with the built-in set of recognizers that recognizes XML
and YAML configurations by checking the root node in the provided
configuration.
The API recognizes configuration provided in InputStreams only, while
the ConfigBuilder implementations can be built from files defined by
their location and URLs too. The reason for lacking the support for
these two options is that both are easy to convert to InputStreams and
that handling errors caused by non-existing resources, missing
privileges etc should be handled outside of this API with potentially
having more contextual information.
The built-in implementations honor parse errors with unrecognized
configuration. The reason is that the provided InputStream can be tested
both for XML and YAML configuration and at least one is expected to
lead to parse errors.
Implements #16866