├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── org
│ │ └── darkphoenixs
│ │ └── pool
│ │ ├── ConnectionException.java
│ │ ├── ConnectionFactory.java
│ │ ├── ConnectionPool.java
│ │ ├── PoolBase.java
│ │ ├── PoolConfig.java
│ │ ├── hbase
│ │ ├── HbaseConfig.java
│ │ ├── HbaseConnectionFactory.java
│ │ ├── HbaseConnectionPool.java
│ │ └── HbaseSharedConnPool.java
│ │ ├── http
│ │ ├── HttpConfig.java
│ │ ├── HttpConnectionFactory.java
│ │ └── HttpConnectionPool.java
│ │ ├── jdbc
│ │ ├── JdbcConfig.java
│ │ ├── JdbcConnectionFactory.java
│ │ └── JdbcConnectionPool.java
│ │ ├── kafka
│ │ ├── KafkaConfig.java
│ │ ├── KafkaConnectionFactory.java
│ │ ├── KafkaConnectionPool.java
│ │ └── KafkaSharedConnPool.java
│ │ ├── redis
│ │ ├── RedisClusterConnPool.java
│ │ ├── RedisConfig.java
│ │ ├── RedisConnectionFactoryOld.java
│ │ ├── RedisConnectionPool.java
│ │ ├── RedisConnectionPoolOld.java
│ │ ├── RedisSentinelConnPool.java
│ │ ├── RedisSentinelConnPoolOld.java
│ │ ├── RedisShardedConnPool.java
│ │ └── RedisShardedConnPoolOld.java
│ │ └── socket
│ │ ├── SocketConfig.java
│ │ ├── SocketConnectionFactory.java
│ │ └── SocketConnectionPool.java
└── resources
│ └── META-INF
│ ├── LICENSE.txt
│ └── NOTICE.txt
└── test
├── java
└── org
│ └── darkphoenixs
│ └── pool
│ ├── ConnectionExceptionTest.java
│ ├── ConnectionFactoryTest.java
│ ├── ConnectionPoolTest.java
│ ├── PoolBaseTest.java
│ ├── PoolConfigTest.java
│ ├── hbase
│ ├── HbaseConfigTest.java
│ ├── HbaseConnectionFactoryTest.java
│ ├── HbaseConnectionPoolTest.java
│ ├── HbaseSharedConnPoolTest.java
│ └── HbaseTest.java
│ ├── http
│ ├── HttpConfigTest.java
│ ├── HttpConnectionFactoryTest.java
│ ├── HttpConnectionPoolTest.java
│ └── HttpTest.java
│ ├── jdbc
│ ├── JdbcConfigTest.java
│ ├── JdbcConnectionFactoryTest.java
│ ├── JdbcConnectionPoolTest.java
│ └── JdbcTest.java
│ ├── kafka
│ ├── KafkaConfigTest.java
│ ├── KafkaConnectionFactoryTest.java
│ ├── KafkaConnectionPoolTest.java
│ ├── KafkaSharedConnPoolTest.java
│ └── KafkaTest.java
│ ├── redis
│ ├── JedisConn.java
│ ├── JedisConn2.java
│ ├── JedisConn3.java
│ ├── JedisConn4.java
│ ├── RedisClusterConnPoolTest.java
│ ├── RedisConfigTest.java
│ ├── RedisConnectionFactoryOldTest.java
│ ├── RedisConnectionPoolOldTest.java
│ ├── RedisConnectionPoolTest.java
│ ├── RedisSentinelConnPoolOldTest.java
│ ├── RedisSentinelConnPoolTest.java
│ ├── RedisShardedConnPoolOldTest.java
│ ├── RedisShardedConnPoolTest.java
│ ├── RedisTest.java
│ ├── ShardedJedisConn.java
│ ├── ShardedJedisConn2.java
│ ├── ShardedJedisConn3.java
│ ├── ShardedJedisConn4.java
│ └── ShardedJedisConn5.java
│ └── socket
│ ├── SocketConfigTest.java
│ ├── SocketConnectionFactoryTest.java
│ ├── SocketConnectionPoolTest.java
│ └── SocketTest.java
└── resources
└── log4j.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | *.iml
3 |
4 | # Mobile Tools for Java (J2ME)
5 | .mtj.tmp/
6 |
7 | # Package Files #
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 | /target
14 | /.settings/
15 | /.classpath
16 | /.project
17 | /.idea/
18 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - openjdk8
4 | before_install:
5 | - pip install --user codecov
6 | after_success:
7 | - codecov
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Connection Pool Client
2 |
3 | [](http://www.darkphoenixs.org)
4 | [](https://travis-ci.org/DarkPhoenixs/connection-pool-client)
5 | [](https://codecov.io/gh/DarkPhoenixs/connection-pool-client)
6 | [](https://maven-badges.herokuapp.com/maven-central/org.darkphoenixs/connectionpool-client/)
7 | [](https://javadoc.io/doc/org.darkphoenixs/connectionpool-client)
8 | [](https://github.com/DarkPhoenixs/connection-pool-client/releases)
9 | [](https://www.apache.org/licenses/LICENSE-2.0.html)
10 |
11 |
12 | This is a simple multi-purpose connection pool client base on [Apache Commons Pool ™](http://commons.apache.org/proper/commons-pool/)
13 |
14 | _Support_
15 | * [Apache Kafka](http://kafka.apache.org/)
16 | * [Apache Hbase](http://hbase.apache.org/)
17 | * [Redis](http://redis.io/)
18 | * RMDB (Oracle/MySQL/SQL Server)
19 | * Socket (TCP)
20 | * HTTP
21 |
22 | ## Documentation
23 |
24 | The documentation is available at [Wiki](https://github.com/DarkPhoenixs/connection-pool-client/wiki).
25 |
26 | ## Download
27 |
28 | #### Maven
29 |
30 | ```xml
31 |
Title: ConnectionException
20 | *Description: 连接异常
21 | * 22 | * @author Victor 23 | * @version 1.0 24 | * @see RuntimeException 25 | * @since 2015年9月19日 26 | */ 27 | public class ConnectionException extends RuntimeException { 28 | 29 | private static final long serialVersionUID = -6503525110247209484L; 30 | 31 | public ConnectionException() { 32 | super(); 33 | } 34 | 35 | public ConnectionException(String message) { 36 | super(message); 37 | } 38 | 39 | public ConnectionException(Throwable e) { 40 | super(e); 41 | } 42 | 43 | public ConnectionException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/darkphoenixs/pool/ConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Dark Phoenixs (Open-Source Organization). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.darkphoenixs.pool; 17 | 18 | import org.apache.commons.pool2.PooledObjectFactory; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | *Title: ConnectionFactory
24 | *Description: 连接工厂接口
25 | * 26 | * @author Victor 27 | * @version 1.0 28 | * @see PooledObjectFactory 29 | * @see Serializable 30 | * @since 2015年9月19日 31 | */ 32 | public interface ConnectionFactoryTitle: createConnection
36 | *Description: 创建连接
37 | * 38 | * @return 连接 39 | * @throws Exception 40 | */ 41 | public abstract T createConnection() throws Exception; 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/darkphoenixs/pool/ConnectionPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Dark Phoenixs (Open-Source Organization). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.darkphoenixs.pool; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | *Title: ConnectionPool
22 | *Description: 连接池接口
23 | * 24 | * @author Victor 25 | * @version 1.0 26 | * @see Serializable 27 | * @since 2015年9月19日 28 | */ 29 | public interface ConnectionPoolTitle: getConnection
33 | *Description: 获取连接
34 | * 35 | * @return 连接 36 | */ 37 | public abstract T getConnection(); 38 | 39 | /** 40 | *Title: returnConnection
41 | *Description: 返回连接
42 | * 43 | * @param conn 连接 44 | */ 45 | public void returnConnection(T conn); 46 | 47 | /** 48 | *Title: invalidateConnection
49 | *Description: 废弃连接
50 | * 51 | * @param conn 连接 52 | */ 53 | public void invalidateConnection(T conn); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/darkphoenixs/pool/PoolConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Dark Phoenixs (Open-Source Organization). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.darkphoenixs.pool; 17 | 18 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | *Title: PoolConfig
24 | *Description: 默认池配置
25 | * 26 | * @author Victor 27 | * @version 1.0 28 | * @see GenericObjectPoolConfig 29 | * @see Serializable 30 | * @since 2015年9月19日 31 | */ 32 | public class PoolConfig extends GenericObjectPoolConfig implements Serializable { 33 | 34 | /** 35 | * DEFAULT_TEST_WHILE_IDLE 36 | */ 37 | public static final boolean DEFAULT_TEST_WHILE_IDLE = true; 38 | /** 39 | * DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS 40 | */ 41 | public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 60000; 42 | /** 43 | * DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS 44 | */ 45 | public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = 30000; 46 | /** 47 | * DEFAULT_NUM_TESTS_PER_EVICTION_RUN 48 | */ 49 | public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = -1; 50 | /** 51 | * serialVersionUID 52 | */ 53 | private static final long serialVersionUID = -2414567557372345057L; 54 | 55 | /** 56 | *Title: PoolConfig
57 | *Description: 默认构造方法
58 | */ 59 | public PoolConfig() { 60 | 61 | // defaults to make your life with connection pool easier :) 62 | setTestWhileIdle(DEFAULT_TEST_WHILE_IDLE); 63 | setMinEvictableIdleTimeMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); 64 | setTimeBetweenEvictionRunsMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS); 65 | setNumTestsPerEvictionRun(DEFAULT_NUM_TESTS_PER_EVICTION_RUN); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/darkphoenixs/pool/hbase/HbaseConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Dark Phoenixs (Open-Source Organization). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.darkphoenixs.pool.hbase; 17 | 18 | /** 19 | *HbaseConfig
20 | *Hbase配置
21 | * 22 | * @author Victor 23 | * @since 1.2.1 24 | */ 25 | public interface HbaseConfig { 26 | 27 | /** 28 | * DEFAULT_HOST 29 | */ 30 | public static final String DEFAULT_HOST = "localhost"; 31 | /** 32 | * DEFAULT_PORT 33 | */ 34 | public static final String DEFAULT_PORT = "2181"; 35 | /** 36 | * DEFAULT_MASTER 37 | */ 38 | public static final String DEFAULT_MASTER = null; 39 | /** 40 | * DEFAULT_ROOTDIR 41 | */ 42 | public static final String DEFAULT_ROOTDIR = null; 43 | 44 | /** 45 | * ZOOKEEPER_QUORUM_PROPERTY 46 | */ 47 | public static final String ZOOKEEPER_QUORUM_PROPERTY = "hbase.zookeeper.quorum"; 48 | /** 49 | * ZOOKEEPER_CLIENTPORT_PROPERTY 50 | */ 51 | public static final String ZOOKEEPER_CLIENTPORT_PROPERTY = "hbase.zookeeper.property.clientPort"; 52 | /** 53 | * MASTER_PROPERTY 54 | */ 55 | public static final String MASTER_PROPERTY = "hbase.master"; 56 | /** 57 | * ROOTDIR_PROPERTY 58 | */ 59 | public static final String ROOTDIR_PROPERTY = "hbase.rootdir"; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/darkphoenixs/pool/hbase/HbaseConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Dark Phoenixs (Open-Source Organization). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.darkphoenixs.pool.hbase; 17 | 18 | import org.apache.commons.pool2.PooledObject; 19 | import org.apache.commons.pool2.impl.DefaultPooledObject; 20 | import org.apache.hadoop.conf.Configuration; 21 | import org.apache.hadoop.hbase.client.Connection; 22 | import org.darkphoenixs.pool.ConnectionException; 23 | import org.darkphoenixs.pool.ConnectionFactory; 24 | 25 | import java.util.Map.Entry; 26 | import java.util.Properties; 27 | 28 | /** 29 | *Title: HbaseConnectionFactory
30 | *Description: Hbase连接工厂
31 | * 32 | * @author Victor 33 | * @version 1.0 34 | * @see ConnectionFactory 35 | * @since 2015年9月19日 36 | */ 37 | class HbaseConnectionFactory implements ConnectionFactoryTitle: HbaseConnectionFactory
51 | *Description: 构造方法
52 | * 53 | * @param hadoopConfiguration hbase配置 54 | */ 55 | public HbaseConnectionFactory(final Configuration hadoopConfiguration) { 56 | 57 | this.hadoopConfiguration = hadoopConfiguration; 58 | } 59 | 60 | /** 61 | *Title: HbaseConnectionFactory
62 | *Description: 构造方法
63 | * 64 | * @param host zookeeper地址 65 | * @param port zookeeper端口 66 | * @param master hbase主机 67 | * @param rootdir hdfs数据目录 68 | */ 69 | public HbaseConnectionFactory(final String host, final String port, final String master, final String rootdir) { 70 | 71 | this.hadoopConfiguration = new Configuration(); 72 | 73 | if (host == null) 74 | throw new ConnectionException("[" + HbaseConfig.ZOOKEEPER_QUORUM_PROPERTY + "] is required !"); 75 | this.hadoopConfiguration.set(HbaseConfig.ZOOKEEPER_QUORUM_PROPERTY, host); 76 | 77 | if (port == null) 78 | throw new ConnectionException("[" + HbaseConfig.ZOOKEEPER_CLIENTPORT_PROPERTY + "] is required !"); 79 | this.hadoopConfiguration.set(HbaseConfig.ZOOKEEPER_CLIENTPORT_PROPERTY, port); 80 | 81 | if (master != null) 82 | this.hadoopConfiguration.set(HbaseConfig.MASTER_PROPERTY, master); 83 | 84 | if (rootdir != null) 85 | this.hadoopConfiguration.set(HbaseConfig.ROOTDIR_PROPERTY, rootdir); 86 | } 87 | 88 | /** 89 | * @param properties 参数配置 90 | * @since 1.2.1 91 | */ 92 | public HbaseConnectionFactory(final Properties properties) { 93 | 94 | this.hadoopConfiguration = new Configuration(); 95 | 96 | for (Entry