// Path: config-face/src/main/java/com/dangdang/config/face/entity/PropertyItem.java
// public class PropertyItem implements Serializable {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 1L;
// 
// 	private String name;
// 	private String value;
// 
// 	public PropertyItem(String name, String value) {
// 		super();
// 		this.name = name;
// 		this.value = value;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	public String getValue() {
// 		return value;
// 	}
// 
// 	public void setValue(String value) {
// 		this.value = value;
// 	}
// 
// }


import com.dangdang.config.face.entity.PropertyItem;
import com.google.common.base.Charsets;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.GetChildrenBuilder;
import org.apache.curator.framework.api.GetDataBuilder;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.List;
/**
 * Copyright 1999-2014 dangdang.com.
 *  
 * 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
 *  
 *      http://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 com.dangdang.config.face.service;



/**
 * @author <a href="mailto:wangyuxuan@dangdang.com">Yuxuan Wang</a>
 * 
 */
@Service
public class NodeService implements INodeService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Value("${zk}")
	private String zkAddress;

	private CuratorFramework client;

	@PostConstruct
	private void init() {
		client = CuratorFrameworkFactory.newClient(zkAddress, new ExponentialBackoffRetry(1000, 3));
		client.start();
	}

	@PreDestroy
	private void destroy() {
		if (client != null) {
			client.close();
		}
	}

	private static final Logger LOGGER = LoggerFactory.getLogger(NodeService.class);

	@Override
// Path: config-face/src/main/java/com/dangdang/config/face/entity/PropertyItem.java
// public class PropertyItem implements Serializable {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 1L;
// 
// 	private String name;
// 	private String value;
// 
// 	public PropertyItem(String name, String value) {
// 		super();
// 		this.name = name;
// 		this.value = value;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	public String getValue() {
// 		return value;
// 	}
// 
// 	public void setValue(String value) {
// 		this.value = value;
// 	}
// 
// }


// Path: config-face/src/main/java/com/dangdang/config/face/service/NodeService.java
import com.dangdang.config.face.entity.PropertyItem;
import com.google.common.base.Charsets;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.GetChildrenBuilder;
import org.apache.curator.framework.api.GetDataBuilder;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.List;

/**
 * Copyright 1999-2014 dangdang.com.
 *  
 * 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
 *  
 *      http://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 com.dangdang.config.face.service;



/**
 * @author <a href="mailto:wangyuxuan@dangdang.com">Yuxuan Wang</a>
 * 
 */
@Service
public class NodeService implements INodeService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Value("${zk}")
	private String zkAddress;

	private CuratorFramework client;

	@PostConstruct
	private void init() {
		client = CuratorFrameworkFactory.newClient(zkAddress, new ExponentialBackoffRetry(1000, 3));
		client.start();
	}

	@PreDestroy
	private void destroy() {
		if (client != null) {
			client.close();
		}
	}

	private static final Logger LOGGER = LoggerFactory.getLogger(NodeService.class);

	@Override
	public List<PropertyItem> findProperties(String node) {