// Path: spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/support/StatusConstants.java
// public final class StatusConstants {
// 
// 	private StatusConstants() {
// 	}
// 
// 	/**
// 	 * Key to the
// 	 * {@link ZookeeperInstance#getMetadata()}
// 	 * map.
// 	 */
// 	public static final String INSTANCE_STATUS_KEY = "instance_status";
// 
// 	/**
// 	 * UP value for {@link StatusConstants#INSTANCE_STATUS_KEY} key.
// 	 */
// 	public static final String STATUS_UP = "UP";
// 
// 	/**
// 	 * OUT_OF_SERVICE value for {@link StatusConstants#INSTANCE_STATUS_KEY} key.
// 	 */
// 	public static final String STATUS_OUT_OF_SERVICE = "OUT_OF_SERVICE";
// 
// }


import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.zookeeper.support.StatusConstants;
import org.springframework.util.StringUtils;
/*
 * Copyright 2015-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.zookeeper.discovery;



/**
 * Properties related to Zookeeper's Service Discovery.
 *
 * @author Spencer Gibb
 * @since 1.0.0
 */
@ConfigurationProperties(ZookeeperDiscoveryProperties.PREFIX)
public class ZookeeperDiscoveryProperties {

	/**
	 * Zookeeper Discovery Properties prefix.
	 */
	public static final String PREFIX = "spring.cloud.zookeeper.discovery";

	/**
	 * Default URI spec.
	 */
	public static final String DEFAULT_URI_SPEC = "{scheme}://{address}:{port}";

	private InetUtils.HostInfo hostInfo;

	private boolean enabled = true;

	/**
	 * Root Zookeeper folder in which all instances are registered.
	 */
	private String root = "/services";

	/**
	 * The URI specification to resolve during service registration in Zookeeper.
	 */
	private String uriSpec = DEFAULT_URI_SPEC;

	/** Id used to register with zookeeper. Defaults to a random UUID. */
	private String instanceId;

	/**
	 * Predefined host with which a service can register itself in Zookeeper. Corresponds
	 * to the {code address} from the URI spec.
	 */
	private String instanceHost;

	/**
	 * IP address to use when accessing service (must also set preferIpAddress to use).
	 */
	private String instanceIpAddress;

	/**
	 * Use ip address rather than hostname during registration.
	 */
	private boolean preferIpAddress = false;

	/** Port to register the service under (defaults to listening port). */
	private Integer instancePort;

	/** Ssl port of the registered service. */
	private Integer instanceSslPort;

	/**
	 * Register as a service in zookeeper.
	 */
	private boolean register = true;

	/**
	 * Gets the metadata name/value pairs associated with this instance. This information
	 * is sent to zookeeper and can be used by other instances.
	 */
	private Map<String, String> metadata = new HashMap<>();

	/**
	 * The initial status of this instance (defaults to
	 * {@link StatusConstants#STATUS_UP}).
	 */
	private String initialStatus = StatusConstants.STATUS_UP;

	/**
	 * Order of the discovery client used by `CompositeDiscoveryClient` for sorting
	 * available clients.
	 */
	private int order = 0;

	// Visible for Testing
	protected ZookeeperDiscoveryProperties() {
	}

	public ZookeeperDiscoveryProperties(InetUtils inetUtils) {
		this.hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
		this.instanceHost = this.hostInfo.getHostname();
		this.instanceIpAddress = this.hostInfo.getIpAddress();
	}

	public boolean isEnabled() {
// Path: spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/support/StatusConstants.java
// public final class StatusConstants {
// 
// 	private StatusConstants() {
// 	}
// 
// 	/**
// 	 * Key to the
// 	 * {@link ZookeeperInstance#getMetadata()}
// 	 * map.
// 	 */
// 	public static final String INSTANCE_STATUS_KEY = "instance_status";
// 
// 	/**
// 	 * UP value for {@link StatusConstants#INSTANCE_STATUS_KEY} key.
// 	 */
// 	public static final String STATUS_UP = "UP";
// 
// 	/**
// 	 * OUT_OF_SERVICE value for {@link StatusConstants#INSTANCE_STATUS_KEY} key.
// 	 */
// 	public static final String STATUS_OUT_OF_SERVICE = "OUT_OF_SERVICE";
// 
// }


// Path: spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryProperties.java
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.zookeeper.support.StatusConstants;
import org.springframework.util.StringUtils;

/*
 * Copyright 2015-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.zookeeper.discovery;



/**
 * Properties related to Zookeeper's Service Discovery.
 *
 * @author Spencer Gibb
 * @since 1.0.0
 */
@ConfigurationProperties(ZookeeperDiscoveryProperties.PREFIX)
public class ZookeeperDiscoveryProperties {

	/**
	 * Zookeeper Discovery Properties prefix.
	 */
	public static final String PREFIX = "spring.cloud.zookeeper.discovery";

	/**
	 * Default URI spec.
	 */
	public static final String DEFAULT_URI_SPEC = "{scheme}://{address}:{port}";

	private InetUtils.HostInfo hostInfo;

	private boolean enabled = true;

	/**
	 * Root Zookeeper folder in which all instances are registered.
	 */
	private String root = "/services";

	/**
	 * The URI specification to resolve during service registration in Zookeeper.
	 */
	private String uriSpec = DEFAULT_URI_SPEC;

	/** Id used to register with zookeeper. Defaults to a random UUID. */
	private String instanceId;

	/**
	 * Predefined host with which a service can register itself in Zookeeper. Corresponds
	 * to the {code address} from the URI spec.
	 */
	private String instanceHost;

	/**
	 * IP address to use when accessing service (must also set preferIpAddress to use).
	 */
	private String instanceIpAddress;

	/**
	 * Use ip address rather than hostname during registration.
	 */
	private boolean preferIpAddress = false;

	/** Port to register the service under (defaults to listening port). */
	private Integer instancePort;

	/** Ssl port of the registered service. */
	private Integer instanceSslPort;

	/**
	 * Register as a service in zookeeper.
	 */
	private boolean register = true;

	/**
	 * Gets the metadata name/value pairs associated with this instance. This information
	 * is sent to zookeeper and can be used by other instances.
	 */
	private Map<String, String> metadata = new HashMap<>();

	/**
	 * The initial status of this instance (defaults to
	 * {@link StatusConstants#STATUS_UP}).
	 */
	private String initialStatus = StatusConstants.STATUS_UP;

	/**
	 * Order of the discovery client used by `CompositeDiscoveryClient` for sorting
	 * available clients.
	 */
	private int order = 0;

	// Visible for Testing
	protected ZookeeperDiscoveryProperties() {
	}

	public ZookeeperDiscoveryProperties(InetUtils inetUtils) {
		this.hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
		this.instanceHost = this.hostInfo.getHostname();
		this.instanceIpAddress = this.hostInfo.getIpAddress();
	}

	public boolean isEnabled() {
		return this.enabled;