All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mydotey.rpc.client.http.HttpServiceClientConfig Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package org.mydotey.rpc.client.http;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.mydotey.codec.Codec;
import org.mydotey.java.ObjectExtension;

/**
 * @author koqizhao
 *
 * Dec 18, 2018
 */
public class HttpServiceClientConfig implements Cloneable {

    private Map _procedureRestPathMap;

    private Supplier _syncClientProvider;
    private Supplier _asyncClientProvider;

    private Codec _codec;

    private HttpLoadBalancer _loadBalancer;

    protected HttpServiceClientConfig() {

    }

    public Map getProcedureRestPathMap() {
        return _procedureRestPathMap;
    }

    public Supplier getSyncClientProvider() {
        return _syncClientProvider;
    }

    public Supplier getAsyncClientProvider() {
        return _asyncClientProvider;
    }

    public Codec getCodec() {
        return _codec;
    }

    public HttpLoadBalancer getLoadBalancer() {
        return _loadBalancer;
    }

    @Override
    protected HttpServiceClientConfig clone() {
        try {
            HttpServiceClientConfig config = (HttpServiceClientConfig) super.clone();
            if (_procedureRestPathMap != null)
                config._procedureRestPathMap = Collections.unmodifiableMap(new HashMap<>(config._procedureRestPathMap));
            return config;
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    public static class Builder {

        private HttpServiceClientConfig _config;

        public Builder() {
            _config = new HttpServiceClientConfig();
        }

        public Builder setProcedureRestPathMap(Map procedureRestPathMap) {
            _config._procedureRestPathMap = procedureRestPathMap;
            return this;
        }

        public Builder setSyncClientProvider(Supplier syncClientProvider) {
            _config._syncClientProvider = syncClientProvider;
            return this;
        }

        public Builder setAsyncClientProvider(Supplier asyncClientProvider) {
            _config._asyncClientProvider = asyncClientProvider;
            return this;
        }

        public Builder setCodec(Codec codec) {
            _config._codec = codec;
            return this;
        }

        public Builder setLoadBalancer(HttpLoadBalancer loadBalancer) {
            _config._loadBalancer = loadBalancer;
            return this;
        }

        public HttpServiceClientConfig build() {
            ObjectExtension.requireNonEmpty(_config._procedureRestPathMap, "procedureRestPathMap");
            ObjectExtension.requireNonNull(_config._syncClientProvider, "syncClientProvider");
            ObjectExtension.requireNonNull(_config._asyncClientProvider, "asyncClientProvider");
            ObjectExtension.requireNonNull(_config._codec, "codec");
            ObjectExtension.requireNonNull(_config._loadBalancer, "loadBalancer");

            return _config.clone();
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy