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

com.ecwid.consul.v1.catalog.CatalogServicesRequest Maven / Gradle / Ivy

There is a newer version: 2.0.0.0-RC3
Show newest version
package com.ecwid.consul.v1.catalog;

import com.ecwid.consul.ConsulRequest;
import com.ecwid.consul.SingleUrlParameters;
import com.ecwid.consul.UrlParameters;
import com.ecwid.consul.v1.NodeMetaParameters;
import com.ecwid.consul.v1.QueryParams;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class CatalogServicesRequest implements ConsulRequest {

	private final String datacenter;
	private final Map nodeMeta;
	private final QueryParams queryParams;
	private final String token;

	public CatalogServicesRequest(String datacenter, Map nodeMeta, QueryParams queryParams, String token) {
		this.datacenter = datacenter;
		this.nodeMeta = nodeMeta;
		this.queryParams = queryParams;
		this.token = token;
	}

	public String getDatacenter() {
		return datacenter;
	}

	public Map getNodeMeta() {
		return nodeMeta;
	}

	public QueryParams getQueryParams() {
		return queryParams;
	}

	public String getToken() {
		return token;
	}

	public static class Builder {
		private String datacenter;
		private Map nodeMeta;
		private QueryParams queryParams;
		private String token;

		private Builder() {
		}

		public Builder setDatacenter(String datacenter) {
			this.datacenter = datacenter;
			return this;
		}

		public Builder setNodeMeta(Map nodeMeta) {
			if (nodeMeta == null) {
				this.nodeMeta = null;
			} else {
				this.nodeMeta = Collections.unmodifiableMap(nodeMeta);
			}

			return this;
		}

		public Builder setQueryParams(QueryParams queryParams) {
			this.queryParams = queryParams;
			return this;
		}

		public Builder setToken(String token) {
			this.token = token;
			return this;
		}

		public CatalogServicesRequest build() {
			return new CatalogServicesRequest(datacenter, nodeMeta, queryParams, token);
		}
	}

	public static Builder newBuilder() {
		return new CatalogServicesRequest.Builder();
	}

	@Override
	public List asUrlParameters() {
		List params = new ArrayList<>();

		if (datacenter != null) {
			params.add(new SingleUrlParameters("dc", datacenter));
		}

		if (nodeMeta != null) {
			params.add(new NodeMetaParameters(nodeMeta));
		}

		if (queryParams != null) {
			params.add(queryParams);
		}

		if (token != null) {
			params.add(new SingleUrlParameters("token", token));
		}

		return params;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy