Class 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
    • Method Detail

      • port

        protected abstract int port​(String hostname)
        Port to use for the ServiceType. 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

        protected Integer tryLoadingPortFromConfig​(String hostname)
        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 the BucketConfig 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 username,
                                                                               String password)
        Initiate the config loading process.
        Specified by:
        loadConfig in interface Loader
        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

        protected ClusterFacade cluster()
        Returns the ClusterFacade for child implementations.
        Returns:
        the cluster reference.
      • replaceHostWildcard

        protected String replaceHostWildcard​(String input,
                                             String hostname)
        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.