|
16 | 16 | import java.util.Properties; |
17 | 17 | import java.util.concurrent.locks.ReentrantLock; |
18 | 18 | import java.util.logging.Logger; |
19 | | -import io.lettuce.core.support.ConnectionPoolSupport; |
| 19 | +import org.apache.commons.pool2.BasePooledObjectFactory; |
20 | 20 | import org.apache.commons.pool2.impl.GenericObjectPool; |
21 | 21 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; |
| 22 | +import org.apache.commons.pool2.impl.DefaultPooledObject; |
| 23 | +import org.apache.commons.pool2.PooledObject; |
22 | 24 | import software.amazon.jdbc.PropertyDefinition; |
23 | 25 | import software.amazon.jdbc.util.StringUtils; |
24 | 26 |
|
@@ -117,27 +119,29 @@ private void createConnectionPool(boolean isRead) { |
117 | 119 | .withSsl(useSSL).withVerifyPeer(false).withLibraryName("aws-jdbc-lettuce").build(); |
118 | 120 |
|
119 | 121 | RedisClient client = RedisClient.create(resources, redisUriCluster); |
120 | | - GenericObjectPool<StatefulRedisConnection<byte[], byte[]>> pool = |
121 | | - ConnectionPoolSupport.createGenericObjectPool( |
122 | | - () -> { |
123 | | - StatefulRedisConnection<byte[], byte[]> connection = client.connect(new ByteArrayCodec()); |
124 | | - // In cluster mode, we need to send READONLY command to the server for reading from replica. |
125 | | - // Note: we gracefully ignore ERR reply to support non cluster mode. |
126 | | - if (isRead) { |
127 | | - try { |
128 | | - connection.sync().readOnly(); |
129 | | - } catch (RedisCommandExecutionException e) { |
130 | | - if (e.getMessage().contains("ERR This instance has cluster support disabled")) { |
131 | | - LOGGER.fine("------ Note: this cache cluster has cluster support disabled ------"); |
132 | | - } else { |
133 | | - throw e; |
134 | | - } |
| 122 | + GenericObjectPool<StatefulRedisConnection<byte[], byte[]>> pool = new GenericObjectPool<>( |
| 123 | + new BasePooledObjectFactory<StatefulRedisConnection<byte[], byte[]>>() { |
| 124 | + public StatefulRedisConnection<byte[], byte[]> create() { |
| 125 | + StatefulRedisConnection<byte[], byte[]> connection = client.connect(new ByteArrayCodec()); |
| 126 | + // In cluster mode, we need to send READONLY command to the server for reading from replica. |
| 127 | + // Note: we gracefully ignore ERR reply to support non cluster mode. |
| 128 | + if (isRead) { |
| 129 | + try { |
| 130 | + connection.sync().readOnly(); |
| 131 | + } catch (RedisCommandExecutionException e) { |
| 132 | + if (e.getMessage().contains("ERR This instance has cluster support disabled")) { |
| 133 | + LOGGER.fine("------ Note: this cache cluster has cluster support disabled ------"); |
| 134 | + } else { |
| 135 | + throw e; |
135 | 136 | } |
136 | 137 | } |
137 | | - return connection; |
138 | | - }, |
139 | | - poolConfig |
140 | | - ); |
| 138 | + } |
| 139 | + return connection; |
| 140 | + } |
| 141 | + public PooledObject<StatefulRedisConnection<byte[], byte[]>> wrap(StatefulRedisConnection<byte[], byte[]> connection) { |
| 142 | + return new DefaultPooledObject<>(connection); |
| 143 | + } |
| 144 | + }, poolConfig); |
141 | 145 |
|
142 | 146 | if (isRead) { |
143 | 147 | readConnectionPool = pool; |
|
0 commit comments