Interface PollingStrategy
-
- All Superinterfaces:
Supplier<PollingStrategy>
- All Known Implementing Classes:
EtcdWatchPollingStrategy
public interface PollingStrategy extends Supplier<PollingStrategy>
Mechanism for notifying interested subscribers when they should check for changes that might have been made to the data used to create aConfigtree, as accessed throughConfigSources.Once it loads a
Configtree fromConfigSources the config system does not itself change the in-memoryConfigtree. Even so, the underlying data available via the tree'sConfigSources can change. Implementations ofPollingStrategyother interested code to learn when changes to that underlying data might have occurred.In implementations of
PollingStrategytheticks()method returns aFlow.PublisherofPollingStrategy.PollingEvents to which the application or theConfigSources themselves can subscribe. Generally, each event is a hint to the application or aConfigSourceitself that it should check to see if any of the underlying config data it relies on might have changed. Note that aPollingStrategy's publication of an event does not necessarily guarantee that the underlying data has in fact changed, although this might be true for somePollingStrategyimplementations.Typically a custom
ConfigSourceimplementation creates aFlow.Subscriberwhich it uses to subscribe to theFlow.Publisherthat is returned from thePollingStrategy.ticks()method. When that subscriber receives aPollingEventit triggers theConfigSourceto reload the configuration from the possibly changed underlying data. For example, eachAbstractParsableConfigSourcecan use a differentPollingStrategy.As described with
ConfigSource.create(Config), the config system can loadConfigSources using meta-configuration, which supports specifying polling strategies. Allbuilt-in polling strategiesand custom ones are supported. (The support is tightly connected withAbstractSource extensionsand will not be automatically provided by any another config source implementations.)The meta-configuration for a config source can set the property
polling-strategyusing the following nestedproperties:type- name of the polling strategy implementation.Built-in Polling Strategies Name Strategy Required Properties regularScheduled polling at regular intervals. See PollingStrategies.regular(Duration).intervalinDurationformat, e.g.PT15Smeans 15 secondswatchFilesystem monitoring of the Pathspecified in the config source definition. SeePollingStrategies.watch(Path).Use this strategy only with config sources based on
AbstractSource.Builderthat are paramaterized withPath. This includes nullclasspath,fileanddirectoryconfig sources.n/a class- fully-qualified class name of a custom polling strategy implementation or a builder class that implements abuild()method that returns aPollingStrategy.
typeorclassto indicate a polling strategy but not both. If both appear the config system ignores theclasssetting.Meta-configuration Support for Custom Polling Strategies
To support settings in meta-configuration, a custom polling strategy must follow these patterns.- Auto-configuration from meta-configuration properties
The implementation class should define a Java bean property for each meta-configuration property it needs to support. The config system uses mapping functions to convert the text in the meta-configuration into the correct Java type and then assigns the value to the correspondingly-named Java bean property defined on the custom strategy instance. See the built-in mappers defined in
ConfigMappersto see what Java types are automatically supported. - Accessing the
ConfigSourcemeta-config attributesThe custom polling strategy can get access to the same meta-configuration attributes that are used to construct the associated
ConfigSource. To do so the custom implementation class should implement a constructor that accepts the same Java type as that returned by theAbstractSource.Builder.target()method on the builder that is used to construct theConfigSource.For example, a custom polling strategy useful with
ConfigSources based on aPathwould implement a constructor that accepts aPathargument.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfacePollingStrategy.PollingEventEvent indicating that data used in constructing a givenConfigtree might have changed.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default PollingStrategyget()Flow.Publisher<PollingStrategy.PollingEvent>ticks()Returns aFlow.Publisherwhich firesPollingStrategy.PollingEvents.
-
-
-
Method Detail
-
get
default PollingStrategy get()
- Specified by:
getin interfaceSupplier<PollingStrategy>
-
ticks
Flow.Publisher<PollingStrategy.PollingEvent> ticks()
Returns aFlow.Publisherwhich firesPollingStrategy.PollingEvents.Note that
PollingStrategyimplementations can generatePollingEvents whether or not any subscribers have subscribed to the publisher of the events.Subscribers typically invoke
Flow.Subscription.request(long)asking for one event initially, and then after it has processed each event the subscriber requests one more event.The subscriber might not receive every event broadcast, for example if it subscribes to the publisher after an event has been delivered to the publisher.
Each
PollingStrategyimplementation chooses which executor to use for notifying subscribers. The recommended practice is to use the same thread as the polling strategy implementation runs on.- Returns:
- a publisher of events
-
-