@Override public CompletableFuture<Void> releaseAsync(StatefulConnection<?, ?> connection) { GenericObjectPool<StatefulConnection<?, ?>> blockingPool = poolRef.remove(connection); if (blockingPool != null) { log.warn("Releasing asynchronously a connection that was obtained from a non-blocking pool"); blockingPool.returnObject(connection); return CompletableFuture.completedFuture(null); } AsyncPool<StatefulConnection<?, ?>> pool = asyncPoolRef.remove(connection); if (pool == null) { return LettuceFutureUtils.failed(new PoolException("Returned connection " + connection + " was either previously returned or does not belong to this connection provider")); } return pool.release(connection); }
@Override public <T extends StatefulConnection<?, ?>> CompletableFuture<T> getConnectionAsync(Class<T> connectionType) { if (!initialized) { // partitions have to be initialized before asynchronous usage. // Needs to happen only once. Initialize eagerly if // blocking is not an options. synchronized (monitor) { if (!initialized) { client.getPartitions(); initialized = true; } } } if (connectionType.equals(StatefulRedisPubSubConnection.class)) { return client.connectPubSubAsync(codec) // .thenApply(connectionType::cast); } if (StatefulRedisClusterConnection.class.isAssignableFrom(connectionType) || connectionType.equals(StatefulConnection.class)) { return client.connectAsync(codec) // .thenApply(connection -> { readFrom.ifPresent(connection::setReadFrom); return connectionType.cast(connection); }); } return LettuceFutureUtils .failed(new UnsupportedOperationException("Connection type " + connectionType + " not supported!")); }
@SuppressWarnings({ "null", "unchecked", "rawtypes" }) @Override public <T extends StatefulConnection<?, ?>> CompletionStage<T> getConnectionAsync(Class<T> connectionType, RedisURI redisURI) { if (connectionType.equals(StatefulRedisSentinelConnection.class)) { return client.connectSentinelAsync(StringCodec.UTF8, redisURI).thenApply(connectionType::cast); } if (connectionType.equals(StatefulRedisPubSubConnection.class)) { return client.connectPubSubAsync(codec, redisURI).thenApply(connectionType::cast); } if (StatefulConnection.class.isAssignableFrom(connectionType)) { return readFrom.map(it -> this.masterReplicaConnectionAsync(redisURI, it)) // .orElseGet(() -> (CompletionStage) client.connectAsync(codec, redisURI)) // .thenApply(connectionType::cast); } return LettuceFutureUtils .failed(new UnsupportedOperationException("Connection type " + connectionType + " not supported!")); }