// Path: src/main/java/org/darkphoenixs/pool/ConnectionException.java
// public class ConnectionException extends RuntimeException {
// 
//     private static final long serialVersionUID = -6503525110247209484L;
// 
//     public ConnectionException() {
//         super();
//     }
// 
//     public ConnectionException(String message) {
//         super(message);
//     }
// 
//     public ConnectionException(Throwable e) {
//         super(e);
//     }
// 
//     public ConnectionException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/org/darkphoenixs/pool/ConnectionPool.java
// public interface ConnectionPool<T> extends Serializable {
// 
//     /**
//      * <p>Title: getConnection</p>
//      * <p>Description: 获取连接</p>
//      *
//      * @return 连接
//      */
//     public abstract T getConnection();
// 
//     /**
//      * <p>Title: returnConnection</p>
//      * <p>Description: 返回连接</p>
//      *
//      * @param conn 连接
//      */
//     public void returnConnection(T conn);
// 
//     /**
//      * <p>Title: invalidateConnection</p>
//      * <p>Description: 废弃连接</p>
//      *
//      * @param conn 连接
//      */
//     public void invalidateConnection(T conn);
// }


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.darkphoenixs.pool.ConnectionException;
import org.darkphoenixs.pool.ConnectionPool;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
package org.darkphoenixs.pool.hbase;



/**
 * <p>Title: HbaseSharedConnPool</p>
 * <p>Description: Hbase共享连接池（单例）</p>
 *
 * @author Victor.Zxy
 * @version 1.2.3
 * @see ConnectionPool
 * @since 2016 /8/25
 */
public class HbaseSharedConnPool implements ConnectionPool<Connection> {

    private static final AtomicReference<HbaseSharedConnPool> pool = new AtomicReference<HbaseSharedConnPool>();

    private final Connection connection;

    private HbaseSharedConnPool(Configuration configuration) throws IOException {

        this.connection = ConnectionFactory.createConnection(configuration);
    }

    /**
     * Gets instance.
     *
     * @param host    the host
     * @param port    the port
     * @param master  the master
     * @param rootdir the rootdir
     * @return the instance
     */
    public synchronized static HbaseSharedConnPool getInstance(final String host, final String port, final String master, final String rootdir) {

        Properties properties = new Properties();

        if (host == null)
            throw new ConnectionException("[" + HbaseConfig.ZOOKEEPER_QUORUM_PROPERTY + "] is required !");
        properties.setProperty(HbaseConfig.ZOOKEEPER_QUORUM_PROPERTY, host);

        if (port == null)
// Path: src/main/java/org/darkphoenixs/pool/ConnectionException.java
// public class ConnectionException extends RuntimeException {
// 
//     private static final long serialVersionUID = -6503525110247209484L;
// 
//     public ConnectionException() {
//         super();
//     }
// 
//     public ConnectionException(String message) {
//         super(message);
//     }
// 
//     public ConnectionException(Throwable e) {
//         super(e);
//     }
// 
//     public ConnectionException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/org/darkphoenixs/pool/ConnectionPool.java
// public interface ConnectionPool<T> extends Serializable {
// 
//     /**
//      * <p>Title: getConnection</p>
//      * <p>Description: 获取连接</p>
//      *
//      * @return 连接
//      */
//     public abstract T getConnection();
// 
//     /**
//      * <p>Title: returnConnection</p>
//      * <p>Description: 返回连接</p>
//      *
//      * @param conn 连接
//      */
//     public void returnConnection(T conn);
// 
//     /**
//      * <p>Title: invalidateConnection</p>
//      * <p>Description: 废弃连接</p>
//      *
//      * @param conn 连接
//      */
//     public void invalidateConnection(T conn);
// }


// Path: src/main/java/org/darkphoenixs/pool/hbase/HbaseSharedConnPool.java
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.darkphoenixs.pool.ConnectionException;
import org.darkphoenixs.pool.ConnectionPool;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;

package org.darkphoenixs.pool.hbase;



/**
 * <p>Title: HbaseSharedConnPool</p>
 * <p>Description: Hbase共享连接池（单例）</p>
 *
 * @author Victor.Zxy
 * @version 1.2.3
 * @see ConnectionPool
 * @since 2016 /8/25
 */
public class HbaseSharedConnPool implements ConnectionPool<Connection> {

    private static final AtomicReference<HbaseSharedConnPool> pool = new AtomicReference<HbaseSharedConnPool>();

    private final Connection connection;

    private HbaseSharedConnPool(Configuration configuration) throws IOException {

        this.connection = ConnectionFactory.createConnection(configuration);
    }

    /**
     * Gets instance.
     *
     * @param host    the host
     * @param port    the port
     * @param master  the master
     * @param rootdir the rootdir
     * @return the instance
     */
    public synchronized static HbaseSharedConnPool getInstance(final String host, final String port, final String master, final String rootdir) {

        Properties properties = new Properties();

        if (host == null)
            throw new ConnectionException("[" + HbaseConfig.ZOOKEEPER_QUORUM_PROPERTY + "] is required !");
        properties.setProperty(HbaseConfig.ZOOKEEPER_QUORUM_PROPERTY, host);

        if (port == null)
            throw new ConnectionException("[" + HbaseConfig.ZOOKEEPER_CLIENTPORT_PROPERTY + "] is required !");