tonybaines/gestalt

Support dynamic values for certain config properties

Closed this issue · 7 comments

Use-case:
It is useful for certain configuration values to be dynamic at runtime, rather than
static for the duration of the program e.g. modifying the size of a DB or thread
pool based on metrics such as throughput or machine capacity, or adjusting time-outs
based on an estimate of how much work needs to happen.

#22 would help support this - writing an implementation of a configuration interface and dropping it in to the list of sources.

An optimisation would be to be able to switch off caching of specific properties (rather than disabling the feature entirely)

Consider providing a pubsub/listener type of interface where the application is notified of the conf object and the old and new value.

Alternatively, I guess the dynamic config provider could manage its own notification mechanism

Having to implement the complete config interface to override one property seems potentially onerous and error-prone in Java (Groovy implementations could be partial though), some thoughts;

  • Encourage dynamic values to be wrapped in a narrow interface by supplying a @NoCache annotation only for class-level
  • Inject individual functions as property-key -> lambda mappings
  • Builder to help construct a dynamic proxy instance, replacing certain properties but defaulting others

However you want to do it, but you need to allow registration of listeners also after the whole config object has been initialised and loaded.

The more I think about it the more sure I am that change-notification an implementation choice for the writer of the dynamic lookup; they'll have a clear view of what 'changed' means, when to notify and can choose to store old/new values to detect if there has even been a change, as well as the particulars of pub-sub.

Enabled by #22 in release 2.0.4