Package com.couchbase.client.core.config
Class DefaultConfigurationProvider
- java.lang.Object
-
- com.couchbase.client.core.config.DefaultConfigurationProvider
-
- All Implemented Interfaces:
ConfigurationProvider
public class DefaultConfigurationProvider extends Object implements ConfigurationProvider
**The default implementation of aConfigurationProvider
.**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
Constructors Constructor Description DefaultConfigurationProvider(ClusterFacade cluster, CoreEnvironment environment)
Create a newDefaultConfigurationProvider
.DefaultConfigurationProvider(ClusterFacade cluster, CoreEnvironment environment, List<Loader> loaderChain, Map<LoaderType,Refresher> refreshers)
Create a newDefaultConfigurationProvider
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description rx.Observable<ClusterConfig>
closeBucket(String name)
rx.Observable<Boolean>
closeBuckets()
ClusterConfig
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
proposeBucketConfig(ProposedBucketConfigContext ctx)
Propose a new bucket config with surrounding context.boolean
seedHosts(Set<String> hosts, boolean shuffle)
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
signalOutdated()
-
-
-
Constructor Detail
-
DefaultConfigurationProvider
public DefaultConfigurationProvider(ClusterFacade cluster, CoreEnvironment environment)
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 Detail
-
configs
public rx.Observable<ClusterConfig> configs()
Description copied from interface:ConfigurationProvider
Returns anObservable
, which pushes a newClusterConfig
once available.- Specified by:
configs
in interfaceConfigurationProvider
- Returns:
- the configuration.
-
config
public ClusterConfig 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
public boolean seedHosts(Set<String> hosts, boolean shuffle)
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
public rx.Observable<ClusterConfig> openBucket(String bucket, String password)
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
public rx.Observable<ClusterConfig> openBucket(String bucket, String username, String password)
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
public rx.Observable<ClusterConfig> closeBucket(String name)
- Specified by:
closeBucket
in interfaceConfigurationProvider
-
closeBuckets
public rx.Observable<Boolean> closeBuckets()
- Specified by:
closeBuckets
in interfaceConfigurationProvider
-
proposeBucketConfig
public void proposeBucketConfig(ProposedBucketConfigContext ctx)
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
public rx.Observable<Boolean> 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.
-
-