Package com.couchbase.client.core.config
Class DefaultConfigurationProvider
java.lang.Object
com.couchbase.client.core.config.DefaultConfigurationProvider
- All Implemented Interfaces:
ConfigurationProvider
**The default implementation of a
ConfigurationProvider
.**
The ConfigurationProvider
is the central orchestrator for configuration management. Observers can observe
bucket and cluster configurations from this component. Behind the scenes, it facilitates configuration loaders and
configuration refreshers that grab initial configurations and keep them refreshed respectively. The structure
looks like this:
[ConfigurationProvider] --> [Config from REST] [ConfigurationProvider] --> [Config from Carrier] package "Config from REST" { [HttpLoader] [HttpRefresher] } [HttpLoader] --> 8091 [HttpRefresher] --> 8091 package "Config from Carrier" { [CarrierLoader] [CarrierRefresher] } [CarrierLoader] --> 11210 [CarrierRefresher] --> 11210
- Since:
- 1.0
- Author:
- Michael Nitschinger
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultConfigurationProvider
(ClusterFacade cluster, CoreEnvironment environment) Create a newDefaultConfigurationProvider
.DefaultConfigurationProvider
(ClusterFacade cluster, CoreEnvironment environment, List<Loader> loaderChain, Map<LoaderType, Refresher> refreshers) Create a newDefaultConfigurationProvider
. -
Method Summary
Modifier and TypeMethodDescriptionrx.Observable<ClusterConfig>
closeBucket
(String name) rx.Observable<Boolean>
config()
Returns the current config or null if not set.rx.Observable<ClusterConfig>
configs()
Returns anObservable
, which pushes a newClusterConfig
once available.static String
determineNetworkResolution
(BucketConfig config, NetworkResolution nr, Set<String> seedHosts) Helper method to figure out which network resolution should be used.rx.Observable<ClusterConfig>
openBucket
(String bucket, String password) Start to fetch a config for the given bucket and also watch for changes, depending on the mechanism used.rx.Observable<ClusterConfig>
openBucket
(String bucket, String username, String password) Start to fetch a config for the given bucket and also watch for changes, depending on the mechanism used.void
Propose a new bucket config with surrounding context.boolean
Set the initial seed hosts for bootstrap.rx.Observable<Boolean>
shutdown()
Shutdown theConfigurationProvider
into a terminal state where it cannot be used anymore and all its non-bucket resources are freed.void
-
Constructor Details
-
DefaultConfigurationProvider
Create a newDefaultConfigurationProvider
. When this constructor is used, the default loader chain is populated (first carrier is tried and the http loader is registered as a fallback).- Parameters:
cluster
- the cluster reference.environment
- the environment.
-
DefaultConfigurationProvider
public DefaultConfigurationProvider(ClusterFacade cluster, CoreEnvironment environment, List<Loader> loaderChain, Map<LoaderType, Refresher> refreshers) Create a newDefaultConfigurationProvider
.- Parameters:
cluster
- the cluster reference.environment
- the environment.loaderChain
- the configuration loaders which will be tried in sequence.
-
-
Method Details
-
configs
Description copied from interface:ConfigurationProvider
Returns anObservable
, which pushes a newClusterConfig
once available.- Specified by:
configs
in interfaceConfigurationProvider
- Returns:
- the configuration.
-
config
Description copied from interface:ConfigurationProvider
Returns the current config or null if not set.- Specified by:
config
in interfaceConfigurationProvider
- Returns:
- returns the current cluster config.
-
seedHosts
Description copied from interface:ConfigurationProvider
Set the initial seed hosts for bootstrap. This should only be done as long as theConfigurationProvider
is not bootstrapped, otherwise it might be ignored.- Specified by:
seedHosts
in interfaceConfigurationProvider
- Parameters:
hosts
- list of seed hosts.shuffle
- shuffle seed host list.- Returns:
- true if host list updated, false otherwise.
-
openBucket
Description copied from interface:ConfigurationProvider
Start to fetch a config for the given bucket and also watch for changes, depending on the mechanism used.- Specified by:
openBucket
in interfaceConfigurationProvider
- Parameters:
bucket
- the name of the bucket.password
- the name of the password.- Returns:
- an observable with the configuration if success, and failures otherwise.
-
openBucket
Description copied from interface:ConfigurationProvider
Start to fetch a config for the given bucket and also watch for changes, depending on the mechanism used.- Specified by:
openBucket
in interfaceConfigurationProvider
- Parameters:
bucket
- the name of the bucket.username
- the user authorized for bucket access.password
- the password of the user.- Returns:
- an observable with the configuration if success, and failures otherwise.
-
closeBucket
- Specified by:
closeBucket
in interfaceConfigurationProvider
-
closeBuckets
- Specified by:
closeBuckets
in interfaceConfigurationProvider
-
proposeBucketConfig
Description copied from interface:ConfigurationProvider
Propose a new bucket config with surrounding context.- Specified by:
proposeBucketConfig
in interfaceConfigurationProvider
- Parameters:
ctx
- the raw config including context.
-
signalOutdated
public void signalOutdated()- Specified by:
signalOutdated
in interfaceConfigurationProvider
-
shutdown
Description copied from interface:ConfigurationProvider
Shutdown theConfigurationProvider
into a terminal state where it cannot be used anymore and all its non-bucket resources are freed.- Specified by:
shutdown
in interfaceConfigurationProvider
-
determineNetworkResolution
public static String determineNetworkResolution(BucketConfig config, NetworkResolution nr, Set<String> seedHosts) Helper method to figure out which network resolution should be used. if DEFAULT is selected, then null is returned which is equal to the "internal" or default config mode. If AUTO is used then we perform the select heuristic based off of the seed hosts given. All other resolution settings (i.e. EXTERNAL) are returned directly and are considered to be part of the alternate address configs.- Parameters:
config
- the config to check againstnr
- the network resolution setting from the environmentseedHosts
- the seed hosts from bootstrap for autoconfig.- Returns:
- the found setting if external is used, null if internal/default is used.
-