B
- type of Builder implementationT
- type of key source attributes (target) used to construct
polling strategy fromS
- type of source that should be builtAbstractConfigSource.Builder
, AbstractOverrideSource.Builder
public abstract static class AbstractSource.Builder<B extends AbstractSource.Builder<B,T,S>,T,S>
extends java.lang.Object
AbstractSource
builder, suitable for concrete Builder
implementations
related to AbstractSource
extensions to extend.
The application can control this behavior:
mandatory
- whether the resource is mandatory (by default) or
optionalpollingStrategy
- which source reload policy to useexecutor
and subscriber's buffer size
-
related to propagating source changesModifier | Constructor | Description |
---|---|---|
protected |
Builder(java.lang.Class<T> targetType) |
Initializes builder.
|
Modifier and Type | Method | Description |
---|---|---|
abstract S |
build() |
Builds new instance of
S . |
B |
changesExecutor(java.util.concurrent.Executor changesExecutor) |
Specifies "observe-on"
Executor to be used to deliver
config source changes . |
B |
changesMaxBuffer(int changesMaxBuffer) |
Specifies maximum capacity for each subscriber's buffer to be used to deliver
config source changes . |
protected java.util.concurrent.Executor |
getChangesExecutor() |
Returns changes-executor property.
|
protected int |
getChangesMaxBuffer() |
Returns changes-max-buffer property.
|
protected PollingStrategy |
getPollingStrategy() |
Returns polling-strategy property.
|
protected RetryPolicy |
getRetryPolicy() |
|
protected T |
getTarget() |
Returns key source attributes (target).
|
protected B |
init(Config metaConfig) |
Initialize builder from specified configuration properties.
|
protected boolean |
isMandatory() |
Returns mandatory property.
|
B |
optional() |
Built
ConfigSource will not be mandatory, i.e. |
B |
pollingStrategy(java.util.function.Function<T,java.util.function.Supplier<PollingStrategy>> pollingStrategyProvider) |
Sets the polling strategy that accepts key source attributes.
|
B |
pollingStrategy(java.util.function.Supplier<PollingStrategy> pollingStrategySupplier) |
Sets a polling strategy.
|
B |
retryPolicy(java.util.function.Supplier<RetryPolicy> retryPolicySupplier) |
Sets a supplier of
RetryPolicy that will be responsible for invocation of AbstractSource.load() . |
protected Builder(java.lang.Class<T> targetType)
targetType
- target typeprotected B init(Config metaConfig)
Supported configuration properties
:
optional
- type boolean
, see optional()
polling-strategy
- see PollingStrategy
for details about configuration format,
see pollingStrategy(Supplier)
or pollingStrategy(Function)
metaConfig
- configuration properties used to initialize a builder instance.public B pollingStrategy(java.util.function.Supplier<PollingStrategy> pollingStrategySupplier)
pollingStrategySupplier
- a polling strategyPollingStrategies.regular(java.time.Duration)
public final B pollingStrategy(java.util.function.Function<T,java.util.function.Supplier<PollingStrategy>> pollingStrategyProvider)
Concrete subclasses should override getTarget()
to provide
the key source attributes (target). For example, the Builder
for a FileConfigSource
or ClasspathConfigSource
uses
the Path
to the corresponding file or resource as the key
source attribute (target), while the Builder
for a
UrlConfigSource
uses the URL
.
pollingStrategyProvider
- a polling strategy providerjava.lang.UnsupportedOperationException
- if the concrete Builder
implementation does not support the polling strategypollingStrategy(Supplier)
,
getTarget()
protected T getTarget()
public B optional()
ConfigSource
will not be mandatory, i.e. it is ignored if configuration target does not exists.public B changesExecutor(java.util.concurrent.Executor changesExecutor)
Executor
to be used to deliver
config source changes
. The same
executor is also used to reload the source, as triggered by the
polling strategy event
.
The default executor is from a dedicated thread pool which reuses threads as possible.
changesExecutor
- the executor to use for async delivery of
Source.changes()
eventschangesMaxBuffer(int)
,
Source.changes()
,
PollingStrategy.ticks()
public B changesMaxBuffer(int changesMaxBuffer)
config source changes
.
By default Flow.DEFAULT_BUFFER_SIZE
is used.
Note: Not consumed events will be dropped off.
changesMaxBuffer
- the maximum capacity for each subscriber's buffer of Source.changes()
events.changesExecutor(Executor)
,
Source.changes()
public B retryPolicy(java.util.function.Supplier<RetryPolicy> retryPolicySupplier)
RetryPolicy
that will be responsible for invocation of AbstractSource.load()
.
The default reply policy is RetryPolicies.justCall()
.
Create a custom policy or use the built-in policy constructed with a builder
.
retryPolicySupplier
- a execute policy supplierpublic abstract S build()
S
.S
.protected boolean isMandatory()
protected PollingStrategy getPollingStrategy()
protected java.util.concurrent.Executor getChangesExecutor()
protected int getChangesMaxBuffer()
protected RetryPolicy getRetryPolicy()
Copyright © 2018 Oracle Corporation. All rights reserved.