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 aConfig
tree, as accessed throughConfigSource
s.Once it loads a
Config
tree fromConfigSource
s the config system does not itself change the in-memoryConfig
tree. Even so, the underlying data available via the tree'sConfigSource
s can change. Implementations ofPollingStrategy
other interested code to learn when changes to that underlying data might have occurred.In implementations of
PollingStrategy
theticks()
method returns aFlow.Publisher
ofPollingStrategy.PollingEvent
s to which the application or theConfigSource
s themselves can subscribe. Generally, each event is a hint to the application or aConfigSource
itself 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 somePollingStrategy
implementations.Typically a custom
ConfigSource
implementation creates aFlow.Subscriber
which it uses to subscribe to theFlow.Publisher
that is returned from thePollingStrategy.ticks()
method. When that subscriber receives aPollingEvent
it triggers theConfigSource
to reload the configuration from the possibly changed underlying data. For example, eachAbstractParsableConfigSource
can use a differentPollingStrategy
.As described with
ConfigSource.create(Config)
, the config system can loadConfigSource
s using meta-configuration, which supports specifying polling strategies. Allbuilt-in polling strategies
and custom ones are supported. (The support is tightly connected withAbstractSource extensions
and will not be automatically provided by any another config source implementations.)The meta-configuration for a config source can set the property
polling-strategy
using the following nestedproperties
:type
- name of the polling strategy implementation.Built-in Polling Strategies Name Strategy Required Properties regular
Scheduled polling at regular intervals. See PollingStrategies.regular(Duration)
.interval
inDuration
format, e.g.PT15S
means 15 secondswatch
Filesystem monitoring of the Path
specified in the config source definition. SeePollingStrategies.watch(Path)
.Use this strategy only with config sources based on
AbstractSource.Builder
that are paramaterized withPath
. This includes nullclasspath
,file
anddirectory
config 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
.
type
orclass
to indicate a polling strategy but not both. If both appear the config system ignores theclass
setting.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
ConfigMappers
to see what Java types are automatically supported. - Accessing the
ConfigSource
meta-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
ConfigSource
s based on aPath
would implement a constructor that accepts aPath
argument.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
PollingStrategy.PollingEvent
Event indicating that data used in constructing a givenConfig
tree might have changed.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default PollingStrategy
get()
Flow.Publisher<PollingStrategy.PollingEvent>
ticks()
Returns aFlow.Publisher
which firesPollingStrategy.PollingEvent
s.
-
-
-
Method Detail
-
get
default PollingStrategy get()
- Specified by:
get
in interfaceSupplier<PollingStrategy>
-
ticks
Flow.Publisher<PollingStrategy.PollingEvent> ticks()
Returns aFlow.Publisher
which firesPollingStrategy.PollingEvent
s.Note that
PollingStrategy
implementations can generatePollingEvent
s 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
PollingStrategy
implementation 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
-
-