question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ConfigSource.getDefaultOrdinal()

See original GitHub issue

Description

Hi guys,

The spec states that:

Note that a special property config_ordinal can be set within any built-in ConfigSource implementation. The default implementation of getOrdinal() will attempt to read this value. If found and a valid integer, the value will be used. Otherwise the respective default value will be used.

And to handle it properly in our custom built-in ConfigSources we often use following or similar boilerplate:

 @Override
   public int getOrdinal() {
      String configOrdinal = getValue(CONFIG_ORDINAL);
      if(configOrdinal != null) {
          try {
              return Integer.parseInt(configOrdinal);
          }
          catch (NumberFormatException ignored) {

          }
      }
      return getDefaultOrdinal();
  }

   public int getDefaultOrdinal() {
      return this.defaultOrdinal;
   }

So I was wonderwing if a change to default ConfigSource.getOrdinal() could be made to invoke another default method getDefaultOrdinal that will return ConfigSource.DEFAULT_ORDINAL by default and that could be overriden by ConfigSource implementors easily instead of the boilerplate.

  • Fixes

The code will looks like:

 @Override
   default int getOrdinal() {
      String configOrdinal = getValue(CONFIG_ORDINAL);
      if(configOrdinal != null) {
          try {
              return Integer.parseInt(configOrdinal);
          }
          catch (NumberFormatException ignored) {

          }
      }
      return getDefaultOrdinal();
  }

   default int getDefaultOrdinal() {
      return DEFAULT_ORDINAL;
   }

WDYT ?

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
radcortezcommented, Jun 18, 2020

Sure go ahead.

0reactions
NicoNescommented, Jun 18, 2020

So @radcortez if you also think there is noting more to talk about and that things are OK as they are, let me know if I can close the issue ?

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

can I load a configSource and then add additional keys in web ...
1 Answer 1 ... appSettings in the external file will override settings with the same key in the main configuration file. Share. Share...
Read more >
Creating ConfigSources - LogicMonitor
To create a ConfigSource, navigate to Settings | LogicModules | ConfigSources | Add | ConfigSource. From the Create New ConfigSource dialog ...
Read more >
Extending Configuration Support - Quarkus
It's possible to create a custom ConfigSource as specified in MicroProfile ... @Override public Set<String> getPropertyNames() { return configuration.
Read more >
Custom ConfigSource with MicroProfile Configuration
To create your own ConfigSource, you just need to create a regular Java POJO and ... retrieves the keys from the getProperties() method....
Read more >
Configuration for MicroProfile
A factory method ConfigProvider#getConfig() to create a Config object based on automatically picked up ConfigSources of the Application ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found