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 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 Details

    • DefaultConfigurationProvider

      public DefaultConfigurationProvider​(ClusterFacade cluster, CoreEnvironment environment)
      Create a new DefaultConfigurationProvider. 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)
      Parameters:
      cluster - the cluster reference.
      environment - the environment.
      loaderChain - the configuration loaders which will be tried in sequence.
  • Method Details

    • configs

      public rx.Observable<ClusterConfig> configs()
      Description copied from interface: ConfigurationProvider
      Returns an Observable, which pushes a new ClusterConfig once available.
      Specified by:
      configs in interface ConfigurationProvider
      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 interface ConfigurationProvider
      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 the ConfigurationProvider is not bootstrapped, otherwise it might be ignored.
      Specified by:
      seedHosts in interface ConfigurationProvider
      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 interface ConfigurationProvider
      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 interface ConfigurationProvider
      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 interface ConfigurationProvider
    • closeBuckets

      public rx.Observable<Boolean> closeBuckets()
      Specified by:
      closeBuckets in interface ConfigurationProvider
    • proposeBucketConfig

      public void proposeBucketConfig​(ProposedBucketConfigContext ctx)
      Description copied from interface: ConfigurationProvider
      Propose a new bucket config with surrounding context.
      Specified by:
      proposeBucketConfig in interface ConfigurationProvider
      Parameters:
      ctx - the raw config including context.
    • signalOutdated

      public void signalOutdated()
      Specified by:
      signalOutdated in interface ConfigurationProvider
    • shutdown

      public rx.Observable<Boolean> shutdown()
      Description copied from interface: ConfigurationProvider
      Shutdown the ConfigurationProvider into a terminal state where it cannot be used anymore and all its non-bucket resources are freed.
      Specified by:
      shutdown in interface ConfigurationProvider
    • 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 against
      nr - the network resolution setting from the environment
      seedHosts - the seed hosts from bootstrap for autoconfig.
      Returns:
      the found setting if external is used, null if internal/default is used.