Class AbstractLoader
java.lang.Object
com.couchbase.client.core.config.loader.AbstractLoader
- All Implemented Interfaces:
Loader
- Direct Known Subclasses:
CarrierLoader
,HttpLoader
public abstract class AbstractLoader extends Object implements Loader
An
AbstractLoader
which provides common basic processing for all implementing loaders.
A loader fetches configuration from a service, maybe falls back to another service and finally response with a
BucketConfig
or an error. There are multiple steps, like making sure that a node or service is alive before
sending a request into, is abstracted in here to avoid duplication.- Since:
- 1.0
- Author:
- Michael Nitschinger
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractLoader(LoaderType loaderType, ServiceType serviceType, ClusterFacade cluster, CoreEnvironment environment)
Create a newAbstractLoader
. -
Method Summary
Modifier and Type Method Description protected ClusterFacade
cluster()
Returns theClusterFacade
for child implementations.protected abstract rx.Observable<String>
discoverConfig(String bucket, String username, String password, String hostname)
Run theBucketConfig
discovery process.protected CoreEnvironment
env()
Returns theCoreEnvironment
for child implementations.rx.Observable<Tuple2<LoaderType,BucketConfig>>
loadConfig(String seedNode, String bucket, String password)
Initiate the config loading process.rx.Observable<Tuple2<LoaderType,BucketConfig>>
loadConfig(String seedNode, String bucket, String username, String password)
Initiate the config loading process.protected abstract int
port(String hostname)
Port to use for theServiceType
.protected String
replaceHostWildcard(String input, String hostname)
Replaces the host wildcard from an incoming config with a proper hostname.protected Integer
tryLoadingPortFromConfig(String hostname)
Tries to identify a prt from a config if present, null otherwise.
-
Constructor Details
-
AbstractLoader
protected AbstractLoader(LoaderType loaderType, ServiceType serviceType, ClusterFacade cluster, CoreEnvironment environment)Create a newAbstractLoader
.- Parameters:
serviceType
- the service serviceType.cluster
- the cluster reference.environment
- the couchbase environment.
-
-
Method Details
-
port
Port to use for theServiceType
. This method needs to be implemented by the actual loader and defines the port which should be used to connect the service to. In practice, the actual port may depend on the environment (i.e. if SSL is used or not).- Returns:
- the port for the service to enable.
-
tryLoadingPortFromConfig
Tries to identify a prt from a config if present, null otherwise.- Parameters:
hostname
- the hostname to identify a port from.- Returns:
- the port if found, null otherwise.
-
discoverConfig
protected abstract rx.Observable<String> discoverConfig(String bucket, String username, String password, String hostname)Run theBucketConfig
discovery process.- Parameters:
bucket
- the name of the bucket.username
- user authorized for bucket access.password
- the password of the user.hostname
- the hostname of the seed node list.- Returns:
- a raw config if discovered.
-
loadConfig
public rx.Observable<Tuple2<LoaderType,BucketConfig>> loadConfig(String seedNode, String bucket, String password)Initiate the config loading process.- Specified by:
loadConfig
in interfaceLoader
- Parameters:
seedNode
- the seed node.bucket
- the name of the bucket.password
- the password of the bucket.- Returns:
- a valid
BucketConfig
.
-
loadConfig
public rx.Observable<Tuple2<LoaderType,BucketConfig>> loadConfig(String seedNode, String bucket, String username, String password)Initiate the config loading process.- Specified by:
loadConfig
in interfaceLoader
- Parameters:
seedNode
- the seed node.bucket
- the name of the bucket.username
- the user authorized for bucket access.password
- the password of the user.- Returns:
- a valid
BucketConfig
.
-
cluster
Returns theClusterFacade
for child implementations.- Returns:
- the cluster reference.
-
env
Returns theCoreEnvironment
for child implementations.- Returns:
- the environment.
-
replaceHostWildcard
Replaces the host wildcard from an incoming config with a proper hostname.- Parameters:
input
- the input config.hostname
- the hostname to replace it with.- Returns:
- a replaced configuration.
-